Australian (ASX) Stock Market Forum

Amibroker FAQ

Thanks Trash
Sorry the late acknowledgment had a whole lot of weather and not a whole lot of power here in the west.
Should have known this code was buried somewhere in the AB manual appreciate your pointing me in the right direction.
 
Switch(ExposureVal)
{
Case < 0.10:
1;
Case (>=0.1 AND <=0.2):
2;
Case >0.2:
3;
}

Is it valid to use boolean logic in case statements as per above or do case values have to be discrete numbers as shown in the AB manual?
 
Hello

I need a bit of help with the following afl. I want to be able to manually enter an entry date in parameters and plot a target line 5% below the entry date. Could someone please tell me what I have wrong. I get an error in the plot.



HTML:
Plot( C, "Close", colorBlack , styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
BuyStartDate = ParamDate( "Buy Start Date", "2012-06-01" );
EndDate = ParamDate( "Last Buy Date", "2020-01-01" );
DateOK = IIf(DateNum() >= BuyStartDate  , 1, 0); //AND DateNum() <= EndDate

Short =  Close>1  AND DateOK  ; ShortPrice=Close;
Cover = RSI(5 ) < 20; CoverPrice=Close;

entry = ShortPrice;
target1 = entry - (entry * .050);


end = LastValue( BarIndex() );

Plot(LineArray(buystartdate,target1, end ,target1,1), "", colorOrange, styleLine);  
//LineArray( x0, y0, x1, y1, extend = 0, usebarindex = False )
 
Show me a long only system that performs well in a sideways or bear market.

No problems. Inspired by the same book.

PHP:
PositionSize = -20;
PositionScore = 1 - C/10;

XAO = Foreign("XSO","Close");
XAOMA = MA(XAO, 75);

Buy = Sell = 0;

SetTradeDelays(1, 1, 1, 1);
BuyPrice = Close;
SellPrice = Close;

Length = 260;	// 1 year

BuySig =
	Close > HHV(Ref(Close, -1), Length)
	AND XAO > XAOMA
	;

SellSig =
	Close < Ref( LLV(Close, Length), -1)
	OR XAO < XAOMA
	;

Buy = ExRem(BuySig, SellSig);
Sell = ExRem(SellSig, BuySig);

ApplyStop(stopTypeLoss, stopModePercent, amount = 25, False );

Backtest filtered by ASX All Ordinaries (2012), 100K initial equity, min $5000 pos, $35 per trade, no more than 1% of entry bar volume.

Jan 2011 - Jun 2012. CAR = 22.33%, MDD = -8.03%

Jan 2004 - Jun 2012. CAR = 21.00%, MDD = -26.41%

Will not make you rich overnight and not that I would trade this system myself, but this an Amibroker thread, not the trading one.
 

Attachments

  • Portfolio Equity 2011-2012.png
    Portfolio Equity 2011-2012.png
    8.6 KB · Views: 154
  • Portfolio Equity 2004-2012.png
    Portfolio Equity 2004-2012.png
    9.1 KB · Views: 156
Could someone please tell me what I have wrong. I get an error in the plot.

Your code has many errors. First, ParamDate without the third parameter returns an integer in DateNum format, which is rather useless in plots. Second, ShortPrice is an array, as a result all the rest - entry and target1 are arrays too, and LineArray accepts only numbers. Third, 1st parameter in LineArray is a bar index, not a DateNum.Try following and be prepared not to see the line if BuyStartDate is far outside the visible range.
PHP:
Plot( C, "Close", colorBlack , styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
BuyStartDate = _DT( ParamDate( "Buy Start Date", "2012-06-01", 1) );
EndDate = _DT( ParamDate( "Last Buy Date", "2020-01-01", 1) );
DateOK = IIf(DateNum() >= BuyStartDate  , 1, 0); //AND DateNum() <= EndDate

Short =  Close>1  AND DateOK  ; ShortPrice=Close;
Cover = RSI(5 ) < 20; CoverPrice=Close;

entry = Lookup(ShortPrice, BuyStartDate, -1);
target1 = entry - (entry * .050);


end = LastValue( BarIndex() );

Plot(LineArray(Lookup(BarIndex(), BuyStartDate), target1, end ,target1, 1), "", colorOrange, styleLine);  
//LineArray( x0, y0, x1, y1, extend = 0, usebarindex = False )
 
Hi qsb6irfa

Thanks for telling me that. I dont have any experience with date/ bar index sort of equations and Ive spent a large chunk of the weekend trying to learn. When you look up the amibroker help files their are heaps of different date related types and it becomes a massive learning curve. Im stumped! The original idea came from a formula that I have posted below that plots 3 targets on a chart after a break of support or resistance. All I am trying to do is edit it so instead of it using a break of support or resistance to initiate the target lines I want to manually enter a date in parameters to start it. I cant find any afl's on the net that I can learn from so I really need some help. The last thing I tried was

Short =Cross( DateNum(),ParamDate( "Start Date","2012-05-01",0 ));

but this is probably wrong too based on what you have said. Do I have to write a loop for the entry or is it just something simple? Is paramdate ok to use? Sorry Ive run out of ideas :confused:



HTML:
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );



showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0);

res=HHV(H,10);
sup=LLV(L,10);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
s5d=IIf(avn==1,sup,res);

if (showsl == 0)
{Plot(s5d,"Stop Loss",colorCustom14,styleDots);}
exitlong = Cross(s5d, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, s5d);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);

Buy = exitshort;
Sell = exitlong;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);



for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "BUY";
sl = s5d[i];
tar1 = entry + (entry * .050);
tar2 = entry + (entry * .075);
tar3 = entry + (entry * .100);

bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = C[i];
sl = s5d[i];
tar1 = entry - (entry * .050);
tar2 = entry - (entry * .075);
tar3 = entry - (entry * .100);


bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, s5d[BarCount-1], Ref(s5d, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine, Null, Null, Offset);

_SECTION_END();
 
qsb6irfa thanks to you I have solved it. I thought a bit about what you said and I think the difference in the end was the zero on the end of the paramdate part.
Short =Cross( DateNum(),ParamDate( "Start Date","2012-05-01",0 ));

When I use this it works fine. Thanks mate!!
 
Hi folks,

Quick question for AB aficionados - is there a way to control text size for PlotText function?

Thanks in advance

Dre
 
Could someone help me plot the value of pSAR for the following day, as a small horizontal line on the chart, using this formula?


SAR tomorrow = SAR today + AF(EP trade - SAR(today)

where AF = acceleration factor, and EP = highest high reached yesterday

I know this isn't the exact formula, but it's sort of close.



Thanks.
 
Could someone help me plot the value of pSAR for the following day, as a small horizontal line on the chart, using this formula?


SAR tomorrow = SAR today + AF(EP trade - SAR(today)

where AF = acceleration factor, and EP = highest high reached yesterday

I know this isn't the exact formula, but it's sort of close.



Thanks.

Something along these lines should work:

extendLine = 3;
startPlot = BarCount - 1 - extendLine;
SART = ****;
Plot( C, "", color, styleBar);
Plot( IIf( BarIndex() >= startPlot, LastValue(SART), Null), "", color, styleThick, Null, Null, extendLine );
 
Something along these lines should work:

extendLine = 3;
startPlot = BarCount - 1 - extendLine;
SART = ****;
Plot( C, "", color, styleBar);
Plot( IIf( BarIndex() >= startPlot, LastValue(SART), Null), "", color, styleThick, Null, Null, extendLine );

Thanks colion, excellent.

Just in case anyone else is wondering about the next day value for the pSAR, it will depend on OHLC values and may vary significantly during the day. Unfortunately there are many supposedly reputable websites that say you can calculate ahead of time what that value will be.
 
Take a look at GfxSelectFont()

Thank colion, however GfxSelectFont does not seem to effect PlotText().

In order to benefit from it it seems I would need to use either GfxTextout or GxfGrawText and I've struggled to get either to work correctly. Is that right?
 
Thank colion, however GfxSelectFont does not seem to effect PlotText().

In order to benefit from it it seems I would need to use either GfxTextout or GxfGrawText and I've struggled to get either to work correctly. Is that right?

Once you jump into low level graphics then as far then as I know you have to go in all the way. Have you seen the tutorial at http://www.amibroker.com/guide/h_lowlevelgfx.html? Of course, if you are satisfied with one font for the entire chart you can use Tools >> Preferences >> Miscellaneous to change the font. I believe that these are your two choices.
 
Once you jump into low level graphics then as far then as I know you have to go in all the way. Have you seen the tutorial at http://www.amibroker.com/guide/h_lowlevelgfx.html? Of course, if you are satisfied with one font for the entire chart you can use Tools >> Preferences >> Miscellaneous to change the font. I believe that these are your two choices.

Thanks again colion.

I shall have another stub at low-level graphics on the weekend again for my own benefit. But for now I will utilise the second method suggested by you.

Cheers
 
Top