Simple Coding Help - No Promise.

Hi Will you plz add scan/exploring to this afl


PHP:
_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) ,colorGreen, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);

PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorRed, 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("G2J 1.4");
//   http://www.bourex.com/viewtopic.php?t=16107&start=45
//   Kourosh Kabir 1389/11/15 (5 Parameters)
SetBarsRequired(1000000,1000000);
ind=StrToNum(NumToStr(BarIndex()));
sajal=1210;
sagr=Year();
magr=Month();
rogr=Day();
roha=DayOfWeek();
tdromab=DayOfYear()+25123;
sagrmo=sagr;
while(sagrmo[ind]>1900)
{
sagrmo--;
tdromab[ind]+=365;
if((sagrmo[ind]%4==0 AND sagrmo[ind]%100!=0) OR sagrmo[ind]%400==0)
tdromab[ind]++;
}
do
{
sakab=(((sajal-1210+1)%33)-1)%4;
sajal++;
tdromab[ind]-=365;
if(sakab==0)
tdromab[ind]--;
}while(tdromab[ind]>365);
switch(tdromab[ind])
{
case 0:
rojal=30;
majal=12;
sajal--;break;
default:
if(tdromab[ind]<=186)
{
rojal=tdromab[ind]%31;
majal=(tdromab[ind]-rojal)/31;
if(rojal==0)
rojal=31;
else
majal++;
}
else
{
tdromab[ind]-=186;
rojal=tdromab[ind]%30;
majal=(tdromab[ind]-rojal)/30;
if(rojal==0)
{
majal+=6;
rojal=30;
}
else
majal+=7;
}break;
}
switch(roha[ind])
{
case 0:
rohare="           ";break;
case 1:
rohare="           ";break;
case 2:
rohare="           ";break;
case 3:
rohare="           ";break;
case 4:
rohare="           ";break;
case 5:
rohare="           ";break;
case 6:
rohare="           ";break;
}
if(magr[ind]<10)
magrre="0"+NumToStr(magr,1,0);
else
magrre=NumToStr(magr,2,0);
if(rogr[ind]<10)
rogrre="0"+NumToStr(rogr,1,0);
else
rogrre=NumToStr(rogr,2,0);
if(majal<10)
majalre="0"+NumToStr(majal,1,0);
else
majalre=NumToStr(majal,2,0);
if(rojal<10)
rojalre="0"+NumToStr(rojal,1,0);
else
rojalre=NumToStr(rojal,2,0);
jaldate=NumToStr(sajal,4,0)+"/"+majalre+"/"+rojalre;
grdate=NumToStr(sagr,4,0)+"/"+magrre+"/"+rogrre;
GfxSetBkMode(1);
if(ParamToggle("Tooltip","Default|Date",1))
ToolTip=" "+rohare+" "+jaldate+" "+StrFormat("\n     Kourosh kabir\n\nOpen: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr(V,1.0),O,H,L,C,SelectedValue(ROC(C,1)));
if(ParamToggle("G overlay","On|Off"))
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma",Param("G font size",13,7,45,1));
GfxSetTextColor(ParamColor("G color",colorGreen));
mode=ParamList("Title","Default - Graphic|Date - Values|Date|Default");
if(mode=="Default - Graphic")
GfxTextOut(rohare+" "+jaldate,3,25);
if(mode=="Date - Values")
_N(Title=Name()+"  "+jaldate+" "+rohare+StrFormat("  {{INTERVAL}}"+"  "+grdate+"   Open %g   High %g   Low %g   Close %g (%.1f%%)   Volume "+NumToStr(V,1.0),O,H,L,C,SelectedValue(ROC(C,1)))+"\n{{VALUES}}");
if(mode=="Date")
_N(Title=Name()+"  "+jaldate+" "+rohare+StrFormat("  {{INTERVAL}}"+"  "+grdate+"   Open %g   High %g   Low %g   Close %g (%.1f%%)   Volume "+NumToStr(V,1.0),O,H,L,C,SelectedValue(ROC(C,1))));
if(mode=="Default")
_N(Title=StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol "+NumToStr(V,1.0)+" {{VALUES}}",O,H,L,C,SelectedValue(ROC(C,1))));
_SECTION_END();
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorRed ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); 
_SECTION_END();

_SECTION_BEGIN("Mid MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 45, 2, 300, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); 
_SECTION_END();

_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 100, 2, 400, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); 
_SECTION_END();

_SECTION_BEGIN("BBands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale;;
Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style ); 
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style ); 
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorLavender ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram  ), 2 );
_SECTION_END();

_SECTION_BEGIN("Price Interpretation");
movshort = ParamField("Short Time MA", 8 );
movmed = ParamField("Mid Time MA", 9 );
movlong = ParamField("Long Time MA", 10 );
btop = ParamField("BBTop", 11 );
bbot = ParamField("BBBottom", 12 );
if( Status("action") == actionCommentary )
{
width = btop - bbot;
lslop = LinRegSlope( C, 30 ) + 100;
lslo = LLV( lslop, 90 );
lshi = HHV( lslop, 90 );
lswidth = lshi - lslo;
trend = 100*( lslop - lslo )/lswidth;

mawidth = MA( width, 100 );
relwidth = 100*(width - mawidth)/mawidth;

_N( tname = Name()+"("+FullName()+")" );

printf("Price and moving averages:\n");
printf( tname + " has closed " + WriteIf( C > movshort, "above" , "below" ) + " its Short time moving average. ");

printf("\nShort time moving average is currently " + WriteIf( movshort > movmed, "above", "below") + " mid-time, AND " + WriteIf( movshort > movlong, "above", "below" ) + " long time moving averages.");

printf("\nThe relationship between price and moving averages is: "+
WriteIf( C > movshort AND movshort > movmed, "bullish",
WriteIf( C < movshort AND movshort < movmed, "bearish", "neutral" ) ) + " in short-term, and "+
WriteIf( movshort > movmed AND movmed > movlong , "bullish",
WriteIf( movshort < movmed AND movmed < movlong, "bearish", "neutral" ) ) + " in mid-long term. ");

printf("\n\nBollinger Bands:\n");
printf(tname+ " has closed " + 
WriteIf( C < bbot, "below the lower band by " +
WriteVal( 100 *( bbot-C )/ width, 1.1 ) + "%%. " +
WriteIf( trend < 30, " This combined with the steep downtrend can suggest that the downward trend in prices has a good chance of continuing.  However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the lower band and a downside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C > btop, "above the upper band by " +
WriteVal( 100 *( C- btop )/ width, 1.1 ) + "%%. " +
WriteIf( trend > 70, " This combined with the steep uptrend suggests that the upward trend in prices has a good chance of continuing.  However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the upper band and a upside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C < btop AND ( ( btop - C ) / width ) < 0.5, 
"below upper band by " +
WriteVal( 100 *( btop - C )/ width, 1.1 ) + "%%. ", 
WriteIf( C < btop AND C > bbot , "above bottom band by " +
WriteVal( 100 *( C - bbot )/ width, 1.1 ) + "%%. ", "" ) ));

printf("\n"+
WriteIf( ( trend > 30 AND trend < 70 AND ( C > btop OR C < bbot ) ) AND abs(relwidth) > 40,
"This picture becomes somewhat unclear due to the fact that Bollinger Bands are  currently",
"Bollinger Bands are " )+	 
WriteVal( abs( relwidth ), 1.1 ) + "%% " +
WriteIf( relwidth > 0, "wider" , "narrower" ) +
" than normal.");

printf("\n");

printf(
WriteIf( abs( relwidth ) < 40, "The current width of the bands (alone) does not suggest anything conclusive about the future volatility or movement of prices.","")+
WriteIf( relwidth < -40, "The narrow width of the bands suggests low volatility as compared to " + tname + "'s normal range.  Therefore, the probability of volatility increasing with a sharp price move has increased for the near-term. "+
"The bands have been in this narrow range for " + WriteVal(BarsSince(Cross(-40,relwidth)),1.0) + " bars. The probability of a significant price move increases the longer the bands remain in this narrow range." ,"")+
WriteIf( relwidth > 40, "The large width of the bands suggest high volatility as compared to " + tname + "'s normal range.  Therefore, the probability of volatility decreasing and prices entering (or remaining in) a trading range has increased for the near-term. "+
"The bands have been in this wide range for  " + WriteVal(BarsSince(Cross(relwidth,40)),1.0) + " bars.The probability of prices consolidating into a less volatile trading range increases the longer the bands remain in this wide range." ,""));

printf("\n\nThis commentary is not a recommendation to buy or sell. Use at your own risk.");
}
_SECTION_END();
 
Dear Sir
Please help me to generate signal;

Buy= when candle stop Above 40 days EMA high
Buy Exit= When candle stop Below 40 days EMA Low

and Sell= vise versa, Next Candle stop

_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );// 40 days High Green Line
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


_SECTION_BEGIN("EMA-2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );// 40 days Low Red Line
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


//MOMIN//////////////////
_SECTION_BEGIN("Magfied Market Price");
FS=Param("Font Size",30,11,100,1);
GfxSelectFont("Times New Roman", FS, 700, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorYellow) );
Hor=Param("Horizontal Position",1480,1,1800,1);
Ver=Param("Vertical Position",12,1,830,1);
GfxTextOut(""+C, Hor-690 , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor(ParamColor("Color",colorYellow) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor-690 , Ver+45 );
_SECTION_END();
 

amitrandive

Well-Known Member
Hi Will you plz add scan/exploring to this afl


PHP:
_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) ,colorGreen, 0, L,-12);
PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);

PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorRed, 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("G2J 1.4");
//   http://www.bourex.com/viewtopic.php?t=16107&start=45
//   Kourosh Kabir 1389/11/15 (5 Parameters)
SetBarsRequired(1000000,1000000);
ind=StrToNum(NumToStr(BarIndex()));
sajal=1210;
sagr=Year();
magr=Month();
rogr=Day();
roha=DayOfWeek();
tdromab=DayOfYear()+25123;
sagrmo=sagr;
while(sagrmo[ind]>1900)
{
sagrmo--;
tdromab[ind]+=365;
if((sagrmo[ind]%4==0 AND sagrmo[ind]%100!=0) OR sagrmo[ind]%400==0)
tdromab[ind]++;
}
do
{
sakab=(((sajal-1210+1)%33)-1)%4;
sajal++;
tdromab[ind]-=365;
if(sakab==0)
tdromab[ind]--;
}while(tdromab[ind]>365);
switch(tdromab[ind])
{
case 0:
rojal=30;
majal=12;
sajal--;break;
default:
if(tdromab[ind]<=186)
{
rojal=tdromab[ind]%31;
majal=(tdromab[ind]-rojal)/31;
if(rojal==0)
rojal=31;
else
majal++;
}
else
{
tdromab[ind]-=186;
rojal=tdromab[ind]%30;
majal=(tdromab[ind]-rojal)/30;
if(rojal==0)
{
majal+=6;
rojal=30;
}
else
majal+=7;
}break;
}
switch(roha[ind])
{
case 0:
rohare="           ";break;
case 1:
rohare="           ";break;
case 2:
rohare="           ";break;
case 3:
rohare="           ";break;
case 4:
rohare="           ";break;
case 5:
rohare="           ";break;
case 6:
rohare="           ";break;
}
if(magr[ind]<10)
magrre="0"+NumToStr(magr,1,0);
else
magrre=NumToStr(magr,2,0);
if(rogr[ind]<10)
rogrre="0"+NumToStr(rogr,1,0);
else
rogrre=NumToStr(rogr,2,0);
if(majal<10)
majalre="0"+NumToStr(majal,1,0);
else
majalre=NumToStr(majal,2,0);
if(rojal<10)
rojalre="0"+NumToStr(rojal,1,0);
else
rojalre=NumToStr(rojal,2,0);
jaldate=NumToStr(sajal,4,0)+"/"+majalre+"/"+rojalre;
grdate=NumToStr(sagr,4,0)+"/"+magrre+"/"+rogrre;
GfxSetBkMode(1);
if(ParamToggle("Tooltip","Default|Date",1))
ToolTip=" "+rohare+" "+jaldate+" "+StrFormat("\n     Kourosh kabir\n\nOpen: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+NumToStr(V,1.0),O,H,L,C,SelectedValue(ROC(C,1)));
if(ParamToggle("G overlay","On|Off"))
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma",Param("G font size",13,7,45,1));
GfxSetTextColor(ParamColor("G color",colorGreen));
mode=ParamList("Title","Default - Graphic|Date - Values|Date|Default");
if(mode=="Default - Graphic")
GfxTextOut(rohare+" "+jaldate,3,25);
if(mode=="Date - Values")
_N(Title=Name()+"  "+jaldate+" "+rohare+StrFormat("  {{INTERVAL}}"+"  "+grdate+"   Open %g   High %g   Low %g   Close %g (%.1f%%)   Volume "+NumToStr(V,1.0),O,H,L,C,SelectedValue(ROC(C,1)))+"\n{{VALUES}}");
if(mode=="Date")
_N(Title=Name()+"  "+jaldate+" "+rohare+StrFormat("  {{INTERVAL}}"+"  "+grdate+"   Open %g   High %g   Low %g   Close %g (%.1f%%)   Volume "+NumToStr(V,1.0),O,H,L,C,SelectedValue(ROC(C,1))));
if(mode=="Default")
_N(Title=StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol "+NumToStr(V,1.0)+" {{VALUES}}",O,H,L,C,SelectedValue(ROC(C,1))));
_SECTION_END();
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorRed ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); 
_SECTION_END();

_SECTION_BEGIN("Mid MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 45, 2, 300, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); 
_SECTION_END();

_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 100, 2, 400, 1 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale ); 
_SECTION_END();

_SECTION_BEGIN("BBands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale;;
Plot( bbt = BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style ); 
Plot( bbb = BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style ); 
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, colorWhite, 0.9 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorLavender ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram  ), 2 );
_SECTION_END();

_SECTION_BEGIN("Price Interpretation");
movshort = ParamField("Short Time MA", 8 );
movmed = ParamField("Mid Time MA", 9 );
movlong = ParamField("Long Time MA", 10 );
btop = ParamField("BBTop", 11 );
bbot = ParamField("BBBottom", 12 );
if( Status("action") == actionCommentary )
{
width = btop - bbot;
lslop = LinRegSlope( C, 30 ) + 100;
lslo = LLV( lslop, 90 );
lshi = HHV( lslop, 90 );
lswidth = lshi - lslo;
trend = 100*( lslop - lslo )/lswidth;

mawidth = MA( width, 100 );
relwidth = 100*(width - mawidth)/mawidth;

_N( tname = Name()+"("+FullName()+")" );

printf("Price and moving averages:\n");
printf( tname + " has closed " + WriteIf( C > movshort, "above" , "below" ) + " its Short time moving average. ");

printf("\nShort time moving average is currently " + WriteIf( movshort > movmed, "above", "below") + " mid-time, AND " + WriteIf( movshort > movlong, "above", "below" ) + " long time moving averages.");

printf("\nThe relationship between price and moving averages is: "+
WriteIf( C > movshort AND movshort > movmed, "bullish",
WriteIf( C < movshort AND movshort < movmed, "bearish", "neutral" ) ) + " in short-term, and "+
WriteIf( movshort > movmed AND movmed > movlong , "bullish",
WriteIf( movshort < movmed AND movmed < movlong, "bearish", "neutral" ) ) + " in mid-long term. ");

printf("\n\nBollinger Bands:\n");
printf(tname+ " has closed " + 
WriteIf( C < bbot, "below the lower band by " +
WriteVal( 100 *( bbot-C )/ width, 1.1 ) + "%%. " +
WriteIf( trend < 30, " This combined with the steep downtrend can suggest that the downward trend in prices has a good chance of continuing.  However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the lower band and a downside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C > btop, "above the upper band by " +
WriteVal( 100 *( C- btop )/ width, 1.1 ) + "%%. " +
WriteIf( trend > 70, " This combined with the steep uptrend suggests that the upward trend in prices has a good chance of continuing.  However, a short-term pull-back inside the bands is likely.",
WriteIf( trend > 30 AND trend < 70, "Although prices have broken the upper band and a upside breakout is possible, the most likely scenario for "+tname+" is to continue within current trading range.", "" ) ), "" ) +

WriteIf( C < btop AND ( ( btop - C ) / width ) < 0.5, 
"below upper band by " +
WriteVal( 100 *( btop - C )/ width, 1.1 ) + "%%. ", 
WriteIf( C < btop AND C > bbot , "above bottom band by " +
WriteVal( 100 *( C - bbot )/ width, 1.1 ) + "%%. ", "" ) ));

printf("\n"+
WriteIf( ( trend > 30 AND trend < 70 AND ( C > btop OR C < bbot ) ) AND abs(relwidth) > 40,
"This picture becomes somewhat unclear due to the fact that Bollinger Bands are  currently",
"Bollinger Bands are " )+	 
WriteVal( abs( relwidth ), 1.1 ) + "%% " +
WriteIf( relwidth > 0, "wider" , "narrower" ) +
" than normal.");

printf("\n");

printf(
WriteIf( abs( relwidth ) < 40, "The current width of the bands (alone) does not suggest anything conclusive about the future volatility or movement of prices.","")+
WriteIf( relwidth < -40, "The narrow width of the bands suggests low volatility as compared to " + tname + "'s normal range.  Therefore, the probability of volatility increasing with a sharp price move has increased for the near-term. "+
"The bands have been in this narrow range for " + WriteVal(BarsSince(Cross(-40,relwidth)),1.0) + " bars. The probability of a significant price move increases the longer the bands remain in this narrow range." ,"")+
WriteIf( relwidth > 40, "The large width of the bands suggest high volatility as compared to " + tname + "'s normal range.  Therefore, the probability of volatility decreasing and prices entering (or remaining in) a trading range has increased for the near-term. "+
"The bands have been in this wide range for  " + WriteVal(BarsSince(Cross(relwidth,40)),1.0) + " bars.The probability of prices consolidating into a less volatile trading range increases the longer the bands remain in this wide range." ,""));

printf("\n\nThis commentary is not a recommendation to buy or sell. Use at your own risk.");
}
_SECTION_END();
Please define your buy and sell conditions to do that
 

amitrandive

Well-Known Member
scan blue arrow for buy and red for sell.i do not know how this indicator works exactly.will you plz explain it.what is best buy/sell signal in your opinion ?
I have absolutely no idea about this.

You can research here and decide your own buy and sell rules.

Either do that or form your own system.No use in following someone else's system without understanding it.

http://www.elliottfractals.com/forecast.asp
 

ram2010

Well-Known Member
can anyone help me by providing the scanner for following conditions

buy-

3 consecutive red candles which close price is lower than previous candle close , and a green candle which closes above the previous candle high at lower bollinger band

sell-

exactly opposite at upper bollinger band

thanks,
 

sr114

Well-Known Member
showing error 10 . [Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range. you attempred to access the non existing -1th element of the array and also the 81th element]
how to correct it?

Code:
s0 = 7604.35;
E = 7000;
r = 0.08;
t = 0.25;
C = 603.45;
sigma = 0.1;

d1 = (log(s0/E)+(r+sigma^2/2)*t)/(sigma*sqrt(t));
d2 = d1-sigma*sqrt(t);
function NORMDIST( x, mean, stddev, Cumulative ) {
  k = 2 / sqrt( 3.14159265 );
  z = ( x - mean ) / ( stddev * sqrt( 2 ) ); 
  q = k * ( z - z ^ 3 / 3 + z ^ 5 / 10 - z ^ 7 / 42 + z ^ 9 / 216
      - z ^ 11 / 1320 + z ^ 13 / 9360 - z ^ 15 / 75600 );

  if ( Cumulative ) {
    result = ( 1 + q ) / 2;
  }

  else {
    result = ( 1 / ( sqrt( 2 * 3.14159265 ) * stddev ) ) 
         * exp( -( x - mean ) ^ 2 / ( 2 * stddev ^ 2 ) );
  }

  return result;
}
nd1=NORMDIST( d1, 0, 1,1);
nd2=NORMDIST( d2, 0, 1,1); 

//#Initial value of volatility:
sig = 0;
sig = sigma;
//#Newton-Raphson method:

for(i=0;i<100;i++)
{
d1 = (log(s0/E)+(r+sigma^2/2)*t)/(sigma*sqrt(t));
d2 = d1-sigma*sqrt(t);
f = s0*nd1-E*exp(-r*t)*nd2-C;
//#Derivative of d1 w.r.t. sigma:
d11 = (sigma^2*t*sqrt(t)-(log(s0/E)+(r+sigma^2/2)*t)*sqrt(t))/(sigma^2*t);
//#Derivative of d2 w.r.t. sigma:
d22 = d11-sqrt(t);
//#Derivative of f(sigma):
f1 = s0*nd1*d11-E*exp(-r*t)*nd2*d22;
//#Update sigma:
sigma = sigma - f/f1;
sig = sigma;

[COLOR="Blue"]if(i > 0 )
       [B]if(abs(sig[i]-sig[i-1]) < 0.00000001) 	sig = sig[i-1];[/B]
   else
       sig = Null; [/COLOR]

}
rgds
 
Last edited:

KelvinHand

Well-Known Member
showing error 10 . [Error 10. Subscript out of range. You must not access array elements outside 0..(BarCount-1) range. you attempred to access the non existing -1th element of the array and also the 81th element]
how to correct it?

Code:
s0 = 7604.35;
E = 7000;
r = 0.08;
t = 0.25;
C = 603.45;
sigma = 0.1;

d1 = (log(s0/E)+(r+sigma^2/2)*t)/(sigma*sqrt(t));
d2 = d1-sigma*sqrt(t);
function NORMDIST( x, mean, stddev, Cumulative ) {
  k = 2 / sqrt( 3.14159265 );
  z = ( x - mean ) / ( stddev * sqrt( 2 ) ); 
  q = k * ( z - z ^ 3 / 3 + z ^ 5 / 10 - z ^ 7 / 42 + z ^ 9 / 216
      - z ^ 11 / 1320 + z ^ 13 / 9360 - z ^ 15 / 75600 );

  if ( Cumulative ) {
    result = ( 1 + q ) / 2;
  }

  else {
    result = ( 1 / ( sqrt( 2 * 3.14159265 ) * stddev ) ) 
         * exp( -( x - mean ) ^ 2 / ( 2 * stddev ^ 2 ) );
  }

  return result;
}
nd1=NORMDIST( d1, 0, 1,1);
nd2=NORMDIST( d2, 0, 1,1); 

//#Initial value of volatility:
sig = 0;
sig = sigma;
//#Newton-Raphson method:

for(i=0;i<100;i++)
{
d1 = (log(s0/E)+(r+sigma^2/2)*t)/(sigma*sqrt(t));
d2 = d1-sigma*sqrt(t);
f = s0*nd1-E*exp(-r*t)*nd2-C;
//#Derivative of d1 w.r.t. sigma:
d11 = (sigma^2*t*sqrt(t)-(log(s0/E)+(r+sigma^2/2)*t)*sqrt(t))/(sigma^2*t);
//#Derivative of d2 w.r.t. sigma:
d22 = d11-sqrt(t);
//#Derivative of f(sigma):
f1 = s0*nd1*d11-E*exp(-r*t)*nd2*d22;
//#Update sigma:
sigma = sigma - f/f1;
sig = sigma;

[COLOR="Blue"]if(i > 0 )
       [B]if(abs(sig[i]-sig[i-1]) < 0.00000001) 	sig = sig[i-1];[/B]
   else
       sig = Null; [/COLOR]

}
rgds

First thing to check, is the loop
always test this: assume i=0; i-1 = -1, can the program accept ?
Code:
for(i=[B][COLOR="Red"]0[/COLOR][/B];i<100;i++)
{
   if(i > 0 )
       if(abs(sig[i]-sig[B][I][COLOR="red"][i-1[/COLOR][/I][/B]]) < 0.00000001) 	sig = sig[[B][I][COLOR="red"]i-1[/COLOR][/I][/B]];
   else
       sig = Null;

}

}
2nd, Ask yourself, below code repeat 100 times, which are not using the looping variable i, is this necessary ?
repeat 1 time and repeat 100 times are the result the same ?
if the same why not move out ?


Code:
for(i=0;i<100;i++)
{
[B][I][COLOR="Red"]d1 = (log(s0/E)+(r+sigma^2/2)*t)/(sigma*sqrt(t));
d2 = d1-sigma*sqrt(t);
f = s0*nd1-E*exp(-r*t)*nd2-C;
//#Derivative of d1 w.r.t. sigma:
d11 = (sigma^2*t*sqrt(t)-(log(s0/E)+(r+sigma^2/2)*t)*sqrt(t))/(sigma^2*t);
//#Derivative of d2 w.r.t. sigma:
d22 = d11-sqrt(t);
//#Derivative of f(sigma):
f1 = s0*nd1*d11-E*exp(-r*t)*nd2*d22;
//#Update sigma:
sigma = sigma - f/f1;
sig = sigma;[/COLOR][/I][/B]
}
 
Last edited:
First thing to check, is the loop

2nd, Ask yourself, below code repeat 100 times, which are not using the looping variable i, is this necessary ?
repeat 1 time and repeat 100 times are the result the same ?
if the same why not move out ?


Code:
for(i=0;i<100;i++)
{
[B][I][COLOR="Red"]d1 = (log(s0/E)+(r+sigma^2/2)*t)/(sigma*sqrt(t));
d2 = d1-sigma*sqrt(t);
f = s0*nd1-E*exp(-r*t)*nd2-C;
//#Derivative of d1 w.r.t. sigma:
d11 = (sigma^2*t*sqrt(t)-(log(s0/E)+(r+sigma^2/2)*t)*sqrt(t))/(sigma^2*t);
//#Derivative of d2 w.r.t. sigma:
d22 = d11-sqrt(t);
//#Derivative of f(sigma):
f1 = s0*nd1*d11-E*exp(-r*t)*nd2*d22;
//#Update sigma:
sigma = sigma - f/f1;
sig = sigma;[/COLOR][/I][/B]
}
Hi Kelvin,
Don't know much about AFL. but sigma value is updating from it's previous value in each iteration inside the for loop. Don't know the significance of why loop is iterating 100 times.

sigma = sigma - f/f1;
 

Similar threads