I am trying to write back testable trading system, Please help on following code.
I am struggling with following.
1.) Stoploss on signal's previous day's low and target next sell signal
2.) Condition1:- Say ema13 and ma34 cross over where when ema13>ma34
Condition2:- when condition1 satisfies, the high of the bar should be long entry if it's crossed by the next bar
If the next bar doesn't crosses the first signal bar when ema13>ma34 then entry gets revised to the next bar high
Say first bar(signal bar) high was 202 and next bar high is 201.4 now our entry gets above 201.4 but again if next bar is unable to cross 201.4 the entry has to be again revised to next bar high
If high doesn't breaks means trade not entered
https://forum.amibroker.com/t/edge-in-a-systematic-trading/11770?u=sandeep
_SECTION_BEGIN("13-34 Crossover Trading System");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g f%%) {{VALUES}}", O, H, L, C ));
//Initial Parameters
SetTradeDelays( 0, 0, 0, 0 );
SetOption( "InitialEquity", 500000);
SetOption("FuturesMode" ,False);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",50);
SetOption("AccountMargin",100);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(150,spsShares);
SetOption( "AllowPositionShrinking", True );
RoundLotSize=1;
//Parameters
MALength1 = 13;
MALength2 = 34;
//prevL = Ref( L, -1 ); // use previous bar low
//prevH = Ref( H, -1 ); // use previous bar high
//Buy-Sell Logic
//Buy = Cross(ema( C, MALength1 ),ema( C, MALength2 ));
//Sell =Cross( ema( C, MALength2 ), ema( C, MALength1 )) ;
Bcond1 = Cross(ema( C, MALength1 ),ema( C, MALength2 ));
Scond1 =Cross( ema( C, MALength2 ), ema( C, MALength1 )) ;
Bcond2=H > Ref(H,-1);
Scond2=L < Ref(L,-1);
Buy = Ref( Bcond1, -1) AND Bcond2;
Sell = Ref(scond1,-1) AND scond2;
*/
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
Short = Cover = 0;
BuyPrice=C;
SellPrice=C;
ShortPrice=C;
CoverPrice=C;
Plot( Close, "Price", colorWhite, styleCandle );
Plot(ema( C, MALength1 ),"FastEMA",colorRed);
Plot(ema( C, MALength2 ),"SlowEMA",colorBlue);
/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
Filter = Buy OR Sell ;
AddColumn(Buy,"Buy");
AddColumn(Close,"RATE",1.2,colorBlack, IIf(Buy,colorAqua,colorPink));
_SECTION_END();
Please help , I have tried but not getting desired result.