Join our facebook group for Amibroker afl code discussion https://www.facebook.com/groups/603980776889348

NR7 Narrow Range For 7 Days Breakout



NR7 Narrow Range For 7 Days Breakout
NR7 Narrow Range For 7 Days Breakout



//www.aflcode.com

_SECTION_BEGIN("NR7 Trading Strategy");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C ));

//Initial Parameters
SetTradeDelays( 0,0,0, 0 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",100);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(50,spsPercentOfEquity);
//SetPositionSize(150,spsShares);
SetOption( "AllowPositionShrinking", True );

Plot( Close, "Price", colorWhite, styleCandle );

//==================================================================================
//NR7 RANGE IDENTIFICATION
 
range = H-L;
Condition0 = range<Ref(range,-1) AND range<Ref(range,-2) AND range<Ref(range,-3)AND range<Ref(range,-4)AND range<Ref(range,-5)AND range<Ref(range,-6);
NR7 = IIf(Condition0,True, False);

printf("\nNR7 : " + NR7 );  

BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;

TGT= Param("Target Percent",4,1,20,1);
SL= Param("SL Percent",1,1,5,1);

Buy=Ref(NR7,-1) AND GapUp();
Short=Ref(NR7,-1) AND GapDown();

BuyTgt=ValueWhen(Buy,BuyPrice,1)*(1+TGT/100);
BuySL=ValueWhen(Buy,BuyPrice,1)*(1-SL/100);
Sell= H>=BuyTgt OR L<=BuySL;


ShortTgt=ValueWhen(Short,ShortPrice,1)*(1-TGT/100);
ShortSL=ValueWhen(Short,ShortPrice,1)*(1+SL/100);
Cover=  L<=ShortTgt OR H>=ShortSL;


SellPrice = IIf(Sell, IIf(H>=BuyTgt, BuyTgt, BuySL), Null);  
CoverPrice = IIf(Cover, IIf(L<=ShortTgt, ShortTgt, ShortSL), Null);  

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


printf("\nBuy : " + Buy );   
printf("\nSell : " + Sell );  
printf("\nShort : " + Short );  
printf("\nCover : " + Cover );  
printf("\nBuyPrice : " + BuyPrice );
printf("\nShortPrice : " + ShortPrice ); 
printf("\nSellPrice : " + SellPrice ); 
printf("\nCoverPrice : " + CoverPrice ); 
printf("\nBuyTgt : " + BuyTgt );  
printf("\nBuySL : " + BuySL ); 
printf("\nShortTgt : " + ShortTgt );  
printf("\nShortSL : " + ShortSL ); 


/* 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(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);
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorWhite, 0, H, Offset=25);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorWhite, 0,L, Offset=-25);

_SECTION_END();

Previous
Next Post »