Which combination of indicators helps detect an impnding upmove or downmove reliably?

MANISH_DAMANI

Well-Known Member
#41
Re: Which combination of indicators helps detect an impnding upmove or downmove relia

"The security price has set a new 14-day high while the RSI has not. This is a bearish divergence.",
WriteIf( vrsi >= HHV( vrsi, 14 ) AND Close < HHV( Close, 14 ),
"The RSI has set a new 14-day high while the security price has not. This is a bullish divergence.",
WriteIf( Close <= LLV( Close, 14 ) AND vrsi > LLV( vrsi, 14 ),
"The security price has set a new 14-day low while the RSI has not. This is a bullish divergence.",
WriteIf( vrsi <= LLV( vrsi, 14) AND Close > LLV(Close,14),
"The RSI has set a new 14-day low while the security price has not. This is a bearish divergence.",
"The RSI and price are not diverging." ) ) ) ));

printf("\n\nDivergence:\n");
temp = Trough(Low, 2, 1) < 0.96 * Ref( Trough(Low, 2, 1), -1) AND ValueWhen( Trough(Low, 2, 1) != Ref( Trough(Low, 2, 1), -1 ), MACD(), 1 ) >= 0.90 * ValueWhen( Trough( Low, 2, 1) != Ref( Trough( Low, 2, 1), -1 ), MACD(), 2 ) AND MACD() < 0;

temp2= Peak( High,2, 1) > 1.04 * Ref( Peak( High, 2, 1), -1) AND ValueWhen( Peak( High, 2, 1) != Ref( Peak( High, 2, 1), -1 ), MACD(), 1 ) <= 0.90 * ValueWhen( Peak( High, 2, 1) != Ref( Peak( High, 2, 1), -1 ), MACD(), 2 ) AND MACD() > 0;

printf(WriteIf( HHV( temp, 5 ) == 1,"A bullish divergence occurred " + WriteVal( BarsSince( temp ), 1.0 ) +
" period(s) ago. Wait for upward price movement for confirmation before considering any long positions.",
WriteIf( HHV( temp2,5) == 1,
"A bearish divergence occurred " +
WriteVal( BarsSince( temp2 ), 1.0 ) +
" period(s) ago. Wait for downward price movement for confirmation before considering any short positions.",
"There have been no divergence signals within the last 5 periods." ) ));

Is it possible to make commentary for divergence like macd and rsi for stochastic also
 

MANISH_DAMANI

Well-Known Member
#43
Re: Which combination of indicators helps detect an impnding upmove or downmove relia

Manishji,
Pl. Elaborate this,not able to understand it fully.
:confused:
I am requesting that if some body has interpretation AFL (i.e commentry) on divergence of stochastic like in MACD, RSI I have shown above. As I am poor in writing AFl.:):thumb:
 

johnnypareek

Well-Known Member
#44
Re: Which combination of indicators helps detect an impnding upmove or downmove relia

You are really asset Jhony Bhai. Any afl on elliot wavre devloped or not. If yes then like to share.
chk mif it works for u

HTML:
// ELLIOT WAVE
//-- Script Start -------
Option = ParamToggle("Insert To", "Price Chart|Indicator");

pr=Param("Elliot Wave minimum % move",2, 0.001,100);

//{ 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;

//{ Advanced Elliot Wave stuff }
RetroSuccessSecret=IIf(EWpk,zzHi,
IIf(EWtr,zzLo,IIf(Avg>Ref(Avg,-1),H,L)));
EW=Zig(RetroSuccessSecret,pr);


_SECTION_BEGIN("Colour Bar Chart");
outsidebar = H > Ref( H, -1 ) AND L < Ref( L, -1 );
insidebar = H < Ref( H, -1 ) AND L > Ref( L, -1 );
upbar = H > Ref( H, -1 ) AND L >= Ref( L, -1 );
downbar = L < Ref( L, -1 ) AND H <= Ref( H, -1 );

barcolor = IIf(outsidebar, colorBlue,
IIf(downbar, colorRed,
IIf(upbar, colorGreen,
IIf(insidebar, 11, colorBlack)
)
)
);

Title = Name() + "\\c" + barcolor + " - Color Bar Chart : " +
WriteIf(Outsidebar, "Outside Bar",
WriteIf(insidebar, "Inside Bar",
WriteIf(upbar, "Up Bar",
WriteIf(downbar, "Down Bar", "Neutral Bar")
)
)
);
Plot(Close, Title, barcolor, styleThick + styleBar);
//{ Plot on price chart }
if (Option==0)
Plot(EW, "EW", ParamColor("Color", colorBrown), ParamStyle("Style", styleNoLabel|styleThick));
else
{

//{ Buy/Sell Elliot Wave stuff }
EWbuy=TroughBars(EW,pr)==0;
EWsell=PeakBars(EW,pr)==0;

//{ Plot on own window }
Plot(EWbuy-EWsell, "EW2", ParamColor("Color", colorRed), ParamStyle("Style", styleNoLabel|styleThick));

}
//-- Script End -------



_SECTION_END();

_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g
(%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1
)));
}

SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorDarkTeal),
ParamColor("Inner panel color lower half",colorBlack)//color of inner panel
,ParamColor("behind Text Color", colorYellow));
_SECTION_END();



//Elliot Wave [Single Loop]
_SECTION_BEGIN("Elliotwave");
X=BarIndex();
p=Param("p",0.50,0.5,30,0.1);
z=Zig(C,p);Plot(C,"C",2,64);
CONDP=PeakBars(C,P)==0;SP=Cum(CONDP);
EP1=ValueWhen(CONDP,C,1);TP1=ValueWhen(CONDP,X,1);
EP2=ValueWhen(CONDP,C,2);TP2=ValueWhen(CONDP,X,2);
EP3=ValueWhen(CONDP,C,3);TP3=ValueWhen(CONDP,X,3);
EP4=ValueWhen(CONDP,C,4);TP4=ValueWhen(CONDP,X,4);
CONDT=TroughBars(C,P)==0;ST=Cum(CONDT);
ET1=ValueWhen(CONDT,C,1);TT1=ValueWhen(CONDT,X,1);
ET2=ValueWhen(CONDT,C,2);TT2=ValueWhen(CONDT,X,2);
ET3=ValueWhen(CONDT,C,3);TT3=ValueWhen(CONDT,X,3);
ET4=ValueWhen(CONDT,C,4);TT4=ValueWhen(CONDT,X,4);
ET5=ValueWhen(CONDT,C,5);TT5=ValueWhen(CONDT,X,5);
// EW definition
EW8=EP3>EP4 AND EP2>EP3 AND EP2>EP1 AND ET4>ET5 AND ET3>ET2 AND
ET2>ET1 AND ET3>ET4 AND ET4>ET5 AND CONDT;
COLOR=colorWhite;
PlotShapes(shapeDigit8*EW8,color);
G=Cum(CONDP OR CONDT);
GEW=SelectedValue(ValueWhen(EW8,G));
for(n=1;n<=9;n++)
{
PlotShapes((49-(2*n-(n%2)))*(G==GEW-n AND (n%2)*CONDP+(-1+n%2)
*CONDT),Color);
}
Plot(EW8,"",colorRed,2+styleOwnScale);
Plot(z,"",colorYellow,styleThick);
Filter=EW8;// explore for all quotations
AddColumn(C,"C");
GraphXSpace=8;
_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();



//Elliot Wave Oscillator
hBar = EMA(C,5)- EMA(C,35);
//Plot(hBar, _DEFAULT_NAME(),
//IIf(hBar>=0, ParamColor("Up Color", colorGreen), ParamColor("Down Color", colorRed)),
//ParamStyle( "Style", styleHistogram | styleThick, maskHistogram )
//);
Plot(hBar, _DEFAULT_NAME(),IIf(hBar>=0,  colorGreen, colorRed),styleOwnScale);


_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 ), styleCandle
| ParamStyle("Style") | GetPriceStyle() );
// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX
// are both trending down.

_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();


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();

_SECTION_BEGIN("LEMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 200, 1, 10 );
lema = EMA (Close,Periods)+ EMA((Close-EMA(Close,Periods)),Periods);
Plot( lEMA, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("ELLIOTT Fractals");
/*
The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
and higher than the two bars immediately following it.
The lows of the bars are NOT considered in determining the up fractal progression.

If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
then a total of six bars rather than the usual five bars will make up the progression.
The first High becomes the counting fractal. Reverse for 'down' fractals.

The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
*/
Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;

//TODO: More filtering: Show only troughs that are around atrough in trix(9).

PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);

PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);

Up = (Up5BarFractal OR Up6BarFractal);
Down = (Down5BarFractal OR Down6BarFractal);
//Removing false fractals:
DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));

LastHigh[0] = H[0];
LastLow[0] = L[0];

LastLowIndex = 0;
LastHighIndex = 0;
Valid = 0;
for (i=1; i < BarCount; i++)
{

LastHigh[i] = LastHigh[i-1];
LastLow[i] = LastLow[i-1];
if (Up[i])
{
Valid[i] = True;
if (DownSignal[i])
{
//Sequence of 2 Up Fractals. Validate only the higher one.
Valid[i] = H[i] >= H[LastHighIndex];
Valid[LastHighIndex] = H[LastHighIndex] > H[i];
}
LastHigh[i] = Max(H[i], H[LastHighIndex ]);
LastHighIndex = i;
}

if (Down[i])
{
Valid[i] = True;
if (UpSignal[i])
{
//Sequence of 2 Down Fractals. Validate only the lower one.
Valid[i] = L[i] <= L[LastLowIndex];
Valid[LastLowIndex] = L[LastLowIndex] < L[i];
}

LastLow[i] = Min(L[i], L[LastLowIndex]);
LastLowIndex = i;
}
}

TrixN = Trix(9);
TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
//TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
//TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));

//Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
//Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
//Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);

//PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);
//PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
Maxi = Up AND (ValidHigh OR ZeroValid);
Mini = Down AND (ValidLow OR ZeroValid);
PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
//Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
//Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);

/*
LastMaxi = 0;
LastMini = 0;
ElliotLines = 0;
State = 0;
for (i=1; i < BarCount; i++)
{
State[i] = State[i-1];
if (Maxi[i])
{
State[i] = 1;//down
}

if (Mini[i])
{
State[i] = 2;
}

}

PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
*/
//Line = LineArray( x0, y0, x1, y1, 1 );
//Plot( Line, "Trend line", colorBlue );

/*
Wave B
Usually 50% of Wave A
Should not exceed 75% of Wave A
Wave C
either 1 x Wave A
or 1.62 x Wave A
or 2.62 x Wave A
*/
function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
{

ALength = abs(startPrice - A); BLength = abs(A-B);
CLength = abs(B-C);

Ratio1 = BLength / CLength ;
Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
Cond2 = abs(Clength - ALength) < Delta OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;

return Cond1 AND Cond2;
}

function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
{
//Wave 2 should be beneath wave 1 start:
Cond1 = Two > StartPrice AND Two < One;
//Wave 4 - the same:
Cond2 = Four > Two AND Four < Three;
//Wave 5 should be <= wave 3
Cond3 = abs(Three-Two) >= abs(Five - Four);
//Wave 1 should be smaller than wave five, making wave 3 the biggest:
Cond4 = abs(StartPrice - One) < abs(Five - Four);
return Cond1 AND Cond2 AND Cond3 AND Cond4;
}
_SECTION_END();

_SECTION_BEGIN("Price1");
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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
one more

HTML:
_SECTION_BEGIN("Background");
    SetChartOptions(0,chartShowArrows|chartShowDates);
    SetChartBkColor(ParamColor("Outer panel",colorGrey40)); // color of outer border
    SetChartBkGradientFill( ParamColor("Inner panel upper",colorGrey40),ParamColor("Inner panel lower",colorBlack));
    tchoice=Param("Title Selection ",2,1,2,1);
 
Plot(C, "", IIf(O>=C, colorOrange, colorGreen), ParamStyle("Price Style",styleCandle, maskPrice));
 
//////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Fib Retracements");
    fibs = ParamToggle("Plot Fibs","Off|On",1);
    pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
    HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
    pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
    LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
    Back = Param ("Extend Left = 2",1,1,500,1);
    Fwd  = Param("Plot Forward", 0, 0, 500, 1);
    text = ParamToggle("Plot Text","Off|On",1);
    hts  = Param ("Text Shift", -33.5,-50,50,0.10);
    style =ParamStyle("Line Style",styleLine,styleNoLabel);
x = BarIndex();
pRp  = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp  = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;
 
function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
AND xSp0 > 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_END();
//////////////////////////////////////////////////////////////////
if (tchoice==1 )
{
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} -   {{INTERVAL}}      {{DATE}}    Open:  %g,    High:  %g,     Low:  %g,     Close:  %g     {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1   ) ) ));
}
//////////////////////////////////////////////////////////////////
if (tchoice==2 )
{
Title = EncodeColor(colorWhite)+  Date() + "   Tick = " + EncodeColor(5) + Interval()+
EncodeColor(colorWhite) + "     Open = " + EncodeColor(colorWhite) + O +
EncodeColor(colorWhite) + "     High = " + EncodeColor(5) + H +
EncodeColor(colorWhite) + "      Low = " + EncodeColor(colorRed) + L +
EncodeColor(colorWhite) + "     Close = " + EncodeColor(colorWhite) + C + "\n" +
EncodeColor( colorWhite) +"_______________"+"\n"+
EncodeColor( colorWhite)  + "424%   =  "    +   EncodeColor(25)+ e424 + " " +"\n"+
EncodeColor( colorWhite)  + "262%   =  "    +   EncodeColor(47)+ e262 + " " +"\n"+
EncodeColor( colorWhite)  + "200%   =  "    +   EncodeColor(47)+ e200 + " " +"\n"+
EncodeColor( colorWhite)  + "162%   =  "    +   EncodeColor(47)+ e162 + " " +"\n"+
EncodeColor( colorWhite)  + "127%   =  "    +   EncodeColor(47)+ e127 + " " +"\n"+
EncodeColor( colorYellow) + "  Res    =  "  +   EncodeColor(32)+ p100 + " " +"\n"+
EncodeColor( colorWhite)  + "  78%   =  "   +   EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite)  + "  62%   =  "   +   EncodeColor(43)+ r618 + " " +"\n"+
EncodeColor( colorWhite)  + "  50%   =  "   +   EncodeColor(41)+ r050 + " " +"\n"+
EncodeColor( colorWhite)  + "  38%   =  "   +   EncodeColor(44)+ r382 + " " +"\n"+
EncodeColor( colorWhite)  + "  23%   =  "   +   EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( colorYellow) + "  Sup   =   "  +   EncodeColor(34)+ p00 + " " ;
}
GraphXSpace=5;
 
SetChartOptions(1, chartShowDates);   // put dates at bottom of chart
 
pr = Param("Elliot Wave minimum % move", 2, 1, 100);
// Beginner Elliot Wave stuff
EWpk = PeakBars(H, pr, 1) == 0;
EWtr = TroughBars(L, pr, 1) == 0;
 
// Intermediate Elliot Wave stuff
zz = Zig(C, pr);
zzHi = Zig(H, pr);
zzLo = Zig(L, pr);
Avg = (zzHi+zzLo)/2;
 
// Advanced Elliot Wave stuff
RetroSuccessSecret = IIf(EWpk, zzHi, IIf(EWtr, zzLo, IIf(Avg > Ref(Avg,-1), H, L)));
EW = Zig(RetroSuccessSecret, pr);
 
// Plot on price chart
/*Plot(C, "Close", colorBlack, styleCandle);*/
Plot(EW, "EW", colorWhite, styleLine);
 
// Plot buy and sell arrows
Buy = TroughBars(EW, pr, 1) == 0;
Sell = PeakBars(EW, pr, 1) ==0;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
 
AlertIf( Buy , "SOUND C:\\Windows\\Media\\Notify.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Tada.wav", "Audio alert", 2 );
 
_SECTION_BEGIN("Elliot Fractals");
 
/*
The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
and higher than the two bars immediately following it.
The lows of the bars are NOT considered in determining the up fractal progression.
 
If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
then a total of six bars rather than the usual five bars will make up the progression.
The first High becomes the counting fractal. Reverse for 'down' fractals.
 
The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
*/
Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;
 
//TODO: More filtering: Show only troughs that are around atrough in trix(9).
 
PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
 
PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
 
Up = (Up5BarFractal OR Up6BarFractal);
Down = (Down5BarFractal OR Down6BarFractal);
//Removing false fractals:
DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));
 
LastHigh[0] = H[0];
LastLow[0] = L[0];
 
LastLowIndex = 0;
LastHighIndex = 0;
Valid = 0;
for (i=1; i < BarCount; i++)
{
 
    LastHigh[i] = LastHigh[i-1];
    LastLow[i] = LastLow[i-1];
    if (Up[i])
    {                              
        Valid[i] = True;
        if (DownSignal[i])
        {
            //Sequence of 2 Up Fractals. Validate only the higher one.
            Valid[i] = H[i] >= H[LastHighIndex];
            Valid[LastHighIndex] = H[LastHighIndex] >  H[i];
        }
        LastHigh[i] = Max(H[i], H[LastHighIndex ]);
        LastHighIndex = i; 
    }
 
    if (Down[i])
    {  
        Valid[i] = True;
        if (UpSignal[i])
        {
            //Sequence of 2 Down Fractals. Validate only the lower one.
            Valid[i] = L[i] <= L[LastLowIndex];
            Valid[LastLowIndex] = L[LastLowIndex] <  L[i];
        }
     
        LastLow[i] = Min(L[i], L[LastLowIndex]);
        LastLowIndex = i;      
    }  
}
 
TrixN = Trix(9);
TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
//TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
//TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));
 
//Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
//Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
//Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);
 
//PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);
//PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
Maxi = Up AND (ValidHigh OR ZeroValid);
Mini = Down AND (ValidLow OR ZeroValid);
PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
//Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
//Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);
 
/*
LastMaxi = 0;
LastMini = 0;
ElliotLines = 0;
State = 0;
for (i=1; i < BarCount; i++)
{
    State[i] = State[i-1];
    if (Maxi[i])
    {      
        State[i] = 1;//down
    }
 
    if (Mini[i])
    {      
        State[i] = 2;
    }
 
}
 
PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
*/
//Line = LineArray( x0, y0, x1, y1, 1 );
//Plot( Line, "Trend line", colorBlue );
 
/*
Wave B
Usually 50% of Wave A
Should not exceed 75% of Wave A
Wave C
either 1 x Wave A
or 1.62 x Wave A
or 2.62 x Wave A
*/
function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
{
     
    ALength = abs(startPrice - A);  BLength = abs(A-B);
    CLength = abs(B-C);
 
    Ratio1 = BLength  / CLength ;
    Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
    Cond2 = abs(Clength - ALength) < Delta  OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;
     
    return Cond1 AND Cond2;
}
 
function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
{
    //Wave 2 should be beneath wave 1 start:
    Cond1 = Two > StartPrice AND Two < One;
    //Wave 4 - the same:
    Cond2 = Four > Two AND Four < Three;
    //Wave 5 should be <= wave 3
    Cond3 = abs(Three-Two) >= abs(Five - Four);
    //Wave 1 should be smaller than wave five, making wave 3 the biggest:
    Cond4 = abs(StartPrice - One) < abs(Five - Four);
    return Cond1 AND Cond2 AND Cond3 AND Cond4;
}
_SECTION_END();
 
 
_SECTION_BEGIN("Ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();
 
 
Plot( 1, /*efines the height of the ribbon in percent of pane width */"ribbon",
 IIf( uptrend, colorGreen, IIf( downtrend, colorRed,IIf(Signal()<MACD(), colorYellow, 0 ))), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -1, 100 );
_SECTION_END();
 
 
_SECTION_BEGIN("Price With Regression Channel");
 
 
//  Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below
 
P = ParamField("Price field",-1);
Daysback = Param("Period for Liner Regression Line",21,1,240,1);
shift = Param("Look back period",0,0,240,1);
 
 
//  =============================== Math Formula =============================================================
 
x = Cum(1);
lastx = LastValue( x ) - shift;
aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );
 
 
// ==================Plot the Linear Regression Line ==========================================================
 
 
LRColor = ParamColor("LR Color", colorCycle );
LRStyle = ParamStyle("LR Style");
 
LRLine =  IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );
Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); //  styleDots );
 
// ==========================  Plot 1st SD Channel ===============================================================
 
SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);
SD = SDP/2;
 
width = LastValue( Ref(SD*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;
 
SDColor = ParamColor("SD Color", colorCycle );
SDStyle = ParamStyle("SD Style");
 
Plot( SDU , "Upper Lin Reg", SDColor,SDStyle );
Plot( SDL , "Lower Lin Reg", SDColor,SDStyle );
 
//  ==========================  Plot 2d SD Channel ===============================================================
 
SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);
SD2 = SDP2/2;
 
width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;
 
SDColor2 = ParamColor("2 SD Color", colorCycle );
SDStyle2 = ParamStyle("2 SD Style");
 
Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2 );
Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 );
 
// ============================ End Indicator Code ==============================================================
 
_SECTION_END();
 
 
_SECTION_BEGIN("trailing stop atr");
function vstop_func(tr)
{
trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];
 
if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = C[ i ] + tr[ i ];
}
}
return trailArray;
}
 
per = Param("per",20, 5, 150, 1);
mult = Param("mult",0.5, 0.5, 4, 0.05);
tr = mult * ATR(per);
trailArray = vstop_func(tr);
//trailArray = Ref(trailArray,-1);
 
//LISTING 1: Zero-lag moving average
 
function ZeroLagMA( data, periods )
{
EMA1 = EMA( data, periods );
EMA2 = EMA( EMA1, periods );
Diff = EMA1 - EMA2;
return EMA1 + Diff;
}
 
Periods = Param("Periods", 20, 2, 100 );
 
//Plot( ZeroLagMA( Close, Periods ), "ZeroLagMA-"+Periods, colorYellow, styleDashed  );
 
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);
 
_SECTION_BEGIN("ProjHL");
//Function pembulatan
function bulat(Lo)
{
 return (
IIf(Lo<= 200,round(Lo/1)*1,
IIf(Lo<= 500,round(Lo/5)*5,
IIf(Lo<=2000,round(Lo/10)*10,
IIf(Lo<=5000,round(Lo/25)*25,
IIf(Lo> 5000,round(Lo/50)*50,0)))))
);
}
 
GfxSetOverlayMode(0);
GfxSelectFont("Arial",9, 700);
GfxSetTextColor( colorRose );
GfxSetBkMode(0); // transparent
GfxTextOut("PivHL   = " + (H+L)/2, 250, 45);
GfxTextOut("Diff    = " + (C-((H+L)/2)), 350, 45);
GfxSetTextColor( colorYellow );
GfxTextOut("TStop   = " + bulat(TrailStop), 450, 45);
GfxTextOut("TPrc   = " + bulat(ProfitTaker), 550, 45);
 
 
 
// PIVOT Calculation
p = bulat( H+ L + C )/3;
GfxSetTextColor( colorLightOrange );
GfxTextOut("Pivot    = " +bulat(p), 350, 60);
 
 
rph1=(H+C+2*L)/2-L;
rph2=(2*H+L+C)/2-L;
rph3=(H+L+2*C)/2-L;
rpl1=(H+C+2*L)/2-H;
rpl2=(2*H+L+C)/2-H;
rpl3=(H+L+2*C)/2-H;
rph=IIf((C<O),rph1,IIf((C>O),rph2,IIf((C==O),rph3,0)));
rpl=IIf((C<O),rpl1,IIf((C>O),rpl2,IIf((C==O),rpl3,0)));
GfxSetTextColor( colorBrightGreen );
GfxTextOut("Proj-H   = " + bulat(rph), 250, 60);
GfxSetTextColor( colorCustom12 );
GfxTextOut("Proj-L   = " + bulat(rpl), 450, 60);
GfxSetTextColor( colorOrange );
GfxTextOut("Trail   = " + bulat(trailArray), 550, 60);
 
//2 Week New High-New Low
HI = High > Ref(HHV(High,10),-1);
LI = Low < Ref(LLV(Low,10),-1);
HIV1= Ref(HHV(High,10),-1);
LIV1=Ref(LLV(Low,10),-1);
Variable = WriteIf(H>HIV1,"High",WriteIf(L<LIV1,"Low","Neutral"));
GfxSetTextColor( colorSkyblue );
GfxTextOut("2 WHL: " + HIV1+" : "+LIV1+  "    " +  Variable,290,75);
_SECTION_END();
 

MANISH_DAMANI

Well-Known Member
#45
Re: Which combination of indicators helps detect an impnding upmove or downmove relia

chk mif it works for u

HTML:
// ELLIOT WAVE
//-- Script Start -------
Option = ParamToggle("Insert To", "Price Chart|Indicator");

pr=Param("Elliot Wave minimum % move",2, 0.001,100);

//{ 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;

//{ Advanced Elliot Wave stuff }
RetroSuccessSecret=IIf(EWpk,zzHi,
IIf(EWtr,zzLo,IIf(Avg>Ref(Avg,-1),H,L)));
EW=Zig(RetroSuccessSecret,pr);


_SECTION_BEGIN("Colour Bar Chart");
outsidebar = H > Ref( H, -1 ) AND L < Ref( L, -1 );
insidebar = H < Ref( H, -1 ) AND L > Ref( L, -1 );
upbar = H > Ref( H, -1 ) AND L >= Ref( L, -1 );
downbar = L < Ref( L, -1 ) AND H <= Ref( H, -1 );

barcolor = IIf(outsidebar, colorBlue,
IIf(downbar, colorRed,
IIf(upbar, colorGreen,
IIf(insidebar, 11, colorBlack)
)
)
);

Title = Name() + "\\c" + barcolor + " - Color Bar Chart : " +
WriteIf(Outsidebar, "Outside Bar",
WriteIf(insidebar, "Inside Bar",
WriteIf(upbar, "Up Bar",
WriteIf(downbar, "Down Bar", "Neutral Bar")
)
)
);
Plot(Close, Title, barcolor, styleThick + styleBar);
//{ Plot on price chart }
if (Option==0)
Plot(EW, "EW", ParamColor("Color", colorBrown), ParamStyle("Style", styleNoLabel|styleThick));
else
{

//{ Buy/Sell Elliot Wave stuff }
EWbuy=TroughBars(EW,pr)==0;
EWsell=PeakBars(EW,pr)==0;

//{ Plot on own window }
Plot(EWbuy-EWsell, "EW2", ParamColor("Color", colorRed), ParamStyle("Style", styleNoLabel|styleThick));

}
//-- Script End -------



_SECTION_END();

_SECTION_BEGIN("Background");
SetChartOptions(0,chartShowArrows|chartShowDates);
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g
(%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1
)));
}

SetChartBkColor(ParamColor("Outer panel color ",colorBlack)); // color of outer border
SetChartBkGradientFill( ParamColor("Inner panel color upper half",colorDarkTeal),
ParamColor("Inner panel color lower half",colorBlack)//color of inner panel
,ParamColor("behind Text Color", colorYellow));
_SECTION_END();



//Elliot Wave [Single Loop]
_SECTION_BEGIN("Elliotwave");
X=BarIndex();
p=Param("p",0.50,0.5,30,0.1);
z=Zig(C,p);Plot(C,"C",2,64);
CONDP=PeakBars(C,P)==0;SP=Cum(CONDP);
EP1=ValueWhen(CONDP,C,1);TP1=ValueWhen(CONDP,X,1);
EP2=ValueWhen(CONDP,C,2);TP2=ValueWhen(CONDP,X,2);
EP3=ValueWhen(CONDP,C,3);TP3=ValueWhen(CONDP,X,3);
EP4=ValueWhen(CONDP,C,4);TP4=ValueWhen(CONDP,X,4);
CONDT=TroughBars(C,P)==0;ST=Cum(CONDT);
ET1=ValueWhen(CONDT,C,1);TT1=ValueWhen(CONDT,X,1);
ET2=ValueWhen(CONDT,C,2);TT2=ValueWhen(CONDT,X,2);
ET3=ValueWhen(CONDT,C,3);TT3=ValueWhen(CONDT,X,3);
ET4=ValueWhen(CONDT,C,4);TT4=ValueWhen(CONDT,X,4);
ET5=ValueWhen(CONDT,C,5);TT5=ValueWhen(CONDT,X,5);
// EW definition
EW8=EP3>EP4 AND EP2>EP3 AND EP2>EP1 AND ET4>ET5 AND ET3>ET2 AND
ET2>ET1 AND ET3>ET4 AND ET4>ET5 AND CONDT;
COLOR=colorWhite;
PlotShapes(shapeDigit8*EW8,color);
G=Cum(CONDP OR CONDT);
GEW=SelectedValue(ValueWhen(EW8,G));
for(n=1;n<=9;n++)
{
PlotShapes((49-(2*n-(n%2)))*(G==GEW-n AND (n%2)*CONDP+(-1+n%2)
*CONDT),Color);
}
Plot(EW8,"",colorRed,2+styleOwnScale);
Plot(z,"",colorYellow,styleThick);
Filter=EW8;// explore for all quotations
AddColumn(C,"C");
GraphXSpace=8;
_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();



//Elliot Wave Oscillator
hBar = EMA(C,5)- EMA(C,35);
//Plot(hBar, _DEFAULT_NAME(),
//IIf(hBar>=0, ParamColor("Up Color", colorGreen), ParamColor("Down Color", colorRed)),
//ParamStyle( "Style", styleHistogram | styleThick, maskHistogram )
//);
Plot(hBar, _DEFAULT_NAME(),IIf(hBar>=0,  colorGreen, colorRed),styleOwnScale);


_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 ), styleCandle
| ParamStyle("Style") | GetPriceStyle() );
// Paste the code below to your price chart somewhere and green ribbon means both
// both MACD and ADX trending up so if the red ribbon shows up the MACD and the ADX
// are both trending down.

_SECTION_BEGIN("trending ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();


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();

_SECTION_BEGIN("LEMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 200, 1, 10 );
lema = EMA (Close,Periods)+ EMA((Close-EMA(Close,Periods)),Periods);
Plot( lEMA, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("ELLIOTT Fractals");
/*
The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
and higher than the two bars immediately following it.
The lows of the bars are NOT considered in determining the up fractal progression.

If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
then a total of six bars rather than the usual five bars will make up the progression.
The first High becomes the counting fractal. Reverse for 'down' fractals.

The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
*/
Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;

//TODO: More filtering: Show only troughs that are around atrough in trix(9).

PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);

PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);

Up = (Up5BarFractal OR Up6BarFractal);
Down = (Down5BarFractal OR Down6BarFractal);
//Removing false fractals:
DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));

LastHigh[0] = H[0];
LastLow[0] = L[0];

LastLowIndex = 0;
LastHighIndex = 0;
Valid = 0;
for (i=1; i < BarCount; i++)
{

LastHigh[i] = LastHigh[i-1];
LastLow[i] = LastLow[i-1];
if (Up[i])
{
Valid[i] = True;
if (DownSignal[i])
{
//Sequence of 2 Up Fractals. Validate only the higher one.
Valid[i] = H[i] >= H[LastHighIndex];
Valid[LastHighIndex] = H[LastHighIndex] > H[i];
}
LastHigh[i] = Max(H[i], H[LastHighIndex ]);
LastHighIndex = i;
}

if (Down[i])
{
Valid[i] = True;
if (UpSignal[i])
{
//Sequence of 2 Down Fractals. Validate only the lower one.
Valid[i] = L[i] <= L[LastLowIndex];
Valid[LastLowIndex] = L[LastLowIndex] < L[i];
}

LastLow[i] = Min(L[i], L[LastLowIndex]);
LastLowIndex = i;
}
}

TrixN = Trix(9);
TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
//TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
//TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));

//Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
//Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
//Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);

//PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);
//PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
Maxi = Up AND (ValidHigh OR ZeroValid);
Mini = Down AND (ValidLow OR ZeroValid);
PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
//Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
//Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);

/*
LastMaxi = 0;
LastMini = 0;
ElliotLines = 0;
State = 0;
for (i=1; i < BarCount; i++)
{
State[i] = State[i-1];
if (Maxi[i])
{
State[i] = 1;//down
}

if (Mini[i])
{
State[i] = 2;
}

}

PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
*/
//Line = LineArray( x0, y0, x1, y1, 1 );
//Plot( Line, "Trend line", colorBlue );

/*
Wave B
Usually 50% of Wave A
Should not exceed 75% of Wave A
Wave C
either 1 x Wave A
or 1.62 x Wave A
or 2.62 x Wave A
*/
function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
{

ALength = abs(startPrice - A); BLength = abs(A-B);
CLength = abs(B-C);

Ratio1 = BLength / CLength ;
Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
Cond2 = abs(Clength - ALength) < Delta OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;

return Cond1 AND Cond2;
}

function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
{
//Wave 2 should be beneath wave 1 start:
Cond1 = Two > StartPrice AND Two < One;
//Wave 4 - the same:
Cond2 = Four > Two AND Four < Three;
//Wave 5 should be <= wave 3
Cond3 = abs(Three-Two) >= abs(Five - Four);
//Wave 1 should be smaller than wave five, making wave 3 the biggest:
Cond4 = abs(StartPrice - One) < abs(Five - Four);
return Cond1 AND Cond2 AND Cond3 AND Cond4;
}
_SECTION_END();

_SECTION_BEGIN("Price1");
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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
one more

HTML:
_SECTION_BEGIN("Background");
    SetChartOptions(0,chartShowArrows|chartShowDates);
    SetChartBkColor(ParamColor("Outer panel",colorGrey40)); // color of outer border
    SetChartBkGradientFill( ParamColor("Inner panel upper",colorGrey40),ParamColor("Inner panel lower",colorBlack));
    tchoice=Param("Title Selection ",2,1,2,1);
 
Plot(C, "", IIf(O>=C, colorOrange, colorGreen), ParamStyle("Price Style",styleCandle, maskPrice));
 
//////////////////////////////////////////////////////////////////
_SECTION_BEGIN("Fib Retracements");
    fibs = ParamToggle("Plot Fibs","Off|On",1);
    pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
    HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
    pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
    LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
    Back = Param ("Extend Left = 2",1,1,500,1);
    Fwd  = Param("Plot Forward", 0, 0, 500, 1);
    text = ParamToggle("Plot Text","Off|On",1);
    hts  = Param ("Text Shift", -33.5,-50,50,0.10);
    style =ParamStyle("Line Style",styleLine,styleNoLabel);
x = BarIndex();
pRp  = PeakBars( H, pctH, 1) == 0;
yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
pSp  = TroughBars( L, pctL, 1) == 0;
ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
Delta = yRp0 - ySp0;
 
function fib(ret)
{
retval = (Delta * ret);
Fibval = IIf(ret < 1.0
AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
AND xSp0 > 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_END();
//////////////////////////////////////////////////////////////////
if (tchoice==1 )
{
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} -   {{INTERVAL}}      {{DATE}}    Open:  %g,    High:  %g,     Low:  %g,     Close:  %g     {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1   ) ) ));
}
//////////////////////////////////////////////////////////////////
if (tchoice==2 )
{
Title = EncodeColor(colorWhite)+  Date() + "   Tick = " + EncodeColor(5) + Interval()+
EncodeColor(colorWhite) + "     Open = " + EncodeColor(colorWhite) + O +
EncodeColor(colorWhite) + "     High = " + EncodeColor(5) + H +
EncodeColor(colorWhite) + "      Low = " + EncodeColor(colorRed) + L +
EncodeColor(colorWhite) + "     Close = " + EncodeColor(colorWhite) + C + "\n" +
EncodeColor( colorWhite) +"_______________"+"\n"+
EncodeColor( colorWhite)  + "424%   =  "    +   EncodeColor(25)+ e424 + " " +"\n"+
EncodeColor( colorWhite)  + "262%   =  "    +   EncodeColor(47)+ e262 + " " +"\n"+
EncodeColor( colorWhite)  + "200%   =  "    +   EncodeColor(47)+ e200 + " " +"\n"+
EncodeColor( colorWhite)  + "162%   =  "    +   EncodeColor(47)+ e162 + " " +"\n"+
EncodeColor( colorWhite)  + "127%   =  "    +   EncodeColor(47)+ e127 + " " +"\n"+
EncodeColor( colorYellow) + "  Res    =  "  +   EncodeColor(32)+ p100 + " " +"\n"+
EncodeColor( colorWhite)  + "  78%   =  "   +   EncodeColor(42)+ r786 + " " +"\n"+
EncodeColor( colorWhite)  + "  62%   =  "   +   EncodeColor(43)+ r618 + " " +"\n"+
EncodeColor( colorWhite)  + "  50%   =  "   +   EncodeColor(41)+ r050 + " " +"\n"+
EncodeColor( colorWhite)  + "  38%   =  "   +   EncodeColor(44)+ r382 + " " +"\n"+
EncodeColor( colorWhite)  + "  23%   =  "   +   EncodeColor(45)+ r236+ " " +"\n"+
EncodeColor( colorYellow) + "  Sup   =   "  +   EncodeColor(34)+ p00 + " " ;
}
GraphXSpace=5;
 
SetChartOptions(1, chartShowDates);   // put dates at bottom of chart
 
pr = Param("Elliot Wave minimum % move", 2, 1, 100);
// Beginner Elliot Wave stuff
EWpk = PeakBars(H, pr, 1) == 0;
EWtr = TroughBars(L, pr, 1) == 0;
 
// Intermediate Elliot Wave stuff
zz = Zig(C, pr);
zzHi = Zig(H, pr);
zzLo = Zig(L, pr);
Avg = (zzHi+zzLo)/2;
 
// Advanced Elliot Wave stuff
RetroSuccessSecret = IIf(EWpk, zzHi, IIf(EWtr, zzLo, IIf(Avg > Ref(Avg,-1), H, L)));
EW = Zig(RetroSuccessSecret, pr);
 
// Plot on price chart
/*Plot(C, "Close", colorBlack, styleCandle);*/
Plot(EW, "EW", colorWhite, styleLine);
 
// Plot buy and sell arrows
Buy = TroughBars(EW, pr, 1) == 0;
Sell = PeakBars(EW, pr, 1) ==0;
Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
 
AlertIf( Buy , "SOUND C:\\Windows\\Media\\Notify.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Tada.wav", "Audio alert", 2 );
 
_SECTION_BEGIN("Elliot Fractals");
 
/*
The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
and higher than the two bars immediately following it.
The lows of the bars are NOT considered in determining the up fractal progression.
 
If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
then a total of six bars rather than the usual five bars will make up the progression.
The first High becomes the counting fractal. Reverse for 'down' fractals.
 
The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
*/
Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;
 
//TODO: More filtering: Show only troughs that are around atrough in trix(9).
 
PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
 
PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
 
Up = (Up5BarFractal OR Up6BarFractal);
Down = (Down5BarFractal OR Down6BarFractal);
//Removing false fractals:
DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));
 
LastHigh[0] = H[0];
LastLow[0] = L[0];
 
LastLowIndex = 0;
LastHighIndex = 0;
Valid = 0;
for (i=1; i < BarCount; i++)
{
 
    LastHigh[i] = LastHigh[i-1];
    LastLow[i] = LastLow[i-1];
    if (Up[i])
    {                              
        Valid[i] = True;
        if (DownSignal[i])
        {
            //Sequence of 2 Up Fractals. Validate only the higher one.
            Valid[i] = H[i] >= H[LastHighIndex];
            Valid[LastHighIndex] = H[LastHighIndex] >  H[i];
        }
        LastHigh[i] = Max(H[i], H[LastHighIndex ]);
        LastHighIndex = i; 
    }
 
    if (Down[i])
    {  
        Valid[i] = True;
        if (UpSignal[i])
        {
            //Sequence of 2 Down Fractals. Validate only the lower one.
            Valid[i] = L[i] <= L[LastLowIndex];
            Valid[LastLowIndex] = L[LastLowIndex] <  L[i];
        }
     
        LastLow[i] = Min(L[i], L[LastLowIndex]);
        LastLowIndex = i;      
    }  
}
 
TrixN = Trix(9);
TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
//TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
//TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));
 
//Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
//Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
//Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);
 
//PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);
//PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
Maxi = Up AND (ValidHigh OR ZeroValid);
Mini = Down AND (ValidLow OR ZeroValid);
PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
//Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
//Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);
 
/*
LastMaxi = 0;
LastMini = 0;
ElliotLines = 0;
State = 0;
for (i=1; i < BarCount; i++)
{
    State[i] = State[i-1];
    if (Maxi[i])
    {      
        State[i] = 1;//down
    }
 
    if (Mini[i])
    {      
        State[i] = 2;
    }
 
}
 
PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
*/
//Line = LineArray( x0, y0, x1, y1, 1 );
//Plot( Line, "Trend line", colorBlue );
 
/*
Wave B
Usually 50% of Wave A
Should not exceed 75% of Wave A
Wave C
either 1 x Wave A
or 1.62 x Wave A
or 2.62 x Wave A
*/
function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
{
     
    ALength = abs(startPrice - A);  BLength = abs(A-B);
    CLength = abs(B-C);
 
    Ratio1 = BLength  / CLength ;
    Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
    Cond2 = abs(Clength - ALength) < Delta  OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;
     
    return Cond1 AND Cond2;
}
 
function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
{
    //Wave 2 should be beneath wave 1 start:
    Cond1 = Two > StartPrice AND Two < One;
    //Wave 4 - the same:
    Cond2 = Four > Two AND Four < Three;
    //Wave 5 should be <= wave 3
    Cond3 = abs(Three-Two) >= abs(Five - Four);
    //Wave 1 should be smaller than wave five, making wave 3 the biggest:
    Cond4 = abs(StartPrice - One) < abs(Five - Four);
    return Cond1 AND Cond2 AND Cond3 AND Cond4;
}
_SECTION_END();
 
 
_SECTION_BEGIN("Ribbon");
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();
 
 
Plot( 1, /*efines the height of the ribbon in percent of pane width */"ribbon",
 IIf( uptrend, colorGreen, IIf( downtrend, colorRed,IIf(Signal()<MACD(), colorYellow, 0 ))), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -1, 100 );
_SECTION_END();
 
 
_SECTION_BEGIN("Price With Regression Channel");
 
 
//  Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below
 
P = ParamField("Price field",-1);
Daysback = Param("Period for Liner Regression Line",21,1,240,1);
shift = Param("Look back period",0,0,240,1);
 
 
//  =============================== Math Formula =============================================================
 
x = Cum(1);
lastx = LastValue( x ) - shift;
aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );
 
 
// ==================Plot the Linear Regression Line ==========================================================
 
 
LRColor = ParamColor("LR Color", colorCycle );
LRStyle = ParamStyle("LR Style");
 
LRLine =  IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );
Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); //  styleDots );
 
// ==========================  Plot 1st SD Channel ===============================================================
 
SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);
SD = SDP/2;
 
width = LastValue( Ref(SD*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;
 
SDColor = ParamColor("SD Color", colorCycle );
SDStyle = ParamStyle("SD Style");
 
Plot( SDU , "Upper Lin Reg", SDColor,SDStyle );
Plot( SDL , "Lower Lin Reg", SDColor,SDStyle );
 
//  ==========================  Plot 2d SD Channel ===============================================================
 
SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);
SD2 = SDP2/2;
 
width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) );   // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET 
SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;
 
SDColor2 = ParamColor("2 SD Color", colorCycle );
SDStyle2 = ParamStyle("2 SD Style");
 
Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2 );
Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 );
 
// ============================ End Indicator Code ==============================================================
 
_SECTION_END();
 
 
_SECTION_BEGIN("trailing stop atr");
function vstop_func(tr)
{
trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];
 
if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = C[ i ] + tr[ i ];
}
}
return trailArray;
}
 
per = Param("per",20, 5, 150, 1);
mult = Param("mult",0.5, 0.5, 4, 0.05);
tr = mult * ATR(per);
trailArray = vstop_func(tr);
//trailArray = Ref(trailArray,-1);
 
//LISTING 1: Zero-lag moving average
 
function ZeroLagMA( data, periods )
{
EMA1 = EMA( data, periods );
EMA2 = EMA( EMA1, periods );
Diff = EMA1 - EMA2;
return EMA1 + Diff;
}
 
Periods = Param("Periods", 20, 2, 100 );
 
//Plot( ZeroLagMA( Close, Periods ), "ZeroLagMA-"+Periods, colorYellow, styleDashed  );
 
TrailStop = HHV( C - 2 * ATR(10), 15 );
ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);
 
_SECTION_BEGIN("ProjHL");
//Function pembulatan
function bulat(Lo)
{
 return (
IIf(Lo<= 200,round(Lo/1)*1,
IIf(Lo<= 500,round(Lo/5)*5,
IIf(Lo<=2000,round(Lo/10)*10,
IIf(Lo<=5000,round(Lo/25)*25,
IIf(Lo> 5000,round(Lo/50)*50,0)))))
);
}
 
GfxSetOverlayMode(0);
GfxSelectFont("Arial",9, 700);
GfxSetTextColor( colorRose );
GfxSetBkMode(0); // transparent
GfxTextOut("PivHL   = " + (H+L)/2, 250, 45);
GfxTextOut("Diff    = " + (C-((H+L)/2)), 350, 45);
GfxSetTextColor( colorYellow );
GfxTextOut("TStop   = " + bulat(TrailStop), 450, 45);
GfxTextOut("TPrc   = " + bulat(ProfitTaker), 550, 45);
 
 
 
// PIVOT Calculation
p = bulat( H+ L + C )/3;
GfxSetTextColor( colorLightOrange );
GfxTextOut("Pivot    = " +bulat(p), 350, 60);
 
 
rph1=(H+C+2*L)/2-L;
rph2=(2*H+L+C)/2-L;
rph3=(H+L+2*C)/2-L;
rpl1=(H+C+2*L)/2-H;
rpl2=(2*H+L+C)/2-H;
rpl3=(H+L+2*C)/2-H;
rph=IIf((C<O),rph1,IIf((C>O),rph2,IIf((C==O),rph3,0)));
rpl=IIf((C<O),rpl1,IIf((C>O),rpl2,IIf((C==O),rpl3,0)));
GfxSetTextColor( colorBrightGreen );
GfxTextOut("Proj-H   = " + bulat(rph), 250, 60);
GfxSetTextColor( colorCustom12 );
GfxTextOut("Proj-L   = " + bulat(rpl), 450, 60);
GfxSetTextColor( colorOrange );
GfxTextOut("Trail   = " + bulat(trailArray), 550, 60);
 
//2 Week New High-New Low
HI = High > Ref(HHV(High,10),-1);
LI = Low < Ref(LLV(Low,10),-1);
HIV1= Ref(HHV(High,10),-1);
LIV1=Ref(LLV(Low,10),-1);
Variable = WriteIf(H>HIV1,"High",WriteIf(L<LIV1,"Low","Neutral"));
GfxSetTextColor( colorSkyblue );
GfxTextOut("2 WHL: " + HIV1+" : "+LIV1+  "    " +  Variable,290,75);
_SECTION_END();
NICE effort but not showing wave count, sub wave count etc. I hope you understand what I mean ?:):thumb:
 

johnnypareek

Well-Known Member
#46
Re: Which combination of indicators helps detect an impnding upmove or downmove relia

"The security price has set a new 14-day high while the RSI has not. This is a bearish divergence.",
WriteIf( vrsi >= HHV( vrsi, 14 ) AND Close < HHV( Close, 14 ),
"The RSI has set a new 14-day high while the security price has not. This is a bullish divergence.",
WriteIf( Close <= LLV( Close, 14 ) AND vrsi > LLV( vrsi, 14 ),
"The security price has set a new 14-day low while the RSI has not. This is a bullish divergence.",
WriteIf( vrsi <= LLV( vrsi, 14) AND Close > LLV(Close,14),
"The RSI has set a new 14-day low while the security price has not. This is a bearish divergence.",
"The RSI and price are not diverging." ) ) ) ));

printf("\n\nDivergence:\n");
temp = Trough(Low, 2, 1) < 0.96 * Ref( Trough(Low, 2, 1), -1) AND ValueWhen( Trough(Low, 2, 1) != Ref( Trough(Low, 2, 1), -1 ), MACD(), 1 ) >= 0.90 * ValueWhen( Trough( Low, 2, 1) != Ref( Trough( Low, 2, 1), -1 ), MACD(), 2 ) AND MACD() < 0;

temp2= Peak( High,2, 1) > 1.04 * Ref( Peak( High, 2, 1), -1) AND ValueWhen( Peak( High, 2, 1) != Ref( Peak( High, 2, 1), -1 ), MACD(), 1 ) <= 0.90 * ValueWhen( Peak( High, 2, 1) != Ref( Peak( High, 2, 1), -1 ), MACD(), 2 ) AND MACD() > 0;

printf(WriteIf( HHV( temp, 5 ) == 1,"A bullish divergence occurred " + WriteVal( BarsSince( temp ), 1.0 ) +
" period(s) ago. Wait for upward price movement for confirmation before considering any long positions.",
WriteIf( HHV( temp2,5) == 1,
"A bearish divergence occurred " +
WriteVal( BarsSince( temp2 ), 1.0 ) +
" period(s) ago. Wait for downward price movement for confirmation before considering any short positions.",
"There have been no divergence signals within the last 5 periods." ) ));

Is it possible to make commentary for divergence like macd and rsi for stochastic also

don't know will it work

HTML:
_SECTION_BEGIN(" commentary");

Buy=Cross( StochK(), StochD() AND StochK()<30 );
Sell = Cross( StochD(),StochK() ) AND StochK()>70 );

"Review of " + FullName() + " (" + Name() + ")" + "\nas of " + Date();


"\nCurrent Statistics\n";
"Close: " + WriteVal(Close);
"Change: " + WriteVal(Close - Ref( Close, -1 ) ) ;
"MACD Value: " + WriteVal(StochK());
"Signal Line: " + WriteVal(StochD());

"\nThe %K %D can provide buy/sell indications in three ways, signal line crossovers, overbought/oversold conditions, and divergences.\n";

"Crossovers:\n";
"Currently the %K%D is "+
WriteIf(StochK() >StochD(),"bullish","bearish")+
" since it is trading "+
WriteIf(StochK() >StochD(),"above","below")+
" its signal line.";


"The%k %Dcrossed "+
WriteIf(StochK() >StochD(),"above","below")+
" its signal line "+
WriteVal( Min( BarsSince( Cross( StochK(),StochD() )), BarsSince( Cross( StochD(),StochK()))), 0.0)+
" period(s) ago.";

bars=LastValue(Min( BarsSince( Cross( StochK(),StochD() )), BarsSince( Cross(  StochD(),StochK())) ));

prevclose=Ref(Close,-bars);

"Since the %K crossed %D, "+
Name()+"'s price has "+
WriteIf(Close>prevclose,"increased ","decreased ")+
WriteVal(100*(Close-prevclose)/prevclose) + "%";

"And has ranged from a high of "+
WriteVal(HHV(High,bars+1),6.3)+
" to a low of "+
WriteVal(LLV(Low,bars+1),6.3);

"\nOverbought/Oversold\n";
Osc = OscP( 12, 26 );
Osc1 = Ref( Osc, -1 );
Osc5 = Ref( Osc, -5 );

WriteIf( StochD() <= 20 ),
"The %K is in an oversold range. Prices may continue to move lower for some time.  Wait for prices to move higher before considering any long positions.", 
WriteIf( StochD() >= 80 ), 
"The %K%D is in an overbought range.  Prices may continue to move higher for some time.  Wait for prices to move lower before considering any short positions.", 
"The %K%D  is not in an Overbought/Oversold range."));
 

MANISH_DAMANI

Well-Known Member
#48
Re: Which combination of indicators helps detect an impnding upmove or downmove relia

don't know will it work

HTML:
_SECTION_BEGIN(" commentary");

Buy=Cross( StochK(), StochD() AND StochK()<30 );
Sell = Cross( StochD(),StochK() ) AND StochK()>70 );

"Review of " + FullName() + " (" + Name() + ")" + "\nas of " + Date();


"\nCurrent Statistics\n";
"Close: " + WriteVal(Close);
"Change: " + WriteVal(Close - Ref( Close, -1 ) ) ;
"MACD Value: " + WriteVal(StochK());
"Signal Line: " + WriteVal(StochD());

"\nThe %K %D can provide buy/sell indications in three ways, signal line crossovers, overbought/oversold conditions, and divergences.\n";

"Crossovers:\n";
"Currently the %K%D is "+
WriteIf(StochK() >StochD(),"bullish","bearish")+
" since it is trading "+
WriteIf(StochK() >StochD(),"above","below")+
" its signal line.";


"The%k %Dcrossed "+
WriteIf(StochK() >StochD(),"above","below")+
" its signal line "+
WriteVal( Min( BarsSince( Cross( StochK(),StochD() )), BarsSince( Cross( StochD(),StochK()))), 0.0)+
" period(s) ago.";

bars=LastValue(Min( BarsSince( Cross( StochK(),StochD() )), BarsSince( Cross(  StochD(),StochK())) ));

prevclose=Ref(Close,-bars);

"Since the %K crossed %D, "+
Name()+"'s price has "+
WriteIf(Close>prevclose,"increased ","decreased ")+
WriteVal(100*(Close-prevclose)/prevclose) + "%";

"And has ranged from a high of "+
WriteVal(HHV(High,bars+1),6.3)+
" to a low of "+
WriteVal(LLV(Low,bars+1),6.3);

"\nOverbought/Oversold\n";
Osc = OscP( 12, 26 );
Osc1 = Ref( Osc, -1 );
Osc5 = Ref( Osc, -5 );

WriteIf( StochD() <= 20 ),
"The %K is in an oversold range. Prices may continue to move lower for some time.  Wait for prices to move higher before considering any long positions.", 
WriteIf( StochD() >= 80 ), 
"The %K%D is in an overbought range.  Prices may continue to move higher for some time.  Wait for prices to move lower before considering any short positions.", 
"The %K%D  is not in an Overbought/Oversold range."));
not working showing error.:):thumb:
 
#49
Re: Which combination of indicators helps detect an impnding upmove or downmove relia

Can you please help me make a basic AFL which plots pivots as defined below

pivot high - if next candle makes lower low and lower close
pivot low - if next candle makes higher high and higher close

pivot low has to be followed by pivot high . We cannot have 2 pivot lows without a pivot high

Thanks in advance
 

DanPickUp

Well-Known Member
#50
Re: Which combination of indicators helps detect an impnding upmove or downmove relia

Dan...
could u please elaborate as a newbie I am not getting your point...
Hi Bewinner

Hope you did read a bit about what was recommended.;):)

Now lets start with Implied volatility. I will explain it the shortest way I can.

Implied volatility is a dynamic figure that changes based on activity in the options marketplace. Usually, when implied volatility increases, the price of options will increase as well, assuming all other things remain constant. So when implied volatility increases after a trade has been placed, its good for the option owner and bad for the option seller.

Conversely, if implied volatility decreases after your trade is placed, the price of options usually decreases. Thats good if youre an option seller and bad if youre an option owner.

How are option priced:

Stock or future price + Strike price + Expiration date + Interest rate + Dividend + IMPLIED VOLATILITY = Price of the option

So, high IV means: The options are higher priced. So we sell options. Now the second part, which is the put call ratio, comes into place.

The put-call ratio is primarily used by traders as a contrarian indicator when the values reach relatively extreme levels. This means that many traders will consider a large ratio a sign of a buying opportunity because they believe that the market holds an unjustly bearish outlook and that it will soon adjust, when those with short positions start looking for places to cover. There is no magic number that indicates that the market has created a bottom or a top, but generally traders will anticipate this by looking for spikes in the ratio or for when the ratio reaches levels that are outside of the normal trading range.

Now if we see a put call ratio which indicates f.e that three times more puts are in the market of one specific option series than calls, we have a put call ration of 3:1. If we see such a number short before option expiration day, the chance is very high that market will move up. In that case the put sellers, which are in general the big institutes and hedge funds, can keep there profit. It also has to do with market manipulation, but that is an other subject.

If we now have or see a spike in IV in the puts (which can be seen in any advanced platform or option analyzing software) and a put call ratio from 3:1, we can start to sell puts, as market most probably will start to move up shortly. If market starts to move up, IV of the puts will come down. And that is what we want when we sell options. This kind of taking decisions would not need any technical indicator by it self. If it even occurs in combination with any TA, you have on ODDs trade.

All the best and good trading / DanPickUp


http://www.optionsplaybook.com/
http://www.investopedia.com
 

Similar threads