// Downloaded From https://www.WiseStockTrader.com KeltnerBands = ParamToggle("Keltner Bands","Show|Hide",1); fibs = ParamToggle("Plot Fibs","Off|On",0); ICHIMOKU = ParamToggle("Plot ICHIMOKU ","Off|On",0); BBand = ParamToggle("BolliBand", "Show|Hide", 0); aama = ParamToggle("Plot Ema ","Off|On",1); ahl = ParamToggle("Plot YHiLo ","Off|On",0); text = ParamToggle("Fib Text","Off|On",1); _SECTION_BEGIN("Small Triggers"); p1 = Param("TL 1 Periods", 20, 5, 50, 1); p2 = Param("TL 2 Periods", 5, 3, 25, 1); TL1 = LinearReg(C, p1); TL2 = EMA(TL1, p2); Col1 = IIf(TL1 > TL2, ParamColor("TL Up Colour", colorBrightGreen), ParamColor("TL Dn Colour", colorCustom12)); Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel); _SECTION_END(); XNAME = Name(); VAL_EXISTS = 0; T2= ""; Prd1=Param("ATR Period",4,1,20,1); Prd2=Param("Look Back",8,1,20,1); green = HHV(LLV(L,Prd1)+ATR(Prd1),Prd2); red = LLV(HHV(H,Prd1)-ATR(Prd1),Prd2); HighClosePercent = (H - C)*100/H; HighLowPercent = MA((H - L)*100/H,25); barColor=IIf(C>Green ,colorBlue,IIf(C < RED,colorRed,IIf(HighClosePercent>5,colorYellow,IIf(HighLowPercent>5 AND ROC(C,1,True)<-3,colorRed,colorWhite)))); ( IIf(C>Green AND ROC(C,1,True)<-4.5,colorBlue,colorBlack)); flowerOpen = O; flowerClose = C; flowerHigh= H; flowerLow = L; _SECTION_BEGIN("Price"); PlotOHLC( IIf(flowerOpen ( LLV( L, 20 ) + 2 * ATR( 10 ) ) AND EMA( Close, 20 ) > EMA( Close, 40 ); DnTrend = C < ( HHV( H, 20 ) - 2 * ATR( 10 ) ) AND EMA( Close, 20 ) < EMA( Close, 40 ); Color = IIf( UpTrend, colorBlue, IIf( DnTrend, colorRed, colorOrange) ); // Plots a 20 period Donchian channel Plot( C, "Price", Color, styleCandle | styleThick ); NewDay = IIf(Day() != Ref(Day(), -1) OR BarIndex() == LastValue(BarIndex()), 1, 0); //Plot(NewDay, "", 47, 2 + 32768 + 4096, Minvalue = 0, Maxvalue = 1); _SECTION_END(); //////////////////////////////////////////////////////////////////////////////// _SECTION_BEGIN("PIVOT POINTS"); /* This code calculates the previous days high, low and close */ Hi1 = IIf(Day()!=Ref(Day(),-1),Ref(HighestSince(Day()!=Ref(Day(),-1),H,1),-1),0); Hi = ValueWhen(Day()!=Ref(Day(),-1),Hi1,1); Lo1 = IIf(Day()!=Ref(Day(),-1),Ref(LowestSince(Day()!=Ref(Day(),-1),L,1),-1),0); Lo = ValueWhen(Day()!=Ref(Day(),-1),Lo1,1); Cl1 = IIf(Day()!=Ref(Day(),-1),Ref(C,-1),0); C1 = ValueWhen(Day()!=Ref(Day(),-1),Cl1,1); wHi=TimeFrameGetPrice("H",inWeekly,-1); wLo=TimeFrameGetPrice("L",inWeekly,-1); wCl=TimeFrameGetPrice("C",inWeekly,-1); mHi=TimeFrameGetPrice("H",inMonthly,-1); mLo=TimeFrameGetPrice("L",inMonthly,-1); mCl=TimeFrameGetPrice("C",inMonthly,-1); //---------------------------------------------------------------------------------- /* This code calculates Daily Piovts */ rg = (Hi - Lo); bp = (Hi + Lo + C1)/3; bpI = LastValue (bp,1); r1 = (bp*2)-Lo; r1I = LastValue (r1,1); s1 = (bp*2)-Hi; s1I = LastValue (s1,1); r2 = bp + r1 - s1; r2I = LastValue (r2,1); s2 = bp - r1 + s1; s2I = LastValue (s2,1); r3 = bp + r2 - s1; r3I = LastValue (r3,1); s3 = bp - r2 + s1; s3I = LastValue (s3,1); r4 = bp + r2 - s2; r4I = LastValue (r4,1); s4 = bp - r2 + s2; s4I = LastValue (s4,1); wrg = (wHi - wLo); wbp = (wHi + wLo + wCl)/3; wbpI = LastValue (wbp,1); wr1 = (wbp*2)-wLo; wr1I = LastValue (wr1,1); ws1 = (wbp*2)-wHi; ws1I = LastValue (ws1,1); wr2 = wbp + wr1 - ws1; wr2I = LastValue (wr2,1); ws2 = wbp - wr1 + ws1; ws2I = LastValue (ws2,1); wr3 = wbp + wr2 - ws1; wr3I = LastValue (wr3,1); ws3 = wbp - wr2 + ws1; ws3I = LastValue (ws3,1); wr4 = wbp + wr2 - ws2; wr4I = LastValue (wr4,1); ws4 = wbp - wr2 + ws2; ws4I = LastValue (ws4,1); mrg = (mHi - mLo); mobp = (mHi + mLo + mCl)/3; mobpI = LastValue (mobp,1); mr1 = (mobp*2)-mLo; mr1I = LastValue (mr1,1); ms1 = (mobp*2)-mHi; ms1I = LastValue (ms1,1); mr2 = mobp + mr1 - ms1; mr2I = LastValue (mr2,1); ms2 = mobp - mr1 + ms1; ms2I = LastValue (ms2,1); if(ppl==1) { Plot(bp,"",colorWhite,styleLine|styleLine|styleNoRescale); Plot(s1,"",colorBrightGreen,styleDashed|styleNoRescale); Plot(s2,"",colorBrightGreen,styleDashed|styleNoRescale); Plot(s3,"",colorBrightGreen,styleDashed|styleNoRescale); Plot(s4,"",colorBrightGreen,styleDashed|styleNoRescale); Plot(r1,"",colorRed,styleDashed|styleNoRescale); Plot(r2,"",colorRed,styleDashed|styleNoRescale); Plot(r3,"",colorRed,styleDashed|styleNoRescale); Plot(r4,"",colorRed,styleDashed|styleNoRescale); Plot(wbp,"",colorTan,styleDashed|styleLine|styleNoRescale); Plot(ws1,"",colorBlue,styleDashed|styleNoRescale); Plot(ws2,"",colorBlue,styleDashed|styleNoRescale); //Plot(ws3,"",colorPaleGreen,styleDashed|styleNoRescale); //Plot(ws4,"",colorPaleGreen,styleDashed|styleNoRescale); Plot(wr1,"",colorYellow,styleDashed|styleNoRescale); Plot(wr2,"",colorYellow,styleDashed|styleNoRescale); //Plot(wr3,"",colorPaleBlue,styleDashed|styleNoRescale); //Plot(wr4,"",colorPaleBlue,styleDashed|styleNoRescale); Plot(mobp,"",colorTan,styleDashed|styleLine|styleNoRescale); Plot(ms1,"",colorPaleGreen,styleDashed|styleNoRescale); Plot(mr1,"",colorDarkRed,styleDashed|styleNoRescale); PlotText(" Pivot = " + WriteVal(bp,fraction), LastValue(BarIndex())-(numbars/Hts), bpI +0.05, colorWhite); PlotText(" Resistance 1 = " + WriteVal(r1,fraction), LastValue(BarIndex())-(numbars/Hts), r1I +0.05, colorRed); PlotText(" Support 1 = " + WriteVal(s1,fraction), LastValue(BarIndex())-(numbars/Hts), s1I +0.05, colorGreen); PlotText(" Resistance 2 = " + WriteVal(r2,fraction), LastValue(BarIndex())-(numbars/Hts), r2I +0.05, colorRed); PlotText(" Support 2 = " + WriteVal(s2,fraction), LastValue(BarIndex())-(numbars/Hts), s2I +0.05, colorBrightGreen); PlotText(" Resistance 3 = " + WriteVal(r3,fraction), LastValue(BarIndex())-(numbars/Hts), r3I +0.05, colorRed); PlotText(" Support 3 = " + WriteVal(s3,fraction), LastValue(BarIndex())-(numbars/Hts), s3I +0.05, colorBrightGreen); PlotText(" Resistance 4 = " + WriteVal(r4,fraction), LastValue(BarIndex())-(numbars/Hts), r4I +0.05, colorRed); PlotText(" Support 4 = " + WriteVal(s4,fraction), LastValue(BarIndex())-(numbars/Hts), s4I +0.05, colorBrightGreen); PlotText(" W Pivot = " + WriteVal(wbp,fraction), LastValue(BarIndex())-(numbars/Hts), wbpI +0.05, colorTan); PlotText(" W Resistance 1 = " + WriteVal(wr1,fraction), LastValue(BarIndex())-(numbars/Hts), wr1I +0.05, colorYellow); PlotText(" W Support 1 = " + WriteVal(ws1,fraction), LastValue(BarIndex())-(numbars/Hts), ws1I +0.05, colorBlue); PlotText(" W Resistance 2 = " + WriteVal(wr2,fraction), LastValue(BarIndex())-(numbars/Hts), wr2I +0.05, colorYellow); PlotText(" W Support 2 = " + WriteVal(ws2,fraction), LastValue(BarIndex())-(numbars/Hts), ws2I +0.05, colorBlue); //PlotText(" W Resistance 3 = " + WriteVal(wr3,fraction), LastValue(BarIndex())-(numbars/Hts), wr3I +0.05, colorPaleBlue); //PlotText(" W Support 3 = " + WriteVal(ws3,fraction), LastValue(BarIndex())-(numbars/Hts), ws3I +0.05, colorPaleGreen); //PlotText(" W Resistance 4 = " + WriteVal(wr4,fraction), LastValue(BarIndex())-(numbars/Hts), wr4I +0.05, colorPaleBlue); //PlotText(" W Support 4 = " + WriteVal(ws4,fraction), LastValue(BarIndex())-(numbars/Hts), ws4I +0.05, colorPaleGreen); PlotText(" M Pivot = " + WriteVal(mobp,fraction), LastValue(BarIndex())-(numbars/Hts), mobpI+0.05, colorTan); PlotText(" M Resistance 1 = " + WriteVal(mr1,fraction), LastValue(BarIndex())-(numbars/Hts), mr1I+0.05, colorPaleBlue); PlotText(" M Support 1 = " + WriteVal(ms1,fraction), LastValue(BarIndex())-(numbars/Hts), ms1I+0.05, colorPaleGreen); } _SECTION_END(); Pivot = ParamToggle("Pivot", "weekly|monthly", 1); if(Pivot) { H1 = TimeFrameGetPrice("H", inMonthly, -1); // yesterdays high L1 = TimeFrameGetPrice("L", inMonthly, -1); // low C1= TimeFrameGetPrice("C", inMonthly, -1); // close } else { H1 = TimeFrameGetPrice("H", inWeekly, -1); // yesterdays high L1 = TimeFrameGetPrice("L", inWeekly, -1); // low C1= TimeFrameGetPrice("C", inWeekly, -1); // close } _SECTION_BEGIN("Stupid Functions"); function HAI_F1(no) { res=HHV(H,no); sup=LLV(L,no); avd=IIf(C>Ref(res,-1),1,IIf(CRef(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))), IIf(CRef(state,-1); ss=stateMDI(n)AND Signal(s)PDI(p)AND Signal(s)>MACD(m)); } _SECTION_END(); ///////////////rahul prev=AMA2(C,1,0); d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))), IIf(CRef(state,-1); ss=stateRef(res,-1),1,IIf(C0; Sell = MACD()<0; Buy =ExRem(Buy,Sell); Sell =ExRem(Sell,Buy); shape = Buy * shapeUpTriangle + Sell * shapeDownTriangle; PlotShapes( shape, IIf( Buy, colorAqua, colorCustom12 ), 0, IIf( Buy, Low, High ) ); WriteIf(s,"EXIT all Short positions\nif trading long positions, enter long Now-\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(L+.75*ATR(5),1.4)+" ,",""); WriteIf(ss,"exit all long positions today with a Market On Close (MOC) order\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(Ref(H+.75*ATR(5), -1),1.4)+",",""); WriteIf( sss ,"No trading signals today.","") ; dist = ATR(21); for (i=0; iMDI(10)AND Signal(29)PDI(20)AND Signal(29)>MACD(13); //Plot( 2, /* defines the height of the ribbon in percent of pane width */"ribbon", //IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */ //styleOwnScale|styleArea|styleNoLabel, -0.5, 100 ); _SECTION_END(); Buy = s AND a AND uptrend ; Short = ss AND b AND downtrend ; Sell = ss AND b AND downtrend ; Cover = s AND a AND uptrend ; Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy); Cover=ExRem(Cover,Short); Short=ExRem(Short,Cover); Filter=Buy OR Sell; Filter= Cover OR Short; AddColumn( Buy, "buy", 1); AddColumn(Sell, "Sell", 1); AddColumn(Close,"Close",1.2); AddColumn(Volume,"Volume",1.0); // Plot the Buy and Sell arrows. shape = Buy * shapeUpArrow + Sell * shapeDownArrow; PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-10); PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-20); PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15); PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20); PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30); PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25); // set background gradient colours SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 0,0,0 )),ParamColor("BgBottom", ColorRGB( 102,136,187 )),ParamColor("titleblock",ColorRGB( 255,255,255 ))); GraphXSpace = 5; /* -------------------------------------------------------------------------------------- */ //////////////////////////////////////////////////////////////////////////////////////////////// intraday = ParamToggle("Message Board","Show|Hide",1); showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0); style = a * styleStaircase + b * styleStaircase; PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High)); if (showsl == 0) Plot(supres,"Stop Loss",colorCustom14,styleDots); exitlong = Cross(supres, H); PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10); exitshort = Cross(L, supres); PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15); Buy = exitshort; Sell = exitlong; //Short = Sell; //Cover = Buy; Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); //Short = ExRem(Short, Cover); //Cover = ExRem(Cover, Short); AlertIf( Buy, "", "BUY @ " + C, 1 ); AlertIf( Sell, "", "SELL @ " + C, 2 ); for (i=BarCount-1; i>1; i--) { if (Buy[i] == 1) { entry = O[i]; sig = " INTRADAY BUY "; sl = supres[1]; tar1 = entry + (entry * .0040); tar2 = entry + (entry * .0080); tar3 = entry + (entry * .0120); tar4 = entry + (entry * .0160); tar5 = entry + (entry * .0200); tar6 = entry + (entry * .0240); tar7= entry + (entry * .0280); tar8 = entry + (entry * .0320); tar9 = entry + (entry * .0360); tar10 = entry + (entry * .0400); tar11 = entry + (entry * .0440); tar12 = entry + (entry * .0480); tar13= entry + (entry * .0520); tar14= entry + (entry * .0560); tar15= entry + (entry * .0600); tar16= entry + (entry * .0640); bars = i; i = 0; } if (Sell[i] == 1) { sig = " INTRADAY SELL"; entry = O[i]; sl = supres[i]; tar1 = entry - (entry * .0040); tar2 = entry - (entry * .0080); tar3 = entry - (entry * .0120); tar4 = entry - (entry * .0160); tar5 = entry - (entry * .0200); tar6 = entry - (entry * .0240); tar7= entry - (entry * .0280); tar8= entry - (entry * .0320); tar9= entry - (entry * .0360); tar10 = entry - (entry * .0400); tar11 = entry - (entry * .0440); tar12 = entry - (entry * .0480); tar13= entry - (entry * .0520); tar14= entry - (entry * .0560); tar15= entry - (entry * .0600); tar16= entry - (entry * .0640); bars = i; i = 0; } } Offset = 20; Clr = IIf(sig == "BUY", colorLime, colorRed); ssl = IIf(bars == BarCount-1, supres[BarCount-1], Ref(supres, -1)); sl = ssl[BarCount-1]; printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago"); printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3); printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)); if (intraday == 0) { GfxSelectFont( "Tahoma", 13, 500 ); GfxSetBkMode( 1 ); GfxSetTextColor( colorWhite ); if (sig =="BUY") GfxSelectSolidBrush( colorGreen ); // this is the box background color else GfxSelectSolidBrush( colorOrange ); // this is the box background color pxHeight = Status( "pxchartheight" ) ; xx = Status( "pxchartwidth"); Left = 800; width =310; x = 10; x2 = 160; y = Status( "pxchartheight" ); GfxSelectPen( colorDarkRed, 1); // broader color GfxRoundRect( x, y - 600, x2, y , 5, 5 ) ; GfxTextOut( ("" + WriteIf(sig =="Buy",sig + " @ ",sig + " @") + " : " + entry) ,13, y-460); GfxTextOut( ("Trailing SL : " + sl + " "), 13, y-440); GfxTextOut( ("TGT:1 : " + tar1), 13, y -420); GfxTextOut( ("TGT:2 : " + tar2), 13,y-400); GfxTextOut( ("TGT:3 : " + tar3), 13,y-380); GfxTextOut( ("TGT:4 : " + tar4), 13,y-340); } /* -------------------------------------------------------------------------------------- */ //////////////////////////////////////////////////////////////////////////////////////////////// m=IIf(ParamList("select type","Message Board|Message Board1")=="Message Board",-1,0); messageboard = ParamToggle("Message Board1","Show|Hide",1); showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0); m1 = ParamToggle("Message Board1","Show|Hide",1); style = a * styleStaircase + b * styleStaircase; PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High)); if (showsl == 0) Plot(supres,"Stop Loss",colorCustom14,styleDots); exitlong = Cross(supres, H); PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10); exitshort = Cross(L, supres); PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15); Buy = exitshort; Sell = exitlong; //Short = Sell; //Cover = Buy; Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); //Short = ExRem(Short, Cover); //Cover = ExRem(Cover, Short); AlertIf( Buy, "", "BUY @ " + C, 1 ); AlertIf( Sell, "", "SELL @ " + C, 2 ); for (i=BarCount-1; i>1; i--) { if (Buy[i] == 1) { entry = O[i]; sig = "BUY"; sl = supres[1]; tar1 = entry + (entry * .0090); tar2 = entry + (entry * .0150); tar3 = entry + (entry * .0250); tar4 = entry + (entry * .0350); tar5 = entry + (entry * .0450); tar6 = entry + (entry * .0550); tar7 = entry + (entry * .0650); tar8 = entry + (entry * .0750); tar9 = entry + (entry * .1000); bars = i; i = 0; } if (Sell[i] == 1) { sig = "SELL"; entry = O[i]; sl = supres[i]; tar1 = entry - (entry * .0090); tar2 = entry - (entry * .0150); tar3 = entry - (entry * .0250); tar4 = entry - (entry * .0325); tar5 = entry - (entry * .0500); tar6 = entry - (entry * .0750); tar7 = entry - (entry * .0850); tar8 = entry - (entry * .0950); tar9 = entry - (entry * .1000); bars = i; i = 0; } } Offset = 20; Clr = IIf(sig == "BUY", colorLime, colorRed); ssl = IIf(bars == BarCount-1, supres[BarCount-1], Ref(supres, -1)); sl = ssl[BarCount-1]; printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago"); printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3); printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)); if (messageboard == 0) { GfxSelectFont( "Tahoma", 13, 100 ); GfxSetBkMode( 1 ); GfxSetTextColor( colorWhite ); if (sig =="BUY") GfxSelectSolidBrush( colorDarkRed ); // this is the box background color else GfxSelectSolidBrush( colorRed ); // this is the box background color pxHeight = Status( "pxchartheight" ) ; xx = Status( "pxchartwidth"); CENTER = 20; width =31; x = 2; x20 = 180; y = Status( "pxchartheight" ); GfxSelectPen( colorDarkRed, 1); // broader color GfxRoundRect( x, y - 400, x20, y , 7, 7 ) ; GfxTextOut( Name(),13,y-398); GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-380); GfxTextOut( ("Trailing SL : " + sl + " "), 13, y-360); GfxTextOut( ("TGT:1 : " + tar1), 13, y -340); GfxTextOut( ("TGT:2 : " + tar2), 13,y-320); GfxTextOut( ("TGT:3 : " + tar3), 13, y -300); GfxTextOut( ("TGT:4 : " + tar4), 13,y-280); GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-0);; } /* -------------------------------------------------------------------------------------- */ //////////////////////////////////////////////////////////////////////////////////////////////// m=IIf(ParamList("select type","Message Board|Message Board1|Message Board2")=="Message Board",-1,0); messageboard = ParamToggle("Message Board2","Show|Hide",1); showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0); m2 = ParamToggle("Message Board2","Show|Hide",0); style = a * styleStaircase + b * styleStaircase; PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High)); if (showsl == 0) Plot(supres,"Stop Loss",colorCustom14,styleDots); exitlong = Cross(supres, H); PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10); exitshort = Cross(L, supres); PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15); Buy = exitshort; Sell = exitlong; //Short = Sell; //Cover = Buy; Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); //Short = ExRem(Short, Cover); //Cover = ExRem(Cover, Short); AlertIf( Buy, "", "BUY @ " + C, 1 ); AlertIf( Sell, "", "SELL @ " + C, 2 ); for (i=BarCount-1; i>1; i--) { if (Buy[i] == 1) { entry = O[i]; sig = "BUY LONG TERM"; sl = supres[1]; tar1 = entry + (entry * .0125); tar2 = entry + (entry * .0250); tar3 = entry + (entry * .0375); tar4 = entry + (entry * .0500); tar5 = entry + (entry * .0625); tar6 = entry + (entry * .0800); tar7 = entry + (entry * .0925); tar8 = entry + (entry * .1050); tar9 = entry + (entry * .1175); bars = i; i = 0; } if (Sell[i] == 1) { sig = "SELL LONG TERM"; entry = O[i]; sl = supres[i]; tar1 = entry - (entry * .0125); tar2 = entry - (entry * .0250); tar3 = entry -(entry * .0375); tar4 = entry - (entry * .0500); tar5 = entry - (entry * .0625); tar6 = entry - (entry * .0800); tar7 = entry - (entry * .0925); tar8 = entry - (entry * .1050); tar9 = entry - (entry * .1175); bars = i; i = 0; } } Offset = 20; Clr = IIf(sig == "BUY", colorLime, colorRed); ssl = IIf(bars == BarCount-1, supres[BarCount-1], Ref(supres, -1)); sl = ssl[BarCount-1]; printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago"); printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3); printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)); if (messageboard == 0) { GfxSelectFont( "Tahoma", 13, 100 ); GfxSetBkMode( 1 ); GfxSetTextColor( colorWhite ); if (sig =="BUY ") GfxSelectSolidBrush( colorBlue ); // this is the box background color else GfxSelectSolidBrush( colorBlack ); // this is the box background color pxHeight = Status( "pxchartheight" ) ; xx = Status( "pxchartwidth"); CENTER = 20; width =31; x = 2; x20 = 180; y = Status( "pxchartheight" ); GfxSelectPen( colorDarkRed, 1); // broader color GfxRoundRect( x, y - 300, x20, y , 7, 7 ) ; GfxTextOut( Name(),13,y-298); GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-280); GfxTextOut( ("Trailing SL : " + sl + " "), 13, y-260); GfxTextOut( ("TGT:1 : " + tar1), 13, y -240); GfxTextOut( ("TGT:2 : " + tar2), 13,y-220); GfxTextOut( ("TGT:3 : " + tar3), 13, y -200); GfxTextOut( ("TGT:4 : " + tar4), 13,y-180); } //rahul _SECTION_BEGIN("Swing2"); no = 22; sloss = HAI_F1(no); a = HAI_F2(no); b = HAI_F3(no); state = HAI_F4(no); sss = HAI_F5(no); uptrend = HAI_F6(20,10,29,22); downtrend = HAI_F7(20,10,29,13); style = a * styleStaircase + b * styleStaircase; PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High)); _SECTION_END(); col=IIf(state == 1 ,51,IIf(state ==0,4,1)); Plot(C,"",Col,64); PlotShapes( shapeUpArrow * a, colorGreen,0,L); PlotShapes( shapeDownArrow * b, colorRed,0,H); Filter = a OR b OR sss ; AddColumn(C,"close",1.2); AddColumn( IIf( a, 66,1 ), "buy", formatChar, 1, bkcolor =IIf (a,colorYellow, colorPink )); AddColumn( IIf( b, 83,1 ), "sell", formatChar, 1, bkcolor =IIf (b,colorPink, colorYellow )); AddColumn( IIf( sss, 87,1 ), "wait", formatChar, 1, bkcolor =IIf (sss,colorYellow, colorRed )); _SECTION_BEGIN("Intraday AFL System"); Buy = a; Sell = b; /* PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-30); PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0, L, Offset=-40); PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-35); PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=30); PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=40); PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-35); dist = ATR(20); for (i=0; i Ref( ChandelierHL(ATR(3),20), -1); //e =Close < Ref( ChandelierHL(ATR(3),20), -1); //f = Close < Ref( ChandelierHL(ATR(3),20), -1); //g = Close > Ref( ChandelierHL(ATR(3),20), -1); Buy = a AND uptrend ; Short = b AND downtrend ; Sell = b AND downtrend ; Cover = a AND uptrend; Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy); Cover=ExRem(Cover,Short); Short=ExRem(Short,Cover); Filter=Buy OR Sell; Filter= Cover OR Short; AddColumn( Buy, "Buy", 1); AddColumn(Sell, "Sell", 1); AddColumn(Close,"Close",1.2); AddColumn(Volume,"Volume",1.0); // Plot the Buy and Sell arrows. shape = Buy * shapeUpArrow + Sell * shapeDownArrow; PlotShapes(shape, IIf(Buy,colorGreen,colorRed), 0, IIf(Buy,Low,High)); //attack Plot(sloss,"Swing",colorCustom8,styleDots); //SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )), //ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 ))); //Alerts AlertIf( Buy, "SOUND C:\\Windows\\Media\\tada.wav", "Buy",1,1+2+4+8); AlertIf( Short, "SOUND C:\\Windows\\Media\\notify.wav", "Short",2,1+2+4+8); GraphXSpace = 5; /* -------------------------------------------------------------------------------------- */ //SetChartBkColor(colorDarkOliveGreen = 46); SetChartOptions(0,chartShowArrows|chartShowDates); /* -------------------------------------------------------------------------------------- */ //do not touch //////////////////////////////////////////////////////////////////////////////////////////////// messageboard = ParamToggle("Message Board","Show|Hide",0); showsl = ParamToggle("Stop Loss Line", "Show|Hide", 0); style = a * styleStaircase + b * styleStaircase; PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High)); if (showsl == 0) Plot(sloss,"Stop Loss",colorCustom8,styleDots); exitlong = Cross(sloss, H); PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10); exitshort = Cross(L, sloss); PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15); Buy = exitshort; Sell = exitlong; //Short = Sell; //Cover = Buy; Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); //Short = ExRem(Short, Cover); //Cover = ExRem(Cover, Short); AlertIf( Buy, "", "BUY @ " + C, 1 ); AlertIf( Sell, "", "SELL @ " + C, 2 ); for (i=BarCount-1; i>1; i--) { if (Buy[i] == 1) { entry = O[i]; sig = "BUY"; sl = sloss[i]; tar1 = entry + (entry * .0040); tar2 = entry + (entry * .0085); tar3 = entry + (entry * .0179); bars = i; i = 0; } if (Sell[i] == 1) { sig = "SELL"; entry = O[i]; sl = sloss[i]; tar1 = entry - (entry * .0040); tar2 = entry - (entry * .0085); tar3 = entry - (entry * .0212); bars = i; i = 0; } } Offset = 20; Clr = IIf(sig == "BUY", colorLime, colorRed); ssl = IIf(bars == BarCount-1, sloss[BarCount-1], Ref(sloss, -1)); sl = ssl[BarCount-1]; printf("Last " + sig + " Signal came " + (BarCount-bars) + " bars ago"); printf("\n" + sig + " @ : " + entry + "\nStop Loss : " + sl + " (" + WriteVal(IIf(sig == "SELL",entry-sl,sl-entry), 2.2) + ")"+ "\nTarget_1 : " + tar1 + "\nTarget_2 : " + tar2 + "\nTarget_3 : " + tar3); printf("\nCurrent P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)); if (messageboard == 0) { GfxSelectFont( "Tahoma", 13, 100 ); GfxSetBkMode( 1 ); GfxSetTextColor( colorWhite ); if (sig =="BUY") GfxSelectSolidBrush( colorGreen ); // this is the box background color else GfxSelectSolidBrush( colorRed ); // this is the box background color pxHeight = Status( "pxchartheight" ) ; xx = Status( "pxchartwidth"); Left = 1100; width = 310; x = 05; x2 = 200; y = Status( "pxchartheight" ); GfxSelectPen( colorGreen, 1); // broader color GfxRoundRect( x, y - 143, x2, y , 7, 7 ) ; GfxTextOut( ( " AFLIntraday "), 10, y-140) ; GfxTextOut( Name(),13,y-120); GfxTextOut( ("" + WriteIf(sig =="BUY",sig + " @ ",sig + " @") + " : " + entry), 13, y-100); GfxTextOut( ("Trailing SL : " + sl + " "), 13, y-80); GfxTextOut( ("TGT:1 : " + tar1), 13, y -60); GfxTextOut( ("TGT:2 : " + tar2), 13,y-40); GfxTextOut( ("Current P/L : " + WriteVal(IIf(sig == "BUY",(C-entry),(entry-C)),2.2)), 13, y-20);; } ///////////////////////////// // Supertrend - Translated from Kolier MQ4 // see: http://kolier.li/indicator/kolier-supertrend-indi // translation in Amibroker AFL code by E.M.Pottasch, 2011 procedure calcTrend_proc(ATR_Period,tr,ATR_Multiplier,TrendMode,CalcPrice) { global buffer_line_down; global buffer_line_up; buffer_line_down = Null; buffer_line_up = Null; PHASE_NONE = 0; PHASE_BUY = 1; PHASE_SELL = -1; phase=PHASE_NONE; band_upper = 0;band_lower = 0; for(i = ATR_Period + 1; i < BarCount; i++) { band_upper = CalcPrice[i] + ATR_Multiplier * tr[i]; band_lower = CalcPrice[i] - ATR_Multiplier * tr[i]; if(phase==PHASE_NONE) { buffer_line_up[i] = CalcPrice[i]; buffer_line_down[i] = CalcPrice[i]; } if(phase!=PHASE_BUY && Close[i]>buffer_line_down[i-1] && !IsEmpty(buffer_line_down[i-1])) { phase = PHASE_BUY; buffer_line_up[i] = band_lower; buffer_line_up[i-1] = buffer_line_down[i-1]; } if(phase!=PHASE_SELL && Close[i]buffer_line_up[i-1]) { buffer_line_up[i] = band_lower; } else { buffer_line_up[i] = buffer_line_up[i-1]; } } if(phase==PHASE_SELL && ((TrendMode==0 && !IsEmpty(buffer_line_down[i-2])) || TrendMode==1) ) { if(band_upperRef(Avg,-1),H,L))); EW=Zig(RetroSuccessSecret,pr); //{ Plot on price chart } if (Option==0){ // will on elliot lines //Plot(EW, "EW", ParamColor("Color", colorBrown), ParamStyle("Style", styleNoLabel|styleThick)); } else { //{ Plot on own window } Plot(EWbuy-EWsell, "EW2", ParamColor("Color", colorRed), ParamStyle("Style", styleNoLabel|styleThick)); } //{ Buy/Sell Elliot Wave stuff } EWbuy=TroughBars(EW,pr)==1; EWsell=PeakBars(EW,pr)==1; Plot(C,"",47,128+4); PlotShapes(EWbuy*shapeUpArrow,5,0,L,-5); PlotShapes(EWsell*shapeDownArrow,4,0,H,-5); //-- Script End ------- _SECTION_END(); Option = ParamToggle("Insert To", "Price Chart|Indicator"); pr=Param("Elliot Wave minimum % move",0.5, 0.25,5,0.25); //{ Beginner Elliot Wave stuff } EWpk=PeakBars(H,pr)==0; EWtr=TroughBars(L,pr)==0; //{ Intermediate Elliot Wave stuff } zz=Zig(C,pr); zzHi=Zig(H,pr); zzLo=Zig(L,pr); Avg=(zzHi+zzLo)/2; Pivot = ParamToggle("Pivot", "weekly|monthly", 1); if(Pivot) { H1 = TimeFrameGetPrice("H", inMonthly, -1); // yesterdays high L1 = TimeFrameGetPrice("L", inMonthly, -1); // low C1= TimeFrameGetPrice("C", inMonthly, -1); // close } else { H1 = TimeFrameGetPrice("H", inWeekly, -1); // yesterdays high L1 = TimeFrameGetPrice("L", inWeekly, -1); // low C1= TimeFrameGetPrice("C", inWeekly, -1); // close } // PIVOT Calculation P = ( H1+ L1+ C1 )/3; R1 = P+(H1-L1)/2-(P-C1)/2; R2 = H1-L1+P; R3 = H1-L1+R1; R4 = H1-L1+R2; R5 = H1-L1+R3; R6 = H1-L1+R4; R7 = H1-L1+R5; R8 = H1-L1+R6; R9 = H1-L1+R7; R10 = H1-L1+R8; S1 = P -(H1-L1)/2-(P-C1)/2; S2 = P -(H1-L1); S3 = S1 -(H1-L1); S4 = S2 -(H1-L1); S5 = S3 -(H1-L1); S6 = S4 -(H1-L1); S7 = S5 -(H1-L1); S8 = S6 -(H1-L1); S9 = S7 -(H1-L1); S10 =S8 -(H1-L1); // PIVOT mid points MIDR1 = (P+R1)/2; MIDR2 = (R1+R2)/2; MIDR3 = (R2+R3)/2; MIDR4 = (R3+R4)/2; MIDR5 = (R4+R5)/2; MIDR6 = (R5+R6)/2; MIDR7 = (R6+R7)/2; MIDR8 = (R7+R8)/2; MIDR9 = (R8+R9)/2; MIDR10 = (R9+R10)/2; MIDS1 = (P+S1)/2; MIDS2 = (S1+S2)/2; MIDS3 = (S2+S3)/2; MIDS4 = (S3+S4)/2; MIDS5 = (S4+S5)/2; MIDS6 = (S5+S6)/2; MIDS7 = (S6+S7)/2; MIDS8 = (S7+S8)/2; MIDS9 = (S8+S9)/2; MIDS10 = (S9+S10)/2; n=130; per =11.5; x = Cum(1); s1=IIf(RSIa(L,n)>Min(RSIa(C,n),RSIa(O,n)),Min(RSIa (C,n),RSIa(O,n)),RSIa(L,n)); s11=IIf(RSIa(H,n)Min(RSIa(C,n),RSIa(O,n)),Min(RSIa (C,n),RSIa(O,n)),RSIa(L,n)); s11=IIf(RSIa(H,n) eb, colorGreen, colorRed ) ); Buy = ea > eb AND TimeNum() > 092000 AND TimeNum() < 150000; Sell = eb > ea OR TimeNum() > 150000; Short = 0; Cover = 0; Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); Short = ExRem(Short,Cover); Cover = ExRem(Cover,Short); SetTradeDelays(1,1,1,1); Factor=Param("Factor",6,1,10,1); Pd=Param("ATR Periods",6,1,100,1); Up=(H+L)/2+(Factor*ATR(Pd)); Dn=(H+L)/2-(Factor*ATR(Pd)); iATR=ATR(Pd); TrendUp=TrendDown=Null; trend[0]=1; changeOfTrend=0; flag=flagh=0; for (i = 1; i Up[i-1]) { trend[i]=1; if (trend[i-1] == -1) changeOfTrend = 1; } else if (Close[i]0) { flag=1; } else { flag=0; } if (trend[i]>0 && trend[i-1]<0) { flagh=1; } else { flagh=0; } if (trend[i]>0 && Dn[i]Up[i-1]) { Up[i]=Up[i-1]; } if (flag==1) { Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);; } if (flagh==1) { Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);; } if (trend[i]==1) { TrendUp[i]=Dn[i]; if (changeOfTrend == 1) { TrendUp[i-1] = TrendDown[i-1]; changeOfTrend = 0; } } else if (trend[i]==-1) { TrendDown[i]=Up[i]; if (changeOfTrend == 1) { TrendDown[i-1] = TrendUp[i-1]; changeOfTrend = 0; } } } Plot(TrendUp,"Trend",colorGreen); Plot(TrendDown,"Down",colorRed); Buy = trend==1; Sell=trend==-1; Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy); Short=Sell; Cover=Buy; BuyPrice=ValueWhen(Buy,C); SellPrice=ValueWhen(Sell,C); ShortPrice=ValueWhen(Short,C); CoverPrice=ValueWhen(Cover,C); Title = EncodeColor(colorWhite)+ "Simple Trading" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) + " - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+ "Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+ EncodeColor(colorLime)+ WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+ WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+ WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+ WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"",""); 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); TrendSL=IIf(trend==1,TrendUp,TrendDown); for(i=BarCount-1;i>1;i--) { if(Buy[i] == 1) { entry = C[i]; sig = "BUY"; sl = TrendSL[i]; tar1 = entry + (entry * .0050); tar2 = entry + (entry * .0092); tar3 = entry + (entry * .0179); bars = i; i = 0; } if(Sell[i] == 1) { sig = "SELL"; entry = C[i]; sl = TrendSL[i]; tar1 = entry - (entry * .0050); tar2 = entry - (entry * .0112); tar3 = entry - (entry * .0212); bars = i; i = 0; } } Offset = 20; Clr = IIf(sig == "BUY", colorLime, colorRed); ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1)); sl = ssl[BarCount-1]; //Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots|styleNoRescale, Null, Null, Offset); //Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset); //Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset); //Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset); //Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset); for (i=bars; i xRp0, ySp0 + retval,IIf(ret > 1.0 AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0 AND xSp0 > xRp0, ySp0 + retval, Null)))); return FibVal; } x0 = Min(xSp0,xRp0)-Back; x1 = (BarCount -1); r236 = fib(0.236); r236I = LastValue (r236,1); r382 = fib(0.382); r382I = LastValue (r382,1); r050 = fib(0.50); r050I = LastValue (r050,1); r618 = fib(0.618); r618I = LastValue (r618,1); r786 = fib(0.786); r786I = LastValue (r786,1); e127 = fib(1.27); e127I = LastValue (e127,1); e162 = fib(1.62); e162I = LastValue (e162,1); e200 = fib(2.00); e200I = LastValue (e200,1); e262 = fib(2.62); e262I = LastValue (e262,1); e424 = fib(4.24); e424I = LastValue (e424,1); p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1); p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1); color00 =IIf(xSp0 > xRp0,colorLime,colorRed); color100 =IIf(xSp0 < xRp0,colorLime,colorRed); numbars = LastValue(Cum(Status("barvisible"))); fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2); if(fibs==1) { Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd); Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd); Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd); } if(text==1) { PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00); PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45); PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44); PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41); PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43); PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42); PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100); PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47); PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47); PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47); PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47); PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25); } _SECTION_BEGIN("swing1"); messageboard = ParamToggle("Message Board","Show|Hide",0); showsl = ParamToggle("Stop Loss Line", "Show|Hide", 1); no=20; res=HHV(H,no); sup=LLV(L,no); avd=IIf(C>Ref(res,-1),1,IIf(C( Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1) ),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))), IIf(C( Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1) ),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))), IIf(C1;i--) { if(Buy[i] == 1) { entry = C[i]; sig = "BUY"; sl = supres[i]; tar1 = entry + (entry * .0050); tar2 = entry + (entry * .0092); tar3 = entry + (entry * .0125); tar4 = entry + (entry * .0192); bars = i; i = 0; } if(Sell[i] == 1) { sig = "SELL"; entry = C[i]; sl = supres[i]; tar1 = entry - (entry * .0050); tar2 = entry - (entry * .0112); tar3 = entry - (entry * .0152); tar4 = entry - (entry * .0212); /*tar1 = entry - 22; tar2 = entry - 38; tar3 = entry - 55;*/ bars = i; i = 0; } } Offset = 3; Clr = IIf(sig == "BUY", colorLime, colorRed); ssl = IIf(bars == BarCount-1, supres[BarCount-1], Ref(supres, -1)); sl = ssl[BarCount-1]; //Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset); //Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset); //Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset); //Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset); //Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset); for (i=bars; i Ref(state,-1); ss=state=85; if(Ovos) { PlotShapes (IIf(Oversold, shapeHollowSmallCircle, shapeNone) ,38, layer = 0, yposition = haLow, offset = -8 ); PlotShapes (IIf(Overbought, shapeHollowSmallCircle, shapeNone) ,colorBrown, layer = 0, yposition = haHigh, offset = 7 ); } _SECTION_END(); _SECTION_BEGIN("TSKPPIVOT"); CHiPr = 0; CLoPr = 9999999; blsLong = 0; PrevCOBar = 0; NumBars = 0; PrePP = 0; PrevLowVal = 9999999; BuySig = 0; blsShort = 0; PrevHiVal = 0; blsNewCO = 0; BarDif = 0; KPA900Val = E_TSKPA900(Close); KPAutoStopVal = E_TSKPAUTOSTOP(High,Low,Close); // -- Create 0-initialized arrays the size of barcount aHPivs = haHigh - haHigh; aLPivs = haLow - haLow; aHiVal = haHigh - haHigh; aLoVal = haLow - haLow; Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume); sctotal = 0; sctotal = sctotal + IIf(tskp_colortmplcnd0 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd1 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd2 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd3 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd4 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd5 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd6 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd7 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd8 > 0, 1, -1); for (curBar=0; curBar < BarCount-1; curBar++) { if ( curBar == 0 ) { CHiPr = haHigh[curBar]; CHiBar = curBar; CLoPr = haLow[curBar]; CLoBar = curBar; blsLong = 0; blsShort = 0; blsNewCO = 0; PrePP = 0; PrevCOBar = 0; PrevHiVal = haHigh[curBar]; PrevLowVal = haLow[curBar]; BuySig = 0; SellSig = 0; blsLL = 0; } if (haHigh[CurBar] >= CHiPr) { CHiPr = haHigh[CurBar]; ChiBar = CurBar; } if (haLow[CurBar] <= CLoPr) { CLoPr = haLow[CurBar]; CLoBar = CurBar; } if ( (KPA900Val[curBar] >= KPAutoStopVal[curbar]) AND (PrePP != -1) AND (blsLong != 1) ){ BarDif = CurBar - PrevCOBar; if (BarDif >= NumBars) { blsLong = 1; blsShort = 0; blsNewCO = 1; PrevCOBar = CurBar; } } if ( (KPA900Val[curBar] <= KPAutoStopVal[curbar]) AND (PrePP != 1) AND (blsShort != 1) ){ BarDif = CurBar - PrevCOBar; if (BarDif >= NumBars) { blsLong = 0; blsShort = 1; blsNewCO = 1; PrevCOBar = CurBar; } } if ( (blsNewCO == 1) AND (sctotal[CurBar] >= 5) AND (blsLong == 1) ) { LVal = CurBar - CLoBar; for (j= CLoBar-1; j <= CLoBar+1; j++) { if (j >=0) { aLPivs[j] = 1; aLoVal[j] = CLoPr; } } PrePP = -1; blsNewCO = 0; CHiPr = haHigh[CurBar]; CHiBar = CurBar; CLoPr = haLow[Curbar]; CLoBar = CurBar; } else if ((blsNewCO == 1) AND (sctotal[CurBar] <= -5) AND (blsShort == 1) ) { HVal = CurBar - CHiBar; for (j= CHiBar-1; j <= CHiBar+1; j++) { if (j >=0) { aHPivs[j] = 1; aHiVal[j] = CHiPr; } } PrePP = 1; blsNewCO = 0; CHiPr = haHigh[CurBar]; CHiBar = CurBar; CLoPr = haLow[Curbar]; CLoBar = CurBar; } } //southwind PlotShapes(IIf(aHPivs == 1, shapeHollowSmallSquare,shapeNone), 25,0, aHiVal+0.05,Offset = 6); PlotShapes(IIf(aLPivs == 1, shapeHollowSmallSquare,shapeNone), colorCustom11,0, aLoVal-0.05, Offset = -6); _SECTION_END(); _SECTION_BEGIN("TSKPMoMo"); blsLong = 0; KPStopLine = E_TSKPSTOPLINE(High,Low,Close); // tskp_upsell, tskp_triggerline, tskp_triggerlinevma sw = E_TSKPUPSELL(Open,High,Low,Close,Volume); KPTriggerLine = tskp_triggerline; KPFast3Val = IIf((E_TSKPFAST3(Open,High,Low,Close,Volume)> 0),1, -1); //tskp_fast2val1, tskp_fast2val2 dummy = E_TSKPFAST2(Open,High,Low,Close,Volume); KPFast2Val = IIf ((tskp_fast2val1 > 0),1,-1); Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume); sctotal = 0; sctotal = sctotal + IIf(tskp_colortmplcnd0 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd1 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd2 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd3 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd4 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd5 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd6 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd7 > 0, 1, -1); sctotal = sctotal + IIf(tskp_colortmplcnd8 > 0, 1, -1); // tskp_mediumma,tskp_mediumup,tskp_mediumdown dummy = E_TSKPMEDIUM(Close); KPMediumUP = tskp_mediumup; KPMediumDwn = tskp_mediumdown; KPMediumMA = tskp_mediumma; // -- Create 0-initialized arrays the size of barcount aHPivs = H - H; aLPivs = L - L; aHiVal = H - H; aLoVal = L - L; for (curBar=5; curBar < BarCount-1; curBar++) { if( (blsLong == -1) OR (blsLong == 0)) { if ((sctotal[CurBar] >= 5) AND (KPMediumUP[CurBar] > KPMediumMA[CurBar] ) AND (KPFast3Val[CurBar] == 1) AND (KPFast2Val[CurBar] == 1) AND (KPTriggerLine[CurBar] >= KPStopLine[CurBar] )) { blsLong = 1; aLPivs[CurBar] = 1; aLoVal[CurBar] = Low[CurBar]; } } if( (blsLong == 1) OR (blsLong == 0)) { if ((sctotal[CurBar] <= -5) AND (KPMediumDwn[CurBar] < KPMediumMA[CurBar] ) AND (KPFast3Val[CurBar] == -1) AND (KPFast2Val[CurBar] == -1) AND (KPTriggerLine[CurBar] <= KPStopLine[CurBar] )) { blsLong = -1; aHPivs[Curbar] = 1; aHiVal[Curbar] = High[Curbar]; } } if ((blsLong == 1) AND ((sctotal[CurBar] < 5) OR (KPMediumUP[CurBar] < KPMediumMA[CurBar] ) OR (KPFast2Val[CurBar] < 1) OR (KPFast3Val[CurBar] < 1) OR (KPTriggerLine[CurBar] < KPStopLine[CurBar] )) ) { blsLong= 0; } if ((blsLong == -1) AND ((sctotal[CurBar] > -5) OR (KPMediumDwn[CurBar] > KPMediumMA[CurBar] ) OR (KPFast2Val[CurBar] > -1) OR (KPFast3Val[CurBar] > -1) OR (KPTriggerLine[CurBar] > KPStopLine[CurBar] )) ) { blsLong = 0; } } PlotShapes (IIf(aHPivs == 1, shapeSmallCircle, shapeNone) ,colorOrange, layer = 0, yposition = haHigh, offset = 7 ); PlotShapes (IIf(aLPivs == 1, shapeSmallCircle, shapeNone) ,10, layer = 0, yposition = haLow, offset = -8 ); _SECTION_END(); if (BBand == 1) { _SECTION_BEGIN("Bollinger Bands"); P = ParamField("Price field",3); Periods = Param("Periods", 15, 2, 300, 1 ); Width = Param("Width", 2, 0, 10, 0.05 ); Color = ParamColor("Color", colorGrey40 ); Style = ParamStyle("style"); Plot( BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style ); Plot( BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style ); _SECTION_END(); } _SECTION_BEGIN("HA"); tchoice=Param("Title Selection ",2,1,2,1); Q=Param("% Change",2.1,1,10,1); Z= Ref(Zig(C ,q ),-1) ; HH=Ref(((Z Ref(Z,-2)) AND (Peak(z,q,1 ) >Peak(Z,q,2))),-1); LH=Ref(((Z Ref(Z,-2)) AND (Peak(Z,q,1 ) Ref(Z,-1) AND Ref(Z,-1) < Ref(Z,-2)) AND (Trough(Z,q,1 ) >Trough(Z,q,2))),-1); LL=Ref(((Z>Ref(Z,-1) AND Ref(Z,-1) < Ref(Z,-2)) AND (Trough(Z,q,1 ) HaOpen,colorGreen,colorBrown),styleCandle); //Sell = (abs(HaOpen -HaClose )<= ((HaHigh -HaLow )*0.1)); //Buy = (abs(HaOpen -HaClose )<= ((HaHigh -HaLow )*0.1)) ; Buy = ExRem( Buy, Sell ); Sell = ExRem( Sell, Buy ); //PlotShapes( IIf( Sell, shapeDownArrow+ shapePositionAbove, shapeNone), colorCustom12 ); //Plot(EMA(HaClose,20), "", colorBlue , styleLine|styleThick ); //Plot(Wilders(H,260.6), "",colorCustom12 , styleDashed|styleThick ); //Plot(EMA(HaClose,10), "",colorTan, styleLine|styleThick ); TimeFrameSet(inHourly); Hh=HHV (L,24); Ll =LLV (H,24); TimeFrameRestore(); Hh1=(TimeFrameExpand( Hh, inHourly)); Ll1=(TimeFrameExpand( Ll, inHourly)); Plot(Hh1 , "27dayssellbelclose",colorRed, 4+8+2048); Plot(Ll1 , "27daysbuyabvclose",colorGreen, 4+8+2048); Buy=Cross(C,LL); Sell=Cross(HH,C); Filter=Buy OR Sell; _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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); } Pivot = ParamToggle("Pivot", "weekly|monthly", 1); if(Pivot) { H1 = TimeFrameGetPrice("H", inMonthly, -1); // yesterdays high L1 = TimeFrameGetPrice("L", inMonthly, -1); // low C1= TimeFrameGetPrice("C", inMonthly, -1); // close } else { H1 = TimeFrameGetPrice("H", inWeekly, -1); // yesterdays high L1 = TimeFrameGetPrice("L", inWeekly, -1); // low C1= TimeFrameGetPrice("C", inWeekly, -1); // close } _SECTION_BEGIN("BACK COLOR"); SetChartBkGradientFill( ParamColor("BgTop", colorPlum), ParamColor("BgBottom", colorBlack),ParamColor("titleblock",colorPlum)); Title = (EncodeColor(colorGold)+Day() + EncodeColor(colorWhite) + Name()+" " + Date() +" "+Interval(2) +" "+ EncodeColor(colorWhite)+",Open "+Open +" , High "+H+" , Low "+L+" , Close "+C+" "+"{{VALUES}}"); BuyPrice = Open; SellPrice = Open; Derived=WMA(WMA(WMA(((H+L)/2)+(O-C),92),1),1); i=WMA(Derived,3); Upper=(Derived+StDev(Derived,7))+ATR(2)/1.5; Lower=(Derived-StDev(Derived,7))-ATR(2)/1; color=IIf(BarsSince(Cross(Lower,Low))> BarsSince(Cross(C,Upper)), colorBrightGreen,colorRed); Plot(C,"",color,64); //WriteIf(s,"EXIT all Short positions\nif trading long positions, enter long Now-\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(L+.75*ATR(5),1.4)+" ,",""); //WriteIf(ss,"exit all long positions today with a Market On Close (MOC) order\nOR at the market price on tomorrow's Open with stop="+EncodeColor(4)+WriteVal(Ref(H+.75*ATR(5), -1),1.4)+",",""); //WriteIf( sss ,"No trading signals today.","") ; SetBarsRequired( 600, 0 ); GraphXSpace = 8; SetChartOptions( 0, chartShowArrows | chartShowDates ); //============== TITLE ============== _SECTION_BEGIN("Magnified Market Price"); FS=Param("Font Size",30,11,100,1); GfxSelectFont("Times New Roman", FS, 700, True ); GfxSetBkMode( colorWhite ); GfxSetTextColor( ParamColor("Color",colorGold) ); Hor=Param("Horizontal Position",970,1,1200,1); Ver=Param("Vertical Position",50,1,830,1); GfxTextOut(""+C, Hor , Ver ); YC=TimeFrameGetPrice("C",inDaily,-1); DD=Prec(C-YC,2); xx=Prec((DD/YC)*100,2); GfxSelectFont("Times New Roman", 11, 700, True ); GfxSetBkMode( colorWhite ); GfxSetTextColor(ParamColor("Color",colorBlack) ); GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 ); _SECTION_END(); _SECTION_BEGIN("Price Line"); dp= Param("dps",3,0,1000,1); PriceLineColor=ParamColor("PriceLineColor",colorOrange); PriceLevel = ParamField("PriceField", field = 3 ); PriceLeve2 = ParamField("PriceField", field = dp ); Daysback = Param("Bars Back",1,10,500,1); FirstBar = BarCount - DaysBack; YY = IIf(BarIndex() >= Firstbar,EndValue(PriceLevel),Null); Plot(YY,"Current Price",PriceLineColor,ParamStyle("LineStyle",styleLine|styleDashed|styleNoTitle|styleNoLabel|styleThick,maskAll)); side = Param("side",1,0,1000,1); dist = 0; for( i = 0; i < BarCount; i++ ) { if(i+side== BarCount) PlotText( "\n " + PriceLevel[ i ], i, YY[ i ]-dist[i], colorGold ); } _SECTION_END(); /****************/ /* */ /* ALERT OUTPUT */ /* */ /****************/ TxtX = Param("Text Left", 600, 0, 1000, 10); TxtY = Param("Text Top", 60, 1, 650, 10); GfxSelectFont("Tahoma", 14, 700 ); GfxSetBkMode(1); if(LastValue(Buy) OR SelectedValue(Buy)) { GfxSetTextColor(colorGold); Say(""); } else if(LastValue(Sell) OR SelectedValue(Sell)) { GfxSetTextColor(colorGold); Say(""); } else { GfxSetTextColor(colorGold); GfxTextOut("", TxtX, TxtY); } _SECTION_BEGIN("sys"); x=Param("xposn",315,0,1000,1); y=Param("yposn",576,0,1000,1); _SECTION_END(); _SECTION_BEGIN("Background text"); C11=ParamColor("up panel",colorBlack ); C12=ParamColor("dn panel",colorBlack ); C13=Param("fonts",20,10,30,1 ); C14=Param("left-right",2.1,1.0,5.0,0.1 ); C15=Param("up-down",8,1,30,1 ); Miny = Status("axisminy"); Maxy = Status("axismaxy"); lvb = Status("lastvisiblebar"); fvb = Status("firstvisiblebar"); pxwidth = Status("pxwidth"); pxheight = Status("pxheight"); GfxSetBkMode( 0 ); GfxSelectFont("Tahoma", 12, 500, False, False, 0); GfxSetTextColor(colorCustom12); GfxSetTextAlign( 6 ); GfxSelectFont("Tahoma", 15, 600, False, False, 0); GfxSetTextColor(colorWhite); GfxSetTextAlign( 6 ); GfxSelectFont("Tahoma", 12, 400, False, False, 0); GfxSetTextColor(colorBrightGreen); GfxSelectFont("Tahoma", 12, 400, False, False, 0); GfxSetTextColor(colorRed); pricechange=(C-Ref(C,-1))*100/Ref(C,-1); changeponit=C-Ref(C,-1); Vlp=Param("Volume lookback period",15,10,300,10); Vrg=MA(V,Vlp); St = StDev(Vrg,Vlp); Vp3 = Vrg + 3*st; Vp2 = Vrg + 2*st;; Vp1 = Vrg + 1*st;; Vn1 = Vrg -1*st; Vn2 = Vrg -2*st; x=Param("xposn",1,0,1000,1); y=Param("yposn",1,0,1000,1); GfxGradientRect( 1, 1, 1400, 40, colorViolet, colorBlack); GfxSetBkMode(0); GfxSelectFont( "Georgia", 18, 800, False ); GfxSetTextColor( colorGold ); GfxTextOut( "Simple ", x+600, y+10 ); GfxSelectFont( "Tahoma", 16, 800, False ); GfxSetTextColor( colorGold ); GfxTextOut( Name(), x+100, y+10 ); GfxSelectFont( "Century Gothic", 15, 100, False ); GfxSetTextColor( colorGold ); GfxTextOut( Date(), x+1000, y+10 ); GfxSelectFont( "Comic Sans MS", 15, 500, False ); GfxSetTextColor( colorYellow ); GfxTextOut( Interval(2), x+275, y+10 ); //------------------------------------------------------------ H, L, O, C---------------------- GfxGradientRect( 1, 40, 1400, 55, colorViolet, colorBlack ); GfxSetBkMode(0); GfxSelectFont( "Areal", 9, 200, False ); GfxSetTextColor( colorWhite ); GfxTextOut( "High:"+WriteVal(H,1.2), x+100, y+40 ); GfxSelectFont( "Areal", 9, 200, False ); GfxSetTextColor( colorWhite ); GfxTextOut( "Low:"+WriteVal(L,1.2), x+200, y+40 ); GfxSelectFont( "Areal", 9, 200, False ); GfxSetTextColor( colorWhite ); GfxTextOut( "Open:"+WriteVal(O,1.2), x+300, y+40 ); GfxSelectFont( "Areal", 9, 200, False ); GfxSetTextColor( colorWhite ); GfxTextOut( "Close:"+WriteVal(C,1.2), x+400, y+40 ); GfxSelectFont( "comic sans ms", 12, 100, False ); //-----------------------------------------------------------Valume------------------------------- // set criteria to scan for big stock only; BigStock = MA( V, 10 ) * MA( C, 10 ) > 100; //---------------Color------------------------ per1 = 6; per2 = 2; Om = MA( O, per1 ); hm = MA( H, per1 ); lm = MA( L, per1 ); Cm = MA( C, per1 ); // 1. Heiken Ashi HACLOSE = ( Om + Hm + Lm + Cm ) / 4; HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); HaHigh = Max( Hm, Max( HaClose, HaOpen ) ); HaLow = Min( Lm, Min( HaClose, HaOpen ) ); Of = MA( Haopen, per2 ); Cf = MA( Haclose, per2 ); Lf = IIf( haOpen < haClose, MA( Halow, per2 ), MA( Hahigh, per2 ) ); Hf = IIf( haOpen < haClose, MA( Hahigh, per2 ), MA( Halow, per2 ) ); //Color = IIf( Cf > Of, colorGreen, colorRed ); //---------------------------------------------------- TrailStop = HHV( C - 2 * ATR( 10 ), 15 ); ProfitTaker = EMA( H, 13 ) + 2 * ATR( 10 ); /* ********************************** Code to automatically identify pivots ********************************** */ // -- what will be our lookback range for the hh and ll? farback = 140; //How Far back to go nBars = 12; //Number of bars // -- Create 0-initialized arrays the size of barcount aHPivs = H - H; aLPivs = L - L; // -- More for future use, not necessary for basic plotting aHPivHighs = H - H; aLPivLows = L - L; aHPivIdxs = H - H; aLPivIdxs = L - L; nHPivs = 0; nLPivs = 0; lastHPIdx = 0; lastLPIdx = 0; lastHPH = 0; lastLPL = 0; curPivBarIdx = 0; // -- looking back from the current bar, how many bars // back were the hhv and llv values of the previous // n bars, etc.? aHHVBars = HHVBars( O, nBars ); aLLVBars = LLVBars( O, nBars ); aHHV = HHV( O, nBars ); aLLV = LLV( O, nBars ); // -- Would like to set this up so pivots are calculated back from // last visible bar to make it easy to "go back" and see the pivots // this code would find. However, the first instance of // _Trace output will show a value of 0 aVisBars = Status( "barvisible" ); nLastVisBar = LastValue( Highest( IIf( aVisBars, BarIndex(), 0 ) ) ); _TRACE( "Last visible bar: " + nLastVisBar ); // -- Initialize value of curTrend curBar = ( BarCount - 1 ); curTrend = ""; if ( aLLVBars[curBar] < aHHVBars[curBar] ) { curTrend = "D"; } else { curTrend = "U"; } // -- Loop through bars. Search for // entirely array-based approach // in future version for ( i = 0; i < BarCount; i++ ) { curBar = ( BarCount - 1 ) - i; // -- Have we identified a pivot? If trend is down... if ( aLLVBars[curBar] < aHHVBars[curBar] ) { // ... and had been up, this is a trend change if ( curTrend == "U" ) { curTrend = "D"; // -- Capture pivot information curPivBarIdx = curBar - aLLVBars[curBar]; aLPivs[curPivBarIdx] = 1; aLPivLows[nLPivs] = L[curPivBarIdx]; aLPivIdxs[nLPivs] = curPivBarIdx; nLPivs++; } // -- or current trend is up } else { if ( curTrend == "D" ) { curTrend = "U"; curPivBarIdx = curBar - aHHVBars[curBar]; aHPivs[curPivBarIdx] = 1; aHPivHighs[nHPivs] = H[curPivBarIdx]; aHPivIdxs[nHPivs] = curPivBarIdx; nHPivs++; } // -- If curTrend is up...else... } // -- loop through bars } // -- Basic attempt to add a pivot this logic may have missed // -- OK, now I want to look at last two pivots. If the most // recent low pivot is after the last high, I could // still have a high pivot that I didn't catch // -- Start at last bar curBar = ( BarCount - 1 ); candIdx = 0; candPrc = 0; lastLPIdx = aLPivIdxs[0]; lastLPL = aLPivLows[0]; lastHPIdx = aHPivIdxs[0]; lastHPH = aHPivHighs[0]; if ( lastLPIdx > lastHPIdx ) { // -- Bar and price info for candidate pivot candIdx = curBar - aHHVBars[curBar]; candPrc = aHHV[curBar]; if ( lastHPH < candPrc AND candIdx > lastLPIdx AND candIdx < curBar ) { // -- OK, we'll add this as a pivot... aHPivs[candIdx] = 1; // ...and then rearrange elements in the // pivot information arrays for ( j = 0; j < nHPivs; j++ ) { aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs- ( j+1 )]; aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-( j+1 )]; } aHPivHighs[0] = candPrc ; aHPivIdxs[0] = candIdx; nHPivs++; } } else { // -- Bar and price info for candidate pivot candIdx = curBar - aLLVBars[curBar]; candPrc = aLLV[curBar]; if ( lastLPL > candPrc AND candIdx > lastHPIdx AND candIdx < curBar ) { // -- OK, we'll add this as a pivot... aLPivs[candIdx] = 1; // ...and then rearrange elements in the // pivot information arrays for ( j = 0; j < nLPivs; j++ ) { aLPivLows[nLPivs-j] = aLPivLows[nLPivs-( j+1 )]; aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-( j+1 )]; } aLPivLows[0] = candPrc; aLPivIdxs[0] = candIdx; nLPivs++; } } //============== EXPLORATION ============== Buy = Cover = BigStock AND aLPivs == 1; Sell = Short = BigStock AND aHPivs == 1; SellPrice = ValueWhen( Sell, C, 1 ); BuyPrice = ValueWhen( Buy, C, 1 ); Long = Flip( Buy, Sell ); Shrt = Flip( Sell, Buy ); //============== Plot price ============== n = 15; a = C > ( MA( H, n ) + MA( L, n ) ) / 2;// then Buy next bar at market; b = C < ( MA( H, n ) + MA( L, n ) ) / 2;// then Sell Short next bar at market; state = IIf( BarsSince( a ) < BarsSince( b ), 1, 0 ); Longs = state == 1; shorts = state == 0; _SECTION_BEGIN("swing2"); no=22; res=HHV(H,no); sup=LLV(L,no); avd=IIf(C>Ref(res,-1),1,IIf(C= 084500 & TimeNum() <= 085959; isdRth = TimeNum() >= 084500 & TimeNum() <= 160000; aRthL = IIf(isRth, L, 1000000); aRthH = IIf(isdRth, H, Null); aRthLd = IIf(isdRth, L, 1000000); DayH = TimeFrameCompress( aRthH, inDaily, compressHigh ); DayH = TimeFrameExpand( DayH, inDaily, expandFirst ); DayL = TimeFrameCompress( aRthLd, inDaily, compressLow ); DayL = TimeFrameExpand( DayL, inDaily, expandFirst ); Bars = BarsSince(TimeNum() >= 94500 AND TimeNum() < 095959);//,BarIndex(),1); // AND DateNum()==LastValue(DateNum()); x0 = BarCount-LastValue(Bars); x1 = BarCount-1; DayHline=LineArray(x0,LastValue(DayH),x1,LastValue (DayH),0); DayLline=LineArray(x0,LastValue(DayL),x1,LastValue (DayL),0); DayHlineI = LastValue (DayHline,1); DayLlineI = LastValue (DayLline,1); Plot(DayHline,"DayH",colorYellow,styleBar|styleNoRescale|styleNoTitle); Plot(DayLline,"DayL",colorYellow,styleBar|styleNoRescale|styleNoTitle); PlotText(" Day Hi " , LastValue(BarIndex())-(numbars/Hts), DayHlineI +0.05, colorYellow); PlotText(" Day Lo " , LastValue(BarIndex())-(numbars/Hts), DayLlineI +0.05, colorYellow); } ////////////add hi comp SL = ( HHV( H, 26 ) + LLV( L, 26) )/2; TL = ( HHV( H, 9 ) + LLV( L, 9 ) )/2; DL = Ref( C, 26 ); Span1 = (( SL + TL )/2); Span2 = (HHV( H, 52) + LLV(L, 52))/2; Sp1=Ref((SL+TL)/2,-25); Sp2=Ref((HHV(H,52)+LLV(L,52))/2,-25); Plot(DL,"",colorLightBlue,styleThick); // delayed, lagging, or chikou span if(ICHIMOKU==1){ Plot (SL,"Standard",colorGreen); Plot (TL,"Turning",colorRed); PlotOHLC (Sp1,Sp1,Sp2,Sp2,"Cloud",IIf (Sp1>Sp2,colorSeaGreen,colorDarkRed),styleCloud); } //==========================================================