Australian (ASX) Stock Market Forum

Using Applystop and BacktestRegularRawMulti together in Amibroker

Joined
25 July 2012
Posts
1
Reactions
0
Greetings Traders,

I am trying to code a simple MA based trading system.
Since the system has multiple open positions, I am using the code - "SetBacktestMode( Backtestregularrawmulti )".

I wish to add a maximum Stop Loss of 0.5% of the entry price.
The problem is I am not able to use Apply Stop ( variable stop loss ) along with SetBacktestMode( Backtestregularrawmulti ) in the same AFL.

Can any one help find a solution to this ?

I am copy pasting my code below.
Hope someone can help.
Thanks in advance





_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

//plotting moving avgs////////////////

_SECTION_BEGIN("EMA10C");
Plot( EMA(C, 10 ), _DEFAULT_NAME(), colorGreen, ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA50C");
Plot( EMA( C, 10 ), _DEFAULT_NAME(),colorRed, ParamStyle("Style") );
_SECTION_END();

// clour bars /////

_SECTION_BEGIN("ColorPrice");

upbar = C >EMA(C,10) ;
downbar = C <EMA(C,10);

/* Colourized price bars drawn here */

Graph0 = Close;
barcolor = IIf( downbar, colorRed, IIf( upbar, colorGreen, 1 ) );
Graph0BarColor = ValueWhen( barcolor != 0, barcolor );

_SECTION_END();

// plot buy sinals //

Buysignalbar = C > EMA(C,10) ;
SellSignalbar = C < EMA(C,10) ;

Buysignalbar = ExRem(Buysignalbar,Sellsignalbar);
SellSignalbar = ExRem(Sellsignalbar,Buysignalbar);

PlotShapes(shapeHollowUpArrow ,IIf(Buysignalbar,colorBlue,0),0,IIf(Buysignalbar,Low,0));
PlotShapes(shapeHollowDownArrow ,IIf(sellsignalbar,colorRed,0),0,IIf(sellsignalbar,High,0));

BuySignalBreakbar = C > EMA(C,10) AND Ref(C,-1) > Ref(EMA(C,10),-1) AND H > ValueWhen(Buysignalbar,H);
BuySignalBreakbar = ExRem(BuySignalBreakbar,Buysignalbar);
PlotShapes(shapeUpArrow ,IIf(BuySignalBreakbar,colorBlue,0),0,IIf(BuySignalBreakbar,Low,0));

Buyentrybar = Ref(C,-1) > Ref(EMA(C,10),-1) AND Ref(C,-2) > Ref(EMA(C,10),-2) AND H > ValueWhen(BuySignalBreakbar,H);
Buyentrybar = ExRem(BuyEntrybar,Buysignalbreakbar);
PlotShapes(shapeUpTriangle ,IIf(BuyEntrybar,colorBlue,0),0,IIf(Buyentrybar,Low,0));

SellEntrybar = L < ValueWhen(sellsignalbar,L) ;
SellEntrybar = ExRem(Sellentrybar,Sellsignalbar);

PlotShapes(shapeDownArrow ,IIf(SellEntrybar,colorRed,0),0,IIf(SellEntrybar,High,0));


Buy = Buyentrybar;
BuyPrice = ValueWhen(Buysignalbreakbar,H);
BuyPrice = Max(O,BuyPrice);


Sell = Sellentrybar;

SellPrice = ValueWhen(Sellsignalbar,L);
SellPrice = Min(SellPrice,Open);

SetBacktestMode(backtestregularrawmulti);
 
Top