_SECTION_BEGIN("ABKPPivotAndPops");
SetBarsRequired(350, -0);
//user parameters
parmPlotScoreCard = ParamToggle("Plot KPScoreCard", "No|Yes", 1);
parmPlotA900AutoStop = ParamToggle("Plot A900/AutoStop", "No|Yes", 0);
parmA900Color = ParamColor("A900 Color", colorBlack);
parmA900Style = ParamStyle("A900 Style", styleNoLabel, maskAll);
parmAutoStopColor = ParamColor("AutoStop Color", colorCustom12);
parmAutoStopStyle = ParamStyle("AutoStop Style", styleLine, maskAll);
parmPPTextColor = ParamColor("PP Text color", colorBlack);
parmPPTrndColorUp = ParamColor("PP Trend Up color", colorGreen );
parmPPTrndColorDn = ParamColor("PP Trend Dwn color", colorRed );
parmPPTextOffSet = Param("PP OffSet", 0.90, 0.40, 1.5, 0.1);
parmTickMultipler = Param("M/W tick allowance", 0, 0, 10, 1);
parmA900AutoStopX = ParamToggle("Plot A900/AutoStop Cross", "No|Yes");
parmA900AutoStopColorX = ParamColor("A900/AutoStop Cross Color", colorBlack);
ParmSCThreshold = Param("ScoreCard Threshold", 5, 1, 9, 1);
parmVoice = ParamToggle("Pivot Voice", "No|Yes", 0);
parmPivotPop = ParamToggle("PivotPop", "No|Yes", 1);
parmBarCancel = Param("Bar Cancel", 4, 1, 20, 1);
parmFilter = ParamList("Filter", "None|KPMSL|KPWaterLevel|KPMedium", 0);
parmPlotFilter = ParamToggle("Plot Filter", "No|Yes", 0);
parmFilterColor = ParamColor("Filter Color", ColorRGB(127,255,212));
parmFilterStyle = ParamStyle("Filter Style", styleLine, maskAll);
parmBBPeriod = Param("Bollinger Band Period", 20, 2, 30, 1);
parmBBSD = Param("Bollinger Band width", 1.0, 0.5, 3.0, 0.5);
ParmPlotPPIndicators = ParamToggle("Plot Pivot Pop indicators", "No|Yes", 0);
parmBBColor = ParamColor("BBands Color", colorBlack);
parmBBStyle = ParamStyle("BBands Style", styleLine, maskAll);
ParmDebug = ParamToggle("Debug", "No|Yes", 0);
// constants
_N(PaneName = Name() + Interval(2)+ _SECTION_NAME());
_N(NewBarName = "NewBar" + PaneName);
//functions
function NewBarP()
{
PrevDT = StaticVarGet( NewBarName);
DT = LastValue(DateTime());
StaticVarSet( NewBarName,DT);
return DT != PrevDT;
}
function MRoundP(Number, Multiple )
{
if(Multiple == 0 )
{
xMultiple = 0.01; }
else
{
xMultiple = Multiple;
}
Divided = Number / xMultiple;
intDivided = int(Divided);
intDivided = intDivided + round(Divided - intDivided);
return intDivided * xMultiple;
}
//miscellaneous setups
ObjAB = CreateObject("Broker.Application");
ticker = objAB.Stocks(Name() );
if(ticker.TickSize == 0)
{
TickValue = 0.01; //set TickValue to a penney
}
else
{
TickValue = ticker.TickSize; // use Tick Size for this symbol
}
NewBarSignal = NewBarP();
// KP Indicators
KPA900 = E_TSKPA900(Close);
KPAutoStop = E_TSKPAUTOSTOP(High,Low,Close);
Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume); //ScoreCard
KPScoreCard = 0;
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd0 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd1 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd2 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd3 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd4 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd5 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd6 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd7 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd8 > 0, 1, -1);
if(parmDebug == 1)
{
printf("a900: %0.6f% \nAutoStop: %0.6f%\nScoreCard: %0.0f%\n", KPA900, KPAutoStop, KPScoreCard);
}
if(parmPlotScoreCard == 1)
{
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g% (%0.4f%) {{VALUES}}", O, H, L, C, SelectedValue( C - Ref(C, -1)) ));
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.2f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
Color = IIf(KPScoreCard >= parmSCThreshold, colorBlue, IIf(KPScoreCard <= -parmSCThreshold, colorRed, colorYellow) );
Plot( C, "Close", Color , styleNoTitle | styleBar+styleThick );
}
//user want A900/AutoStop plotted
if(parmPlotA900AutoStop == 1)
{
Plot(KPA900, "A900", parmA900Color, parmA900Style);
Plot(KPAutoStop, "AutoStop", parmAutoStopColor, parmAutoStopStyle);
}
// find A900/AutoStop cross over/under with ScoreCard confirmation.
XOUp = (KPA900 > KPAutoStop) AND (KPScoreCard >= parmSCThreshold); // New Pivot Low
XODn = (KPA900 < KPAutoStop) AND (KPScoreCard <= -parmSCThreshold); // New Pivot High
if(parmDebug == 1)
{
printf(WriteIf(XOUp, "before= XOUp: True", "before= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//remove duplicate signals
XOUp = ExRem(XOUp, XODn);
XODn = ExRem(XODn, XOUp);
if(parmDebug == 1)
{
printf(WriteIf(XOUp, "after= XOUp: True", "after= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//find the current Pivot Points - PL and PH
//remember XOUp = 1 means a PL and XODn =1 means a PH
PLBars = IIf(XOUp, LowestSinceBars(XODn, L ,1), 0); //find the bar that produced the Lowest Low
PHBars = IIf(XODn, HighestSinceBars(XOUp, H, 1),0); //find the bar that produced the Highest High
//PLPrice = IIf(XOUp, Ref(L, -PLBars), 0);
//PHPrice = IIf(XODn, Ref(H, -PHBars),0);
PLPrice = Ref(L, -PLBars);
PHPrice = Ref(H, -PHBars);
//keep track of the previous Pivot Points
PrevPLBars = Ref(BarsSince(XOUp), -1) +1;
PrevPHBars = Ref(BarsSince(XODn), -1) +1;
PrevPLPrice = Ref(PLPrice, -prevPLBars);
PrevPHPrice = Ref(PHPrice, -PrevPHBars );
PivotsCloseEnough = TickValue * parmTickMultipler;
PLDifference = MroundP(PLPrice - PRevPLPrice, ticker.TickSize);
PHDifference = MroundP(PHPrice - PrevPHPrice, ticker.TickSize);
PPTrend = IIf(XOUp AND (PLDifference > PivotsCloseEnough) AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 1,
IIf(XOUp AND (PLDifference < - PivotsCloseEnough) AND PRevPHPrice > PrevPLPrice AND PrevPHPrice > PLPrice, -1,
IIf(XODn AND (PHDifference > PivotsCloseEnough) AND PrevPLPrice < PrevPHprice AND PrevPLPrice < PHPrice, 1,
IIf(XODn AND (PHDifference < -PivotsCloseEnough) AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -1, 0)) ));
/*
PPTrend = IIf(XOUp AND PLPrice > PRevPLPrice AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 1,
IIf(XOUp AND PLPrice < PRevPLPrice AND PRevPHPrice > PrevPLPrice AND PrevPHPrice > PLPrice, -1,
IIf(XODn AND PHPrice > PrevPHPrice AND PrevPLPrice < PrevPHprice AND PrevPLPrice < PHPrice, 1,
IIf(XODn AND PHPrice < PrevPHPrice AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -1, 0)) ));
*/
if(ParmDebug)
{
printf("Current PH Bar: %g% /Price: %g%\n", PHBars, PHPrice);
printf("Current PL Bar: %g% /Price: %g%\n", PLBars, PLPrice);
printf("Previous PH Bar: %g% /Price: %g%\n", PrevPHBars, PrevPHPrice);
printf("Previous PL Bar: %g% /Price: %g%\n", PrevPLBars, PrevPLPrice) ;
printf("PP Trend: %g%\n", PPTrend);
printf("PHPrice - PrevPHPrice: %g%\nPLPrice - PrevPLPrice: %g%\nPivotsCloseEnough: %g%\n", PHDifference, PLDifference, PivotsCloseEnough);
}
//PLot pivots as text
dist = parmPPTextOffSet * ATR(10);
//for( i = 0; i < BarCount -1; i++)
for( i = 0; i < BarCount ; i++)
{
if(XOUp[i ] == 1 ) //cross up -plot the Pivot Low
{
PlotText("PL \n"+PLPrice[i], i - PLBars[i], PLPrice[i] - dist[i] , parmPPTextColor, IIf(PPTrend[i] == 1, parmPPTrndColorUp, IIf(PPTrend[i] == -1, parmPPTrndColorDn, colorYellow) ));
}
if(XODn[i ] == 1 ) //cross down - plot the pivot high
{
PlotText("PH \n"+PHPrice[i], i - PHBars[i], PHPrice[i] + dist[i], parmPPTextColor, IIf(PPTrend[i] == 1, parmPPTrndColorUp, IIf(PPTrend[i] == -1, parmPPTrndColorDn, colorYellow) ));
}
} //end For
// Plot A900/AutoStop cross over/under
if(parmA900AutoStopX == 1)
{
PlotShapes(IIf(Cross(KPA900, KPAutoStop), shapeUpTriangle, shapeNone), parmA900AutoStopColorX, 0, L, -20);
PlotShapes(IIf(Cross(KPAutoStop, KPA900), shapeDownTriangle, shapeNone), parmA900AutoStopColorX, 0, H , -20);
}
//PHLine = LineArray(BarCount - LastValue(PHBars) -3, LastValue(PHPrice), BarCount - LastValue(PHBars) +2, LastValue(PHPrice), 0);
//Plot(PHLine, "PH", colorBlack, styleLine);
//PLLine = LineArray(BarCount - LastValue(PLBars) -3, LastValue(PLPrice), BarCount - LastValue(PLBars) +2, LastValue(PLPrice), 0);
//Plot(PLLine, "PL", colorBlack, styleLine);
// identify M, lazy M, W and Lazy W formations
//voice
if(parmVoice ==1)
{
if(NewBarSignal)
{
if( LastValue(Ref(XODn, -1)) == 1 AND LastValue(Ref(PPTrend, -1)) == 1) Say(Interval(2) + " New pivot. Higher high.");
if( LastValue(Ref(XODn, -1)) == 1 AND LastValue(Ref(PPTrend, -1)) == -1) Say(Interval(2) + " New pivot. Lower high.");
if( LastValue(Ref(XODn, -1)) == 1 AND LastValue(Ref(PPTrend, -1)) == 0) Say(Interval(2) + " New pivot. M Top.");
if( LastValue(Ref(XOUp,-1)) ==1 AND LastValue(Ref(PPTrend, -1)) == 1) Say(Interval(2) + " New pivot. Higher low.");
if( LastValue(Ref(XOUp,-1)) ==1 AND LastValue(Ref(PPTrend, -1)) == -1) Say(Interval(2) + " New pivot. Lower low.");
if( LastValue(Ref(XOUp,-1)) ==1 AND LastValue(Ref(PPTrend, -1)) == 0) Say(Interval(2) + " New pivot. W bottom.");
}
}
//Pivot Pop code
if(parmPivotPop == 1)
{
//Kp indicators for Pivot Pop
dummy = E_TSKPFAST2(Open, High, Low, Close, Volume);
KPFast2 = IIf(tskp_fast2val1 > 0, 1, -1);
BarsSinceXOUp =BarsSince(XOUp);
BarsSinceXODn = BarsSince(XODn);
switch(parmFilter)
{
case "None":
PopFilter = True;
break;
case "KPMSL":
swVal = E_TSKPSWINGLINE(High, Low, Close);
KPMSL = tskp_swmean;
PopFilter = IIf(BarsSinceXOUp < BarsSinceXODn AND (C > KPMSL), True, IIf(BarsSinceXODn < BarsSinceXOUp AND (C < KPMSL), True, False));
break;
case "KPWaterLevel":
KPWaterlevel = E_TSKPWATERLEVEL(Open,High,Low,Close,Volume);
PopFilter = IIf(BarsSinceXOUp < BarsSinceXODn AND (C > KPWaterLevel), True, IIf(BarsSinceXODn < BarsSinceXOUp AND (C < KPWaterLevel), True, False));
break;
case "KPMedium":
dummy = E_TSKPMEDIUM(Close);
KPMediumUp = tskp_mediumup;
KPMediumDn = tskp_mediumdown;
KPMediumMA = tskp_mediumma;
KPMedium = KPMediumUp + KPMediumDn;
PopFilter = IIf(BarsSinceXOUp < BarsSinceXODn AND (KPMedium > KPMediumMA), True, IIf(BarsSinceXODn < BarsSinceXOUp AND (KPMedium < KPMediumMA), True, False));
break;
}
//calculations
UBB = BBandTop(C, parmBBPeriod, parmBBSD);
LBB = BBandBot(C, parmBBPeriod, parmBBSD);
if(parmDebug == 1)
{
printf("Fast2: %1.0f% \nUBB: %0.6f%\nLBB: %0.6f%\nC: %g%\n", KPFast2, UBB, LBB, C);
printf("Bars since Last XOUp: %1.0f%\nBars since last XODn: %1.0f%\n", BarsSinceXOUp, BarsSinceXODn );
printf("Bars since PPTrnd =1: %1.0f%\nBars since PPTrnd = -1: %1.0f%\n", BarsSince(PPTrend ==1), BarsSince(PPTrend == -1) );
printf("ParmFilter: " + parmFilter + "\nPopFilter: %g%\n", PopFilter);
switch(parmFilter)
{
case "None":
break;
case "KPMSL":
printf("KPMSL: %g%\n", KPMSL);
break;
case "KPWaterLevel":
printf("KPWaterlevel: %g%\n", KPWaterLevel);
break;
case "KPMedium":
printf("KPMedium: %g%\nKPMediumMA: %g%\n", KPMedium, KPMediumMA);
break;
}
}
PPopUp = (BarsSince(PPTrend == 1) <= parmBarCancel) AND (BarsSince(XOUp) <= parmBarCancel) AND (KPA900 >= KPAutoStop) AND(KPFast2 == 1) AND (KPScoreCard >= 5)
AND PopFilter
AND (C > UBB) AND (C > O) ;
PPopUp = IIf( PPopUp AND Sum(PPopUP, BarsSince(XOUp)+1) == 1, True, False ); //keep only the 1st signal
PPopDn = (BarsSince(PPTrend == -1) <= parmBarCancel) AND (BarsSince(XODn) <= parmBarCancel) AND (KPA900 <= KPAutoStop) AND(KPFast2 == -1) AND (KPScoreCard <= -5)
AND PopFilter
AND (C < LBB) AND (C < O) ;
PPopDn = IIf( PPopDn AND Sum(PPopDn, BarsSince(XODn) + 1) == 1, True, False); //keep only the first signal
if(parmDebug == 1)
{
printf(WriteIf(PPopUp,"PPopUp: True", "PPopUp: False") + WriteIf(PPopDn, " PPopDn: True\n", " PPopDn: False\n") );
printf("PPopUp sum: %1.0f% \nPPopDn sum: %1.0f%", Sum(PPopUP, BarsSince(XOUp)) , Sum(PPopDn, BarsSince(XODn)) );
}
// Plots
PlotShapes(IIf(PPopUp, shapeUpTriangle, shapeNone), colorLightBlue, 0, L, -30);
PlotShapes(IIf(PPopDn, shapeDownTriangle, shapeNone), colorRed, 0, H, -30);
if(ParmPlotPPIndicators == 1) //plot the Pivot Pop Indicators
{
Plot(UBB, "Upper BB", parmBBColor, parmBBStyle);
Plot(LBB, "Lower BB", parmBBColor, parmBBStyle);
if(parmPlotA900AutoStop == 1)
{
Plot(KPA900, "A900", parmA900Color, parmA900Style);
Plot(KPAutoStop, "AutoStop", parmAutoStopColor, parmAutoStopStyle);
}
Plot( 0.5, "Fast2", IIf(tskp_fast2val1 > 0, parmPPTrndColorUp, parmPPTrndColorDn) , styleArea | styleNoLabel | styleOwnScale , 0, 10);
} //endif parmPlotPPIndicators
if(parmPlotFilter == 1)
{
switch(parmFilter)
{
case "None":
break;
case "KPMSL":
Plot(KPMSL, "KPMSL", parmFilterColor, parmFilterStyle);
break;
case "KPWaterLevel":
Plot(KPWaterLevel, "KPWaterLevel", parmFilterColor, parmFilterStyle);
break;
case "KPMedium":
// HMM how to print Medium on a price chart
break;
}
} //endif parmPlotFilter
} // end if parmPivotPop
_SECTION_END();
_SECTION_BEGIN("Fibo for all bars");
TimeFrameSet( in15Minute*2 );
DH=Ref(H,-1);
DL=Ref(L,-1);
DC=Ref(C,-1);
pd = (O+ DH+ DL + DC )/4;
sd1 = (2*pd)-DH;
sd2 = pd -(DH - DL);
sd3 = Sd1 - (DH-DL);
rd1 = (2*pd)-DL;
rd2 = pd +(DH -DL);
rd3 = rd1 +(DH-DL);
//Plot (pd,"Pivot",colorBlue,styleDots);
//Plot (rd1," R1 ",35,styleDots);
//Plot (rd2," R2 ",35,styleDots);
//Plot (rd3," R3 ",35,styleDots);
//Plot (sd1," S1 ",4,styleDots);
//Plot (Sd2," S2 ",4,styleDots);
//Plot (Sd3," S3 ",4,8+16);
/*
style = IIf(ParamList("Chart style", "styleCandle|styleBar")=="styleCandle",64,128+4);
Plot (C,Date ()+" close",1,style); //ENABLE THIS TO HAVE CANDLES AS WELL
*/
TimeFrameRestore();
Title = EncodeColor(colorWhite)+ "Previous High Previous Low Detector" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "
//+ WriteIf(Col_action==colorGreen, EncodeColor(colorGreen)+"stay LONG","")+ WriteIf(Col_action==colorRed, EncodeColor(colorRed)+"stay SHORT","")+ WriteIf(Col_action==colorBlack, EncodeColor(colorYellow)+"No Trend","")+"\n"
+ "Vol= "+ WriteVal(V) +WriteIf ( V > MA(V,26) ,EncodeColor(colorGreen)+" UP "+ (V/MA(V,26))*100 + " %", EncodeColor(colorRed)+" DOWN "+ (V/MA(V,26))*100 + " %")
+ EncodeColor(colorGreen)+ "\n R3 : "+ EncodeColor(colorWhite)+RD3
+ EncodeColor(colorGreen)+ "\n R2 : "+ EncodeColor(colorWhite)+RD2
+ EncodeColor(colorGreen)+ "\n R1 : "+ EncodeColor(colorWhite)+RD1+ EncodeColor(colorGreen)+ "` Hi: "+ EncodeColor(colorWhite)+H
+ EncodeColor(colorBlue)+ "\n Pivot : "+ EncodeColor(colorWhite)+pd + EncodeColor(colorYellow)+ "` Op: "+ EncodeColor(colorWhite)+O+ EncodeColor(colorAqua)+ "Cl: "+ EncodeColor(colorBrightGreen)+C
+ EncodeColor(colorRed)+ "\n S1 : "+ EncodeColor(colorWhite)+SD1+ EncodeColor(colorRed)+ "` Lo: "+ EncodeColor(colorWhite)+L
+ EncodeColor(colorRed)+ "\n S2 : "+ EncodeColor(colorWhite)+SD2
+ EncodeColor(colorRed)+ "\n S3 : "+ EncodeColor(colorWhite)+SD3
;
_SECTION_END();
_SECTION_BEGIN("NICK MA Swing");
DayH = TimeFrameGetPrice("H", in15Minute*2, -1);// yesterdays high
DayL = TimeFrameGetPrice("L", in15Minute*2, -1);//low
DayC = TimeFrameGetPrice("C", in15Minute*2, -1);//close
DayO = TimeFrameGetPrice("O", in15Minute*2 );//open today
R6 = (DayH / DayL) * DayC * 1.002;
R5 = (DayH / DayL) * DayC;
R4 = (((DayH / DayL) + 0.83) / 1.83) * DayC;
R3 = ( ( (DayH / DayL) + 2.66) / 3.66) * DayC;
R2 = ( ( (DayH / DayL) + 4.5) / 5.5) * DayC;
R1 = ( ( (DayH / DayL) + 10) / 11) * DayC;
S1 = (2- ( ( (DayH / DayL) + 10) / 11)) * DayC;
S2 = (2-( (DayH / DayL) + 4.5) / 5.5) * DayC;
S3 = (2-(( DayH / DayL) + 2.66) / 3.66) * DayC;
S4 = (2-( (DayH / DayL) + 0.83) / 1.83) * DayC;
S5 = (2-( DayH / DayL)) * DayC;
S6 = (2-( DayH / DayL)) * DayC * 0.998;
//Plot(Close,"",colorBlue,styleBar+styleThick);
Plot(s3, "", colorGreen,styleThick+styleNoLabel);
Plot(s4, "", colorGreen,styleThick+styleNoLabel);
Plot(r3, "", colorRed,styleThick+styleNoLabel);
Plot(r4, "", colorRed,styleThick+styleNoLabel);
pivot = (DayH+DayL+DayC)/3;
NW = pivot;
J = MA(Close,3);
Plot(j, "", IIf(j > Ref(j,-1),colorGreen,colorOrange),styleThick);
Plot(NW, "", colorWhite,styleThick+styleNoLabel);
Buy=Cover=Cross(j,r4);
Sell=Short=Cross(s4,j);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
SellPrice=ValueWhen(Sell,C,1);
BuyPrice=ValueWhen(Buy,C,1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );
_SECTION_END();
// divergence tracking of rsi
n=20;
Buy_rsi=Sell_rsi=0;
Var = Zig(RSI(14), n);
t= Trough(RSI(14), n, 1);
p= Peak(RSI(14), n, 1);
x[0] =Var[0];
price[0] = C[0];
j=0;
// bearish divergence
for ( i=0; i<BarCount; i++)
{
if(Var[i] == p[i])
{
j++;
x[j] =Var[i];
price[j] =C[i];
if(x[j] <x[j-1] && price[j-1]< price[j])
Sell_rsi[i] =1;
}
}
// bullish divergence
for ( i=0; i<BarCount; i++)
{
if(Var[i] == t[i])
{
j++;
x[j] =Var[i];
price[j] =C[i];
if(x[j] >x[j-1] && price[j]<price[j-1])
Buy_rsi[i] =1;
}
}
//Plot(Var, "", 39);
PlotShapes ( IIf(Sell_rsi, shapeDigit2, shapeNone), colorRed);
PlotShapes( IIf(Buy_rsi, shapeDigit2, shapeNone), colorBrightGreen);
//=======================digengence on stoch
ST33=StochD(14);
TR1=LLVBars(ST33,4);
TR2=IIf(ST33<30 AND TR1>0 AND Ref(TR1,-1)==0,Ref(ST33,-1),0);
TRC=IIf(TR2>0,C,0);
vs=ValueWhen(tr2, Ref(st33,-1), 1);
dvs=vs-Ref(vs,-1);
vc=ValueWhen(trc, LLV(C,3), 1);
dvc=vc-Ref(vc,-1);
diver=IIf(dvs>0 AND dvc<0,30,0);
DAS=BarsSince(Ref(TR2,-1)>0);
DD=IIf(DAS<20 AND C>=Ref(C,-1),DIVER,0);
//Graph0=TR2;
//Graph0Style=2;
//Graph0BarColor=12;
//Graph1=dd;
//Graph1BarColor=5;
Buy1=DD>0 ;
PlotShapes( IIf(Buy1, shapeDigit1, shapeNone), colorBrightGreen);
ST33=StochD(14);
TR11=HHVBars(ST33,4);
TR21=IIf(ST33>70 AND TR11>0 AND Ref(TR11,-1)==0,Ref(ST33,-1),0);
TRC1=IIf(TR21>0,C,0);
vs1=ValueWhen(tr21, Ref(st33,-1), 1);
dvs1=vs1-Ref(vs1,-1);
vc1=ValueWhen(trc1, HHV(H,3), 1);
dvc1=vc1-Ref(vc1,-1);
diver1=IIf(dvs1<0 AND dvc1>0,90,0);
DAS1=BarsSince(Ref(TR21,-1)>0);
ddd1=IIf(DAS1<20 AND C<Ref(C,-1),DIVER1,0);
//Graph1=TR2;
//Graph0=ddd;
//Graph0BarColor=4;
//Graph1Style=2;
//Graph1BarColor=1;
Sell1=ddd1==90;
PlotShapes ( IIf(Sell1, shapeDigit1, shapeNone), colorRed);
EMA1= EMA(Close,12);
EMA2= EMA(EMA1,12);
Difference= EMA1 - EMA2;
ZeroLagEMAp= EMA1 + Difference;
//---------------------------------------
EMA1= EMA(Close,26);
EMA2= EMA(EMA1,26);
Difference= EMA1 - EMA2;
ZeroLagEMAq= EMA1 + Difference;
//---------------------------------------
ZeroLagMACD=ZeroLagEMAp - ZeroLagEMAq;
ST33= ZeroLagMACD;
bars=50;
TR1= LLVBars(ST33,5);
COND1=TR1> 0 AND Ref(TR1,-1)==0 AND Ref(ST33,-1)<0;
TR2= IIf(COND1,Ref(ST33,-1),0);
M1= ValueWhen(COND1,ST33);
P1= ValueWhen(COND1,LLV(L,3));
DM1=M1- Ref(M1,-1);DP1=P1-Ref(P1,-1);
DT= Ref(BarsSince(COND1),-1);
POSDIV=DM1> 0 AND DP1<0 AND DT<BARS;
TR11= HHVBars(ST33,5);
COND11=TR11> 0 AND Ref(TR11,-1)==0 AND Ref(ST33,-1)>0;
TR21= IIf(COND11,Ref(ST33,-1),0);
M11= ValueWhen(COND11,ST33);
P11= ValueWhen(COND11,HHV(H,3));
DM11=M11- Ref(M11,-1);DP11=P11-Ref(P11,-1);
DT1= Ref(BarsSince(COND11),-1);
NEGDIV=DM11< 0 AND DP11>0 AND DT1<BARS;
PlotShapes(shapeDigit3*POSDIV,colorBrightGreen);
PlotShapes(shapeDigit3*NEGDIV,colorRed);
col_bar = IIf(ZeroLagMACD > Ref(ZeroLagMACD,-1),colorBrightGreen,colorRed);
//Plot(Close,"close",col_bar,styleBar+styleThick);
//========hist divergence
A1=EMA(C,12)-EMA(C,26);
a2 = EMA(a1,9);
Hist = a1-a2;
ST33= Hist;
bars=50;
TR1= LLVBars(ST33,5);
COND1=TR1> 0 AND Ref(TR1,-1)==0 AND Ref(ST33,-1)<0;
TR2= IIf(COND1,Ref(ST33,-1),0);
M1= ValueWhen(COND1,ST33);
P1= ValueWhen(COND1,LLV(L,3));
DM1=M1- Ref(M1,-1);DP1=P1-Ref(P1,-1);
DT= Ref(BarsSince(COND1),-1);
POSDIV1=DM1> 0 AND DP1<0 AND DT<BARS;
TR11= HHVBars(ST33,5);
COND11=TR11> 0 AND Ref(TR11,-1)==0 AND Ref(ST33,-1)>0;
TR21= IIf(COND11,Ref(ST33,-1),0);
M11= ValueWhen(COND11,ST33);
P11= ValueWhen(COND11,HHV(H,3));
DM11=M11- Ref(M11,-1);DP11=P11-Ref(P11,-1);
DT1= Ref(BarsSince(COND11),-1);
NEGDIV1=DM11< 0 AND DP11>0 AND DT1<BARS;
PlotShapes(shapeDigit4*POSDIV1,colorBrightGreen);
PlotShapes(shapeDigit4*NEGDIV1,colorRed);
_SECTION_END();
//=================TITLE================================================================================================
_SECTION_END();
//=================TITLE================================================================================================
_SECTION_BEGIN("Title");
Title = EncodeColor(colorWhite)+ "" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n"+
EncodeColor(colorYellow)+ " 30M's High : "+ EncodeColor(colorWhite)+DayH + EncodeColor(colorYellow)+ " 30M's Low : "+ EncodeColor(colorWhite)+DayL
+"\n"+
WriteIf(H > Ref(H,-1),EncodeColor(colorBrightGreen),EncodeColor(colorRed))+" Hi "+H+"\n"+
EncodeColor(colorWhite)+"Op "+O+EncodeColor(colorAqua)+" Cl : " +C+"\n"+
WriteIf(L < Ref(L,-1),EncodeColor(colorRed),EncodeColor(colorBrightGreen))+" Lo "+L+
"\n"+
//WriteIf (Buy ,EncodeColor(colorGreen)+ " GO LONG / Reverse Signal at "+C+" ","")+
//WriteIf (Sell ,EncodeColor(colorRed)+ " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
//WriteIf(Sell , EncodeColor(colorRed)+"Total Profit/Loss for the Last Trade Rs."+round(C-BuyPrice)+"","")+
//WriteIf(Buy ,EncodeColor(colorGreen)+ "Total Profit/Loss for the Last trade Rs."+round(SellPrice-C)+"","")+
//WriteIf(Long AND NOT Buy,EncodeColor(colorGreen)+ "Trade : Long - Entry price Rs."+(BuyPrice),"")+
//WriteIf(shrt AND NOT Sell,EncodeColor(colorRed)+ "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
//WriteIf(Long AND NOT Buy, EncodeColor(colorYellow)+"Current Profit/Loss Rs."+round(C-BuyPrice)+"\n Place SL at "+s4,"")+
//WriteIf(shrt AND NOT Sell,EncodeColor(colorYellow)+ "Current Profit/Loss Rs."+round(SellPrice-C)+"\n Place SL at "+R4,"")+
//"\n"+
WriteIf(C > R6,EncodeColor(colorYellow)+"\n Price "+C,"")+
EncodeColor(colorDarkRed)+"\n H6 : "+R6+
WriteIf(C > R5 AND C < r6,EncodeColor(colorYellow)+" \n Price "+C,"")+
EncodeColor(colorDarkRed)+"\n H5 : "+R5+
WriteIf(C > R4 AND C < r5,EncodeColor(colorYellow)+" \n Price "+C,"")+
EncodeColor(colorRed)+"\n H4 : "+R4+
WriteIf(C > R3 AND C < r4,EncodeColor(colorYellow)+" \n Price "+C,"")+
EncodeColor(colorRed)+"\n H3 : "+R3+
"\n"+
WriteIf(C > s3 AND C < r3,EncodeColor(colorYellow)+" \n Price "+C,"")+
"\n"+
EncodeColor(colorBrightGreen)+"\n L3 : "+S3+
WriteIf(C > s4 AND C < s3,EncodeColor(colorYellow)+" \n Price "+C,"")+
EncodeColor(colorBrightGreen)+"\n L4 : "+S4+
WriteIf(C > s5 AND C < s4,EncodeColor(colorYellow)+" \n Price "+C,"")+
EncodeColor(colorDarkGreen)+"\n L5 : "+S5+
WriteIf(C > s6 AND C < s5,EncodeColor(colorYellow)+" \n Price "+C,"")+
EncodeColor(colorDarkGreen)+"\n L6 : "+S6+
WriteIf(C < s6,EncodeColor(colorYellow)+" \n Price "+C,"")+
"\n"+
WriteIf(Sell_rsi,EncodeColor(colorRed)+"\n SELL :Divergence on RSI","") +
WriteIf(Buy_rsi,EncodeColor(colorBrightGreen)+"\n BUY :Divergence on RSI","")+
WriteIf(Sell1,EncodeColor(colorRed)+"\n SELL :Divergence on STOCH","") +
WriteIf(Buy1,EncodeColor(colorBrightGreen)+"\n BUY :Divergence on STOCH","")+
WriteIf(POSDIV,EncodeColor(colorBrightGreen)+"\n BUY :Divergence on MACD","")+
WriteIf(NEGDIV,EncodeColor(colorRed)+"\n SELL :Divergence on MACD","") +
WriteIf(POSDIV1,EncodeColor(colorBrightGreen)+"\n BUY :Divergence on HIST","")+
WriteIf(NEGDIV1,EncodeColor(colorRed)+"\n SELL :Divergence on HIST","")
;