// Downloaded From https://www.WiseStockTrader.com _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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); _SECTION_END(); // Parameters PeriodEMA = 13; MACDIndicatorRange = 50; // Volume filter VolumeFilter = Param( "Volume MA filter", 100000, 50000, 500000, 100000 ); Timeframe = Interval(2); // Adjust for weekly if necessary if( Timeframe == "5-day" || Timeframe == "Weekly" ) { VolumeFilter = VolumeFilter * 5; } else if( Timeframe == "Monthly") { VolumeFilter = VolumeFilter * 20; } else if( Timeframe != "Daily" ) { VolumeFilter = 0; } // Minimum number of bars required to form a divergence pattern. For a // positive divergence, this is the number of falling bars in the context // of a rising MACD or MACD-H pattern. Vice versa for negative divergence MACDDivMinWidth = Param("Divergence min width", 4, 1, 10, 1 ); // Minimum width of negative projecting wave between two positive MACD-H waves, // otherwise two positive waves will be considered as one single wave. This // minimises invalid divergences, to ensure that "back of bears is broken". // The same applies for a positive wave between two negative waves. HistMinWidth = Param("Histogram min width", 4, 1, 10, 1 ); PeriodEMA = Optimize( "PeriodEMA ", 13, 5, 23, 1 ); // Other parameters OpenPositions = 10; ATRPeriod = 5; InitialCapital = 100000; PeriodFast = Param( "Fast EMA", 12, 2, 200, 1 ); PeriodSlow = Param( "Slow EMA", 26, 2, 200, 1 ); PeriodSignal = Param( "Signal EMA", 9, 2, 200, 1 ); MACDInd = MACD(PeriodFast, PeriodSlow ); SigInd = Signal(PeriodFast, PeriodSlow , PeriodSignal ); HistInd = MACDInd - SigInd ; _N( macdStr = WriteVal( PeriodFast, 1.0 )+","+WriteVal( PeriodSlow , 1.0 ) ); _N( sigStr = macdStr + ","+WriteVal( PeriodSignal , 1.0 ) ); // Get displayed min and max value of MACD and MACD-H, to rescale it for better visibility scMACDMax = LastValue(HHV(Max(MACDInd, sigInd), BarsSince( Status("barvisible") AND NOT Ref(Status("barvisible"),-1) ))); scMACDMin = LastValue(LLV(Min(MACDInd, sigInd), BarsSince( Status("barvisible") AND NOT Ref(Status("barvisible"),-1) ))); scaleMACD = Max( abs(scMACDMax), abs(scMACDMin) ); scHistMax = LastValue(HHV(HistInd, BarsSince( Status("barvisible") AND NOT Ref(Status("barvisible"),-1) ))); scHistMin = LastValue(LLV(HistInd, BarsSince( Status("barvisible") AND NOT Ref(Status("barvisible"),-1) ))); scaleHist = Max( abs(scHistMax), abs(scHistMin) ); _SECTION_BEGIN("Patterns Wave"); Change = Param("Wave Period",7,0,100,1); SupResA = Param("Sup-Res A Period",20,0,100,1); SupResB = Param("Sup-Res B Period",25,0,100,1); Res1 = ParamColor("Resistance High", colorYellow | styleThick); Res2 = ParamColor("Resistance Low", colorYellow | styleThick); Sup1 = ParamColor("Support High", colorBlue| styleThick); Sup2 = ParamColor("Support Low", colorBlue| styleThick); procedure PlotShapeAt( x, y, shape, shift ) { PlotShapes( IIf( BarIndex() == x, shape, 0 ), colorWhite, 0, y, shift ); } bi = BarIndex(); sbi = SelectedValue( bi ); GraphXSpace = 2; Plot( Zig( C, Change ), "", colorYellow, styleDots | styleLine | styleThick ); upshift = 80; if( SelectedValue( PeakBars( C, Change ) < TroughBars( C, Change ) ) ) { pt1 = PeakBars( C, Change, 1 ) == 0 ; pt2 = TroughBars( C, Change, 1 ) == 0 ; } else { pt1 = TroughBars( C, Change, 1 ) == 0 ; pt2 = PeakBars( C, Change, 1 ) == 0 ; upshift = -upshift; } bpt1 = SelectedValue( ValueWhen( pt1, bi ) ); bpt2 = SelectedValue( ValueWhen( pt2, bi ) ); bpt3 = SelectedValue( ValueWhen( pt1, bi, 2 ) ); bpt4 = SelectedValue( ValueWhen( pt2, bi, 2 ) ); bpt5 = SelectedValue( ValueWhen( pt1, bi, 3 ) ); bpt6 = SelectedValue( ValueWhen( pt2, bi, 3 ) ); PlotShapeAt( bpt1, C, shapeDigit5, upshift ); PlotShapeAt( bpt2, C, shapeDigit4, -upshift ); PlotShapeAt( bpt3, C, shapeDigit3, upshift ); PlotShapeAt( bpt4, C, shapeDigit2, -upshift ); PlotShapeAt( bpt5, C, shapeDigit1, upshift ); _SECTION_END(); _SECTION_BEGIN("trend candle"); //////////////////////////////////// // Heikin_Ashi For Amibroker //////////////////////////////////// HaClose =EMA((O+H+L+C)/4,3); HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); HaHigh = Max( H, Max( HaClose, HaOpen ) ); HaLow = Min( L, Min( HaClose, HaOpen ) ); PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "Modified " + Name(), colorRed, styleCandle | styleNoLabel ); SetChartBkGradientFill( ParamColor("BgTop", colorBrightGreen),ParamColor("BgBottom", colorSeaGreen)); Title=""; _SECTION_END(); _SECTION_BEGIN("Unnamed 3"); pWMA1 = Param("WMA 1 period", 6, 1, 20, 1); pWMA2 = Param("WMA 2 period", 7, 1, 20, 1); fMA1 = WMA(HaClose , pWMA1); // calculate MA 1 fMA2 = WMA( (HaOpen + HaClose )/2, pWMA2); // original Plot(fMA1, "\nMA1(" + NumToStr(pWMA1, 1.0) + ")", colorWhite| styleThick); // plot the MA lines Plot(fMA2, "\nMA2(" + NumToStr(pWMA2, 1.0) + ")", colorBlack|styleThick); // plot the MA lines Plot( 2, "", IIf( fMA1>fMA2, colorBlue, colorRed),styleOwnScale|styleArea|styleNoLabel, -0.5, 100 ); _SECTION_END(); _SECTION_BEGIN("Support-Resistance"); //Plot( Close, "Close", colorWhite, styleCandle ); MaxGraph = 12; BuyOffSet = SupResA; //Optimize("BuyOffSet",18,15,20,1); SellOffset = BuyOffSet; //Optimize("SellOffset",2,2,14,2); RegLength = 5; //Optimize("RegLength",5, 2,11,2); BuyATRPeriod = 2; //Optimize("BuyATRPeriod",2,2,5,1); SellATRPeriod = BuyATRPeriod; //Optimize("SellATRPeriod",4,2,11,2); ATRMultiplier = 0.5; //Optimize("ATRMultiplier",1,0.7,1.25,.05); Graph8 = HHV(H-ATRMultiplier*ATR(BuyATRPeriod),BuyOffset); /* RED */ Graph9 = LLV(L+ATRMultiplier*ATR(SellATRPeriod),SellOffset) ; /* GREEN */ ave=(Graph8+Graph9)/2; Graph8Style=Graph9Style = styleNoTitle|styleLine|styleThick; Graph9Color= Sup1; /* 5 is green */ Graph8Color = Res2; /* 4 is red */ nn=SupResB; mmm=100; TYP=(High + Low + 2*Close)/4; CI=(TYP-MA(TYP,14))/(0.015*StDev(TYP,14)); CCCI=EMA(CI,5)+mmm; Hh=HHV(H,nn); Ll=LLV(L,nn); MM=(Hh+Ll)/2; CCCC=EMA(CCCI*(Hh-Ll)/(2*mmm)+Ll,5); Plot(Hh,"High Reistance",Res1,styleLine|styleNoTitle|styleThick) ; Plot(Ll,"Low Suport",Sup2,styleLine|styleNoTitle|styleThick); _SECTION_END(); _SECTION_BEGIN("MABIUTS"); SetChartOptions(0,chartShowArrows|chartShowDates); _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) )); Buy=EMA(C,13)>EMA(EMA(C,13),9) AND Cross (C,Peak(C,5,1)); Sell=Cross (EMA(EMA(C,13),9),EMA(C,13)); MYcolor = IIf( EMA(C,13)>EMA(EMA(C,13),9) AND C>Peak(C,2,1), colorGreen, IIf(EMA(C,13)>EMA(EMA(C,13),9) AND C Ref( Close, -1 ); Cond2 = High < Ref( High, -1 ) AND Low > Ref( Low, -1 ); Cond3 = Close < Ref( Close, -1 ); SetTradeDelays( 1, 1, 1, 1 ); Buy = Cond1 AND Ref( Cond2, -1 ) AND Ref( Cond1, -2 ); BuyPrice = Open; Short = Cond3 AND Ref( Cond2, -1 ) AND Ref( Cond3, -2 ); ShortPrice = Open; Sell = Cover = False; // exits only by stops // profit target being higher than loss gives better result // than proposed in article equal to 0.75% Target = 6.5; Loss = 0.75; // 0.75% max loss stop; SetOption("InitialEquity", 30000 ); ApplyStop( stopTypeLoss, stopModePercent, Loss, True ); ApplyStop( stopTypeProfit, stopModePercent, Target, True ); SetOption("ActivateStopsImmediately", False ); // activate stops next bar SetPositionSize( 1, spsShares ); PointValue = 1000; // big point value NYMEX CL MarginDeposit = 5063; // overnight margin NYMEX CL _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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); _SECTION_END(); SetChartBkColor(ParamColor("Outer panel color ",colorLightYellow)); SetChartBkColor(ParamColor("BackGround Color", colorWhite)); _SECTION_BEGIN("EmaCrossoverSystem"); ShortPeriod = Param("ShortPeriod", 5, 2, 200, 1); LongPeriod = Param("LongPeriod", 13, 2, 200, 1); Cover=Cross(EMA(C,ShortPeriod),EMA(C,LongPeriod)); Short=Cross(EMA(C,LongPeriod),EMA(C,ShortPeriod)); shape = Cover * shapeUpArrow + Short * shapeDownArrow; PlotShapes( shape, IIf( Cover, colorBlue, colorBlue ),0, IIf( Cover, Low, High ) ); _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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); _SECTION_END(); _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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); _SECTION_END(); Param_Margin = Param("Margin required (used for backtesting only)", 15,0.001,100,0.001); Param_LotSize = Param("Lot Size (used for backtesting only)", 50,5,5000,5); Param_NoOfLots = Param("No of lots normally traded (used for backtesting only)",1,1,10000,1); C13=Param("fonts",20,10,30,1 ); C14=Param("left-right",2.1,1.0,5.0,0.1 ); wc = TimeFrameCompress( Close, in15Minute ); /* now the time frame is still unchanged (say daily) and our MA will operate on daily data */ dailyma = EMA( C, 39 ); /* but if we call MA on compressed array, it will give MA from other time frame */ weeklyma = EMA( wc, 39 ); // note that argument is time-compressed array weeklyma = TimeFrameExpand( weeklyma, in15Minute ); // expand for display Plot( weeklyma, "WeeklyMA", colorBlue ); wc = TimeFrameCompress( Close, in15Minute ); /* now the time frame is still unchanged (say daily) and our MA will operate on daily data */ dailyma = EMA( C, 104 ); /* but if we call MA on compressed array, it will give MA from other time frame */ weeklyma = EMA( wc, 104 ); // note that argument is time-compressed array weeklyma = TimeFrameExpand( weeklyma, in15Minute ); // expand for display Plot( weeklyma, "WeeklyMA", colorBrightGreen ); wc = TimeFrameCompress( Close, in15Minute ); /* now the time frame is still unchanged (say daily) and our MA will operate on daily data */ dailyma = MA( C, 104 ); /* but if we call MA on compressed array, it will give MA from other time frame */ weeklyma = MA( wc, 104 ); // note that argument is time-compressed array weeklyma = TimeFrameExpand( weeklyma, in15Minute ); // expand for display Plot( weeklyma, "WeeklyMA", colorLightGrey ); _SECTION_END(); _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", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); _SECTION_END(); DayH = SelectedValue(TimeFrameGetPrice("H", inDaily));// yesterdays high DayL = SelectedValue(TimeFrameGetPrice("L", inDaily));//low DayH1 = SelectedValue(TimeFrameGetPrice("H", inDaily, -1));// yesterdays high DayL1 = SelectedValue(TimeFrameGetPrice("L", inDaily, -1));//low DayH2 = SelectedValue(TimeFrameGetPrice("H", inDaily, -2));// yesterdays high DayL2 = SelectedValue(TimeFrameGetPrice("L", inDaily, -2));//low Range = ((DayH +DayH1 +DayH2)/3 - (DayL+DayL1+DayL2)/3); sr1= (Range *0.292)+DayL; sr2= Dayh-(Range *0.33); sr3= (Range *0.702)+DayL; sr4= DayH-(Range *0.655); style = styleLine | styleNoRescale|styleLine; Plot(sr1, "SR1",colorWhite ,styleDashed|styleNoRescale|styleThick); Plot(sr2, "SR2",colorGold ,styleDashed|styleNoRescale|styleThick); Plot(sr3, "SR3",colorPink , styleDashed|styleNoRescale|styleThick); Plot(sr4, "SR4",colorOrange ,styleDashed|styleNoRescale|styleThick); Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1)); TT= RSIa(C,60); StartBar = ValueWhen(TimeNum() == 090000, BarIndex()); TodayVolume = Sum(TT,Bars_so_far_today); IIf (BarIndex() >= StartBar, VWAP = Sum (C * TT, Bars_so_far_today ) / TodayVolume,0); Plot (VWAP,"VWAP",colorOrange,4 +8+2048 ); _SECTION_BEGIN("Volume"); Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorBrown ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram ), 2 ); _SECTION_END(); SetChartBkGradientFill( ParamColor("BgTop", colorWhite), ParamColor("BgBottom", colorBlack),ParamColor("titleblock", colorGreen)); GraphXSpace = 5; _SECTION_BEGIN("EMA"); P = ParamField("Price field",-1); Periods = Param("Periods", 13); Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); _SECTION_END(); _SECTION_BEGIN("DEMA"); P = ParamField("Price field",-1); Periods = Param("Periods", 65, 2, 3000, 1, 10 ); Plot( DEMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorAqua ), ParamStyle("Style") ); _SECTION_END(); A = DEMA (H,65); B = EMA (H,39); G = DEMA (L,65); I = EMA(L,39); D = Min (G,I); E = Max (A,B); /* Buy or Sell Condition */ Buy =Cover= Cross(Close,E); Sell = Short=Cross(D,Close); Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); SellPrice=ValueWhen(Sell,C,1); BuyPrice=ValueWhen(Buy,C,1); Filter = Buy OR Sell; /* Exploration Parameters */ AddTextColumn( FullName(), "Company Name" ); AddColumn( Buy, "Buy", 1 ); AddColumn( Sell, "Sell", 1 ); AddColumn( C, "Close", 1.3 ); AddColumn( H, "High", 1.3 ); Title = EncodeColor(colorWhite)+ "" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) + " - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+ "Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+ 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(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); _SECTION_END(); //------------------------------------------------------------------------------ GraphXSpace=1; MaxGraph=12; Period=Param("MM_Period", 32, 4, 256, 1) ; Graph1Color=6; Graph2Color=7; Graph3Color=4; Graph4Color=5; Graph5Color=6; Graph6Color=5; Graph7Color=4; Graph8Color=7; Graph9Color=6; Graph10Color=4; Graph11Color=4; Graph0=Close; Graph0Color=1; Graph0Style=64; Graph1Style=1; Graph2Style=1; Graph3Style=1; Graph4Style=1; Graph5Style=1; Graph6Style=1; Graph7Style=1; Graph8Style=1; Graph9Style=1; Graph10Style=1; Graph11Style=4; PER = Period; BarNR = LastValue(Cum(1)) ; TimeFrame = BarNR - PER ; TF = TimeFrame ; Lo = LastValue(ValueWhen(Cross(Cum(1), TF), LLV(Min(H,L),PER),1)) ; Hi = LastValue(ValueWhen(Cross(Cum(1), TF), HHV(Max(H,L),PER),1)) ; Lo = LastValue( LLV(Min(H,L),PER ),1) ; Hi = LastValue( HHV(Max(H,L),PER ),1) ; Fractal = IIf(Hi<=250,100, IIf(Hi<=2500,1000, IIf(Hi<=25000,10000, IIf(Hi<=250000,100000, 0 )))) ; int_Log = int( log(Fractal/(Hi-Lo))/log(2) ) ; Oct = Fractal * ( exp(ln(1/2)* int_Log ) ) ; Min_1 = int( Lo / Oct ) * Oct ; Max_1 = IIf( (Min_1 + Oct) > Hi, Min_1 + Oct, Min_1 + 2*Oct ) ; Min_2 = IIf( (Min_1 + 1/8*(Max_1-Min_1)) <= Lo AND Hi <= (Max_1 - 1/8*(Max_1-Min_1)) , (Min_1 + 1/4*(Max_1-Min_1)) , Min_1 ) ; Max_2 = IIf( (Min_1 + 1/8*(Max_1-Min_1)) <= Lo AND Hi <= (Max_1 - 1/8*(Max_1-Min_1)) , (Max_1 - 1/4*(Max_1-Min_1)) , Max_1 ) ; /******************************/ Diff = Max_2 - Min_2 ; H1 = IIf( (Min_2 + 3/16*Diff) <= Lo AND Hi <= (9/16*Diff + Min_2) , Min_2 + 1/2*Diff, 0) ; H2 = IIf( (Min_2 - 1/8*Diff) <= Lo AND Hi <= (5/8*Diff + Min_2) AND H1==0, Min_2 + 1/2*Diff, 0) ; H3 = IIf( (Min_2 + 7/16*Diff) <= Lo AND Hi <= (Min_2 + 13/16*Diff), Min_2 + 3/4*Diff, 0 ) ; H4 = IIf( (Min_2 + 3/8*Diff) <= Lo AND Hi <= (Min_2 + 9/8*Diff) AND H3==0, Max_2, 0 ) ; H5 = IIf( (Min_2 + 1/8*Diff)<=Lo AND Hi <= (Min_2 + 7/8*Diff) AND H1==0 AND H2==0 AND H3==0 AND H4==0, Min_2 + 3/4*Diff , 0 ) ; H6 = IIf( ( H1 + H2 + H3 + H4 + H5 ) == 0, Max_2, 0 ) ; /**************************/ L1 = IIf(H1>0, Min_2 + 1/4*Diff, 0) ; L2 = IIf(H2>0, Min_2, 0) ; L3 = IIf(H3>0, Min_2 + 1/2*Diff, 0) ; L4 = IIf(H4>0, Min_2 + 1/2*Diff, 0) ; L5 = IIf(H5>0, Min_2 + 1/4*Diff, 0) ; L6 = IIf(H6>0, Min_2, 0 ) ; M_8 = ( H1 + H2 + H3 + H4 + H5 + H6 ) ; M_0 = ( L1 + L2 + L3 + L4 + L5 + L6 ) ; /**************************************/ Graph1 = ValueWhen(Cum(1) >= TF, M_0 ); Graph2 = ValueWhen(Cum(1) >= TF, M_0 + (1*(0.125*(M_8-M_0)))); Graph3 = ValueWhen(Cum(1) >= TF, M_0 + (2*(0.125*(M_8-M_0)))); Graph4 = ValueWhen(Cum(1) >= TF, M_0 + (3*(0.125*(M_8-M_0)))); Graph5 = ValueWhen(Cum(1) >= TF, M_0 + (4*(0.125*(M_8-M_0)))); Graph6 = ValueWhen(Cum(1) >= TF, M_0 + (5*(0.125*(M_8-M_0)))); Graph7 = ValueWhen(Cum(1) >= TF, M_0 + (6*(0.125*(M_8-M_0)))); Graph8 = ValueWhen(Cum(1) >= TF, M_0 + (7*(0.125*(M_8-M_0)))); Graph9 = ValueWhen(Cum(1) >= TF, M_8 ) ; Graph10 = ValueWhen(Cum(1) >= TF, M_8 + (2*(0.125*(M_8-M_0)))); Graph11 = ValueWhen(Cum(1) >= TF, M_0 - (2*(0.125*(M_8-M_0)))); /**************************************************************/ Title = Name() + "=" + WriteIf( round(C)== C, NumToStr(C,1) , WriteVal(C) ) + " " + "\\c17" + WriteIf( Interval()==86400, "Daily ", WriteIf(Interval()==3600,"Hourly ", WriteIf(Interval()==900,"15 Min ", WriteIf(Interval()==300,"5 Min ", WriteIf(Interval()==60,"1 Min ", "" ) ) ) ) ) + Date() + "\\c12" + WriteIf(Volume>0," Turnover=","") + WriteIf(Volume>0, WriteVal(Volume*Close/1000), "" ) ; _SECTION_BEGIN("EMA1"); P = ParamField("Price field",-1); Periods = Param("Periods", 15, 2, 300, 1, 10 ); Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); _SECTION_END(); _SECTION_BEGIN("WMA"); P = ParamField("Price field",-1); Periods = Param("Periods", 15, 2, 300, 1, 10 ); Plot( WMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); _SECTION_END(); _SECTION_BEGIN("WMA1"); P = ParamField("Price field",-1); Periods = Param("Periods", 15, 2, 300, 1, 10 ); Plot( WMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); _SECTION_END(); _SECTION_BEGIN("Bollinger Bands"); P = ParamField("Price field",-1); Periods = Param("Periods", 15, 2, 300, 1 ); Width = Param("Width", 2, 0, 10, 0.05 ); Color = ParamColor("Color", colorCycle ); 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("SAR1"); acc = Param("Acceleration", 0.02, 0, 1, 0.001 ); accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 ); Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) ); _SECTION_END(); SetBarsRequired( 800, 0 ); GraphXSpace = 7; SetChartOptions( 0, chartShowArrows | chartShowDates ); // set criteria to scan for big stock only; BigStock = MA( V, 10 ) * MA( C, 10 ) > 1000000; //---------------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( H, nBars ); aLLVBars = LLVBars( L, nBars ); aHHV = HHV( H, nBars ); aLLV = LLV( L, 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; //Chart Colorbar = IIf( Longs, colorGreen, IIf( Shorts, colorRed, colorGrey40 ) ); Plot( C, "Close", colorbar, styleCandle = 64 | styleNoTitle ); //============== Plot Shape ============== PlotShapes( IIf( aHPivs == 1, shapeDownArrow, shapeNone ), colorOrange, 0, High, Offset = -45 ); PlotShapes( IIf( aLPivs == 1, shapeUpArrow , shapeNone ), colorLime, 0, Low, Offset = -20 ); PlotShapes( IIf(Buy, shapeSmallCircle, shapeNone),colorBrightGreen, 0, BuyPrice, Offset = -15 ); PlotShapes( IIf(Sell, shapeSmallCircle, shapeNone),colorWhite, 0 ,SellPrice, Offset = 45 ); FirstVisibleBar = Status( "FirstVisibleBar" ); Lastvisiblebar = Status("LastVisibleBar"); for( b = Firstvisiblebar; b <= Lastvisiblebar AND b < BarCount; b++) { if( Buy[b] ) PlotText("\n\n\n\n Buy\n "+NumToStr(BuyPrice[b],1.2),b,BuyPrice[b],colorBrightGreen); else if( Sell[b] ) PlotText("Sell "+NumToStr(SellPrice[b], 1.2),b,SellPrice[b],colorWhite); } //============== EMA(13) ============== Plot( EMA( C, 13 ), "" , colorSkyblue + styleLine + styleNoRescale ); //============== TRENDING ============== DTL = 150; // DTL = Define Trend Long DTM = 70; // DTM = Define Trend Medium DTS = 14; // DTS = Define Trend Short TL = LinRegSlope( MA( C, DTL ), 2 ); // TL = Trend Long TM = LinRegSlope( MA( C, DTM ), 2 ); // TM = Trend Medium TS = LinRegSlope( MA( C, DTS ), 2 ); // TS = Trend Short TLL = IIf( LinRegSlope( MA( C, DTL ), 2 ) > 0, True, False ); TMM = IIf( LinRegSlope( MA( C, DTM ), 2 ) > 0, True, False ); TSS = IIf( LinRegSlope( MA( C, DTS ), 2 ) > 0, True, False ); //============== VOLUME ============== Vlp = 30; //Volume lookback period 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; //============== WILLIAM'S %R ============== WR = ( ( HHV( H, 14 ) - C ) / ( HHV ( H, 14 ) - LLV ( L, 14 ) ) ) * -100; //============== A/D ============== TRH = IIf( Ref( C, -1 ) > H, Ref( C, -1 ), H ); TRL = IIf( Ref( C, -1 ) < L, Ref( C, -1 ), L ); ad = IIf( C > Ref( C, -1 ), C - TRL, IIf( C < Ref( C, -1 ), C - TRH, 0 ) ); WAD = Cum( ad ); wu = wad > Ref( wad, -1 ); wd = wad < Ref( wad, -1 ); //============== MACD ============== MB = Cross ( MACD(), Signal() ); MS = Cross( Signal(), MACD() ); MB = ExRem( MB, MS ); MS = ExRem( MS, MB ); MB1 = MACD() > Signal(); MS1 = MACD() < Signal(); //============== STOCH ============== StochKval = StochK( 10, 5 ); StochDval = StochD( 10, 5, 5 ); StochBuy = Cross( StochK( 10, 5 ), StochD( 10, 5, 5 ) ); StochSell = Cross ( StochD( 10, 5, 5 ), StochK( 10, 5 ) ); StBuy = StochK( 10, 5 ) > StochD( 10, 5, 5 ); StSell = StochK( 10, 5 ) < StochD( 10, 5, 5 ); //============== ADX ============== adxBuy = Cross( PDI( 14 ), MDI( 14 ) ); adxSell = Cross( MDI( 14 ), PDI( 14 ) ); adxBuy = ExRem( adxBuy, adxSell ); adxSell = ExRem( adxSell, adxBuy ); adxbuy1 = PDI( 14 ) > MDI( 14 ); adxsell1 = MDI( 14 ) > PDI( 14 ); //==============Zero Lag TMA ============== function ZeroLagTEMA( array, period ) { TMA1 = TEMA( array, period ); TMA2 = TEMA( TMA1, period ); Diff = TMA1 - TMA2; return TMA1 + Diff ; } haClose = ( haClose + haOpen + haHigh + haLow ) / 4; periodtm = 55; ZLHa = ZeroLagTEMA( haClose, periodtm ); ZLTyp = ZeroLagTEMA( Avg, periodtm ); TMBuy = Cross( ZLTyp, ZLHa ); TMSell = Cross( ZLHa, ZLTyp ); TMBuy1 = ZLTyp > ZLHa ; TMSell1 = ZLHa > ZLTyp ; //============== ZLW ============== R = ( ( HHV( H, 14 ) - C ) / ( HHV ( H, 14 ) - LLV ( L, 14 ) ) ) * -100; MaxGraph = 10; PeriodZ = 10; EMA1 = EMA( R, PeriodZ ); EMA2 = EMA( EMA1, 5 ); Difference = EMA1 - EMA2; ZeroLagEMA = EMA1 + Difference; PR = 100 - abs( ZeroLagEMA ); MoveAvg = MA( PR, 5 ); ZBuy = Cross( PR, moveAvg ) AND PR < 30; ZSell = Cross( moveAvg, PR ) AND PR > 70; ZBuy1 = PR >= MoveAvg AND PR >= Ref( PR, -1 ) ; ZSell1 = ( PR < MoveAvg ) OR PR >= MoveAvg AND PR < Ref( PR, -1 ) ; //============== RS ============== p = ( H + L + C ) / 3; r1 = ( 2 * p ) - L; s1 = ( 2 * p ) - H; r2 = p + ( r1 - s1 ); s2 = p - ( r2 - s1 ); R3 = P + ( R2 - S2 ); S3 = P - ( R3 - S2 ); //============== IBUY ============== Ibuy = Cross( RSI( 14 ), EMA( RSI( 14 ), 9 ) ); Isell = Cross( EMA( RSI( 14 ), 9 ), RSI( 14 ) ); Ibuy = ExRem( Ibuy, ISell ); Isell = ExRem( ISell, Ibuy ); BlRSI = RSI( 14 ) > EMA( RSI( 14 ), 9 ); BrRSI = RSI( 14 ) < EMA( RSI( 14 ), 9 ); //=================Trend & Signals & Market Index =============================== /// Please replace "00DSEGEN" with your market index ticker and activate the codes /// Market Bull Bear Cg = Foreign("^GSPC", "C"); Cgo= Ref(Cg,-1); //Longterm Bullish or Bearish Bullg = Cg > WMA(Cg,200); Bearg= Cg WMA(Cg,50); mBearg= Cg WMA(Cg,15); sBearg= Cg =0; Comche1= xChange1<0; xperchange1 = xChange1/100; perchange1 = StrFormat("%1.2f% ",xperchange1); positivechange1 = xperchange1>0; negativechange1 = xperchange1<0; //=================Trend & Signals & Market Index END=============================== //Settings for Backtester SetOption("AllowSameBarExit", False); SetOption("AllowPositionShrinking", False); SetOption("FuturesMode", True); SetOption("InterestRate",0); SetOption("MaxOpenPositions",1); RoundLotSize = Param_LotSize; SetOption("MinShares",RoundLotSize); SetOption("PriceBoundChecking",False); //SetOption("CommissionMode",3); //SetOption("CommissionAmount",12.5/RoundLotSize); SetOption("AccountMargin",Param_Margin); SetOption("ReverseSignalForcesExit",True); SetOption("UsePrevBarEquityForPosSizing",True); SetOption("GenerateReport",1); SetOption("MaxOpenLong",1); SetOption("MaxOpenShort",1); SetOption("RefreshWhenCompleted",True); PositionSize = C*RoundLotSize*Param_NoOfLots; SetTradeDelays(0,0,0,0); BuyPrice = Close; SellPrice = Close; ShortPrice = Close; CoverPrice = Close; //End of Settings for Backtester _SECTION_END();