// Downloaded From https://www.WiseStockTrader.com BuyAdjusted=0; BuyPriceAdjusted=0; ShortAdjusted=0; ShortPriceAdjusted=0; SellAdjusted=0; SellPriceAdjusted=0; CoverAdjusted=0; CoverPriceAdjusted=0; function calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr) { if( ((C[i-1]>ML[i] AND L[i]ML[i] AND L[i]ema1[i] AND TimeWindowTrade[i] ) { BuyAdjusted[i]=1; BuyPriceAdjusted[i]=Min(O[i],floor(ML[i]/TickSize)*TickSize)+slip; for(j=i+delay;j=endTradeTime) { SellAdjusted[j]=1; SellPriceAdjusted[j]=O[j]-slip; i=j+1; break; } else if(C[j-1]HL[j]) { SellAdjusted[j]=1; SellPriceAdjusted[j]=Max(O[j],ceil(HL[j]/TickSize)*TickSize)-slip; i=j+1; break; } else if (j==BarCount-1) { i=BarCount; break; } } } return i; } procedure buySellShortCover_proc(R3R4,S3S4,R1S1,R1,R2,R3,R4,R5,R6,R7,R8,S1,S2,S3,S4,S5,S6,S7,S8,S4S5,S5S6,S6S7,S7S8,R4R5,R5R6,R6R7,R7R8, firstTradeBarOfDay,timearr,endTradeTime,TickSize,ema1,TimeWindowTrade) { delay=1; slip=TickSize*0; for(i=1;i=BarCount-1) break; // long trade at R6 ML=R6;LL=R5R6;HL=R6R7; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at R5 ML=R5;LL=R4R5;HL=R5R6; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at R4 ML=R4;LL=R3R4;HL=R4R5; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at R3 ML=R3;LL=R2;HL=R3R4; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at R2 ML=R2;LL=R1;HL=R3; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at R1 ML=R1;LL=R1S1;HL=R2; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at S1 ML=S1;LL=S2;HL=R1S1; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at S2 ML=S2;LL=S3;HL=S1; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at S3 ML=S3;LL=S3S4;HL=S2; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at S4 ML=S4;LL=S4S5;HL=S3S4; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at S5 ML=S5;LL=S5S6;HL=S4S5; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at S6 ML=S6;LL=S6S7;HL=S5S6; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; // long trade at S7 ML=S7;LL=S7S8;HL=S6S7; i=calculateLongEntryExit(i,ML,LL,HL,delay,ema1,TimeWindowTrade,slip,endTradeTime,timearr); if(i>=BarCount-1) break; } } SetTradeDelays(0,0,0,0); SetOption("CommissionMode",3); SetOption("CommissionAmount",2.01); SetOption("FuturesMode",True); SetOption("PriceBoundChecking",False); SetOption("AllowSameBarExit",True); NumContracts=1; PositionSize=NumContracts*MarginDeposit; SetOption("MaxOpenPositions",5); beginCalcTime=093000;endCalcTime=160000; beginTradeTime=093000;endTradeTime=155500; timeWindowTrade=TimeNum()>=beginTradeTime AND TimeNum()<=endTradeTime; timeWindowCalc=TimeNum()>=beginCalcTime AND TimeNum()<=endCalcTime; firstBarOfDay=TimeNum()>=beginCalcTime ;firstBarOfDay=(firstBarOfDay-Ref(firstBarOfDay,-1))==1; lastBarOfDay=TimeNum()>=endCalcTime;lastBarOfDay=(lastBarOfDay-Ref(lastBarOfDay,-1))==1; firstTradeBarOfDay=TimeNum()>=beginTradeTime;firstTradeBarOfDay=(firstTradeBarOfDay-Ref(firstTradeBarOfDay,-1))==1; lastTradeBarOfDay=TimeNum()>=endTradeTime;lastTradeBarOfDay=(lastTradeBarOfDay-Ref(lastTradeBarOfDay,-1))==1; ttt=firstBarOfDay OR lastBarOfDay; inTrade=Flip(firstBarOfDay,LastBarOfDay); myHigh=ValueWhen(timeWindowCalc,HighestSince(firstBarOfDay,High)); myLow=ValueWhen(timeWindowCalc,LowestSince(firstBarOfDay,Low)); myClose=ValueWhen(lastBarOfDay,C); myOpen=ValueWhen(firstBarOfDay,O); DH=TimeFrameCompress(myHigh,inDaily,compressLast); DL=TimeFrameCompress(myLow,inDaily,compressLast); DC=TimeFrameCompress(myClose,inDaily,compressLast); bk=1;DH=Ref(DH,-bk);DL=Ref(DL,-bk);DC=Ref(DC,-bk); YHigh=TimeFrameExpand(DH,inDaily,expandFirst); YLow=TimeFrameExpand(DL,inDaily,expandFirst); YClose=TimeFrameExpand(DC,inDaily,expandFirst); fact=1.1; R1=YClose+((YHigh-Ylow)*fact)/12; R2=YClose+((YHigh-Ylow)*fact)/6; R3=YClose+((YHigh-Ylow)*fact)/4; R4=YClose+((YHigh-Ylow)*fact)/2; S1=YClose-((YHigh-Ylow)*fact)/12; S2=YClose-((YHigh-Ylow)*fact)/6; S3=YClose-((YHigh-Ylow)*fact)/4; S4=YClose-((YHigh-Ylow)*fact)/2; R5=((YHigh-Ylow)*0.82)+YClose; R6=((YHigh-Ylow)*1.09)+YClose; R7=((YHigh-Ylow)*1.35)+YClose; R8=((YHigh-Ylow)*1.62)+YClose; S5=YClose-((YHigh-Ylow)*0.82); S6=YClose-((YHigh-Ylow)*1.09); S7=YClose-((YHigh-Ylow)*1.35); S8=YClose-((YHigh-Ylow)*1.62); R3R4=(R3+R4)/2; S3S4=(S3+S4)/2; R1S1=(R1+S1)/2; S4S5=(S4+S5)/2; S5S6=(S5+S6)/2; S6S7=(S6+S7)/2; S7S8=(S7+S8)/2; R4R5=(R4+R5)/2; R5R6=(R5+R6)/2; R6R7=(R6+R7)/2; R7R8=(R7+R8)/2; per=Optimize("per",40,2,100,1); ema1=Ref(EMA(C,per),-1); buySellShortCover_proc(R3R4,S3S4,R1S1,R1,R2,R3,R4,R5,R6,R7,R8,S1,S2,S3,S4,S5,S6,S7,S8,S4S5,S5S6,S6S7,S7S8,R4R5,R5R6,R6R7,R7R8, firstTradeBarOfDay,TimeNum(),endTradeTime,TickSize,ema1,TimeWindowTrade); Buy=BuyAdjusted; BuyPrice=BuyPriceAdjusted; Short=ShortAdjusted; ShortPrice=ShortPriceAdjusted; Sell=SellAdjusted; SellPrice=SellPriceAdjusted; Cover=CoverAdjusted; CoverPrice=CoverPriceAdjusted; GraphXSpace = 5;SetChartOptions(0, chartShowDates); SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey))); Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,0,0,0,0); if(Interval()==in5Minute) { PlotPivots = ParamToggle("Main Pivots","Show|Hide",0); Plottop = ParamToggle("Top Pivots","Show|Hide",0); Plotbot = ParamToggle("Bottom Pivots","Show|Hide",0); Plotmid = ParamToggle("Middle Pivots","Show|Hide",0); if (PlotPivots==0) { Plot(R3,"",ColorRGB(0,255,0),styleThick,0,0,0,-1); Plot(S3,"",ColorRGB(255-0,255-255,255-0),styleThick,0,0,0,-1); Plot(R4,"",ColorRGB(0,100,0),styleThick,0,0,0,-1); Plot(S4,"",ColorRGB(255-0,255-100,255-0),styleThick,0,0,0,-1); Plot(ema1,"",ColorRGB(80,80,80),styleDashed,0,0,0,-1); PlotOHLC(R4,R4,R3,R3,"",ColorRGB(30,0,0),styleCloud|styleNoLabel,0,0,0,-2); PlotOHLC(S3,S3,S4,S4,"",ColorRGB(0,30,0),styleCloud|styleNoLabel,0,0,0,-2); Plot(R3R4,"",ColorRGB(181,206,162),styleDashed,0,0,0,-1); Plot(S3S4,"",ColorRGB(255,182,193),styleDashed,0,0,0,-1); if(Plottop==0) { Plot(R8,"",ColorRGB(255-104,255-34,255-139),styleLine); Plot(R5,"",ColorRGB(202,255,112),styleLine); Plot(R6,"",ColorRGB(238,180,180),styleLine); Plot(R7,"",ColorRGB(255,64,64),styleLine); Plot(R4R5,"",colorWhite,styleDashed); Plot(R5R6,"",colorWhite,styleDashed); Plot(R6R7,"",colorWhite,styleDashed); Plot(R7R8,"",colorWhite,styleDashed); } if(Plotbot==0) { Plot(S8,"",ColorRGB(104,34,139),styleLine); Plot(S5,"",ColorRGB(255-202,255-255,255-112),styleLine); Plot(S6,"",ColorRGB(255-238,255-180,255-180),styleLine); Plot(S7,"",ColorRGB(255-255,255-64,255-64),styleLine); Plot(S4S5,"",colorWhite,styleDashed); Plot(S5S6,"",colorWhite,styleDashed); Plot(S6S7,"",colorWhite,styleDashed); Plot(S7S8,"",colorWhite,styleDashed); } if(Plotmid==0) { Plot(R1S1,"",ColorRGB(255,255,255),styleDashed); Plot(R2,"",ColorRGB(132,112,255),styleLine); Plot(R1,"",ColorRGB(255,187,255),styleLine); Plot(S1,"",ColorRGB(255-255,255-187,255-255),styleLine); Plot(S2,"",ColorRGB(255-132,255-112,255-255),styleLine); } PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorDarkGreen,0,L,-15); PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0); PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15); PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0); PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeNone),colorRed,0,H,IIf(Short AND Sell,-30,-15)); PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0); PlotShapes(IIf(Cover,shapeSmallUpTriangle,shapeNone),colorDarkGreen,0,L,IIf(Cover AND Buy,-30,-15)); PlotShapes(IIf(Cover,shapeSmallCircle,shapeNone),colorWhite,0,CoverPrice,0); Plot(firstTradeBarOfDay,"",ColorRGB(0,0,255),styleHistogram|styleThick|styleOwnScale|styleNoLabel,0,1,0,-0); Plot(lastTradeBarOfDay,"",ColorRGB(200,200,200),styleHistogram|styleThick|styleOwnScale|styleNoLabel,0,1,0,0); } }