AFL help needed to plot lines

casoni

Well-Known Member
#11
I think ST's gap concept is like this:
In uptrend: Find a PH called PH1. Find a higher PL called PL2. If PL2 minus PH1 is greater than user defined minimum gap, then we have ST's gap.
In downtrend: Find a PL called PL1. Find a lower PH called PH2. If PL1 minus PH2 is greater than user defined minimum gap, then we have ST's gap.
In sideways: not applicable.

By how much PL must be greater than PH can be left to the parameters (% and/or absolute number).
Entry/exit signals not required as they depend on one's method.
Also scan/explore capability in various TF's will be ideal.
Hello Raghuveer,

can you please mark PH1 , PL1 on current Nift_f1 or banknifty_1 chat !
so that i can understand and can proceed futher on ST concept
thank you
 

Raghuveer

Well-Known Member
#12
Hello Raghuveer,

can you please mark PH1 , PL1 on current Nift_f1 or banknifty_1 chat !
so that i can understand and can proceed futher on ST concept
thank you
Thanks for looking into this. Appreciate your help.

In downtrend:


In uptrend:
 
Last edited:

amitrandive

Well-Known Member
#14
Casoni,mastermind and Raghuveer

Thanks for looking into this.And many thanks for your inputs

Raghuveer has outlined the concepts beautifully,that defines the logic of this AFL.
:clapping::clapping::clapping:
 

amitrandive

Well-Known Member
#15
Amit, Casoni


Essentially entire AFL coding circles around identifying a particular candle (the chosen candle) that fits certain rules. As long as we can pin-point the rules, we can make the AFL.

For example, in the chart displayed by amit, some of the rules are
1) We identify a candle that has made a higher high relative to the candle that was M bars ago.
2) Our chosen candle must not be making a higher high relative to N bars previous.
3) The Low of chosen candle must be higher than Low of Candle M bars ago but not higher than Low of candle N bars ago.
..... and so on ....
Here, M == integer; N == M / 2 thru to (M - 1);
So if M is 10, N is from 5 to 9.

You need to evolve what ST said into a logic such as above for it to be converted into the AFL.

Do bear in mind that when we manually identify candle, we may sometimes miss a valid one and sometimes make incorrect choices... AFL will not make the same mistakes...

After all this AFL geeky stuff, I have one idea that is a lot simpler to identify what ST identifies by means of Gaps.

If you have BNF data from the time period ST shows on chart, simply plot MA(L, 20) on it. My hunch is that in all the middle periods (the hold-on periods), Low would not breach the average. You may even use EMA....
I have intraday data for 6 months only.
I plotted this on the recent chart,not much of a difference between EMA(C,20) and EMA(L,20)
 

amitrandive

Well-Known Member
#16
Amit

I have a question that relates to the market movement this week and very creative use of gaps in December 2014 NIFTY and BANKNIFTY.

On the day that the indice opened with bullish gap { O > Ref (C, -1) } , it closed bearish and vice-versa.

Last two days (18 and 19) have been claimed as being bullish in emails from brokers and media but it is actually bears who have ensured that prices remained high and they've continued selling!

19 Dec by comparison has +ve close relative to 18 dec but all those who went long at start of 19th show max profit of 15-25 points whereas bears got 45-50 points on an average. Actual sentiment is that of sell-off
Mastermind

I feel the intermediate downtrend is still strong.It can be a bearish flag with the last leg on.As all three candles on 17,18 and 19 started with gap ups.
Only the candle of 18th was able to hold on to the gains and closed bullish.

Similar discussion going around here

http://www.traderji.com/general-trading-investing-chat/96368-general-trading-chat-2.html#post1038966
 

amitrandive

Well-Known Member
#17
i think this code will do the job ,[ as per rules you have mentioned ]
* its Edward Pottasch code

// AFL code by Edward Pottasch,
xx=BarIndex();x=xx;Lx=LastValue(x);
rightStrength=Param("Fractal Pivot Right side Strength",3,0,50,1);
leftStrength=Param("Fractal Pivot Left side Strength",5,0,50,1);
pk=H>Ref(HHV(H,leftStrength),-1) AND Ref(HHV(H,rightStrength),rightStrength)<=H;
tr=L<Ref(LLV(L,leftStrength),-1) AND Ref(LLV(L,rightStrength),rightStrength)>=L;
SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,0,0,0,0);
PlotShapes(shapeSmallCircle*tr,IIf(Lx-ValueWhen(tr,x)>rightStrength,ColorRGB(0,100,0),colorWhite),0,L,-10);
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>rightStrength,ColorRGB(255,0,0),colorWhite),0,H,10);

peak or trough will be confirmed when the shape turn's its color i.e from white to red / green

Thank you
Pivot High Low code also works similar to this.But it looks to the future and repaints.

Code:
_SECTION_BEGIN("ZigZag");
P = Param("ZigZag_Percent",0.1,0.01,2,0.01);
ZigH  = Zig(H,P);		ZigL = Zig(L,P);
ZigHi = ZigH > Ref(ZigH,-1) AND ZigH > Ref(ZigH,1);		
ZigLo = ZigL < Ref(ZigL,-1) AND ZigL < Ref(ZigL,1);
j=0;	k=0;	PH[0] = PL[0] = 0;
for( i = 1; i < BarCount-1; i++ ) { 
 if (ZigLo[i])	{
	if (PL[k] > ZigL[i])  	PlotText("LL",i, L[i]-5, colorGreen);
	else						PlotText("HL",i, L[i]-5, colorGreen);
	k = k + 1;		PL[k] = ZigL[i]; }
 if (ZigHi[i]) {
	if (PH[j] < ZigH[i])  	PlotText("HH", i, H[i]+5, colorRed);
	else						PlotText("LH", i, H[i]+5, colorRed);
	j = j + 1;
	PH[j] = ZigH[i]; }
}

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

casoni

Well-Known Member
#18
Pivot High Low code also works similar to this.But it looks to the future and repaints.

Code:
_SECTION_BEGIN("ZigZag");
P = Param("ZigZag_Percent",0.1,0.01,2,0.01);
ZigH  = Zig(H,P);		ZigL = Zig(L,P);
ZigHi = ZigH > Ref(ZigH,-1) AND ZigH > Ref(ZigH,1);		
ZigLo = ZigL < Ref(ZigL,-1) AND ZigL < Ref(ZigL,1);
j=0;	k=0;	PH[0] = PL[0] = 0;
for( i = 1; i < BarCount-1; i++ ) { 
 if (ZigLo[i])	{
	if (PL[k] > ZigL[i])  	PlotText("LL",i, L[i]-5, colorGreen);
	else						PlotText("HL",i, L[i]-5, colorGreen);
	k = k + 1;		PL[k] = ZigL[i]; }
 if (ZigHi[i]) {
	if (PH[j] < ZigH[i])  	PlotText("HH", i, H[i]+5, colorRed);
	else						PlotText("LH", i, H[i]+5, colorRed);
	j = j + 1;
	PH[j] = ZigH[i]; }
}

_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();
In Edward pottash formula we have plus point

peak or trough will be confirmed when the shape turn's its color i.e from white to red / green

*Ever peak - through formula based on No of bars , will look into future
 

casoni

Well-Known Member
#19
Hello ,
According to ST concept ,
Gap is when , HL is greater then second HH !!!
see image [1] based on 5 min [2] as per hourly chart

* i have to delete previous images , because my uploading limit is very low
thank you
 
Last edited:

Raghuveer

Well-Known Member
#20
One more request , what's Are the condition for PH1,PL1 ,
i.e
H>ref(H,-1) AND L > REF(L,-1) AND ...........
Thank you
Thanks casoni.
Pivots used for this purpose must be visual pivots. Hard to define. In some cases we get nice two legged pullbacks to form a pivot and in some cases only one legged pullback. If it looks like a pivot then its a pivot.

Aggressive pivots are better avoided for this AFL.

If below Demark rule for TD pivot point fails then that is not a pivot:
for PH: ( H > Ref(H, 1) AND H > Ref(H, -1) AND H > Ref(C, -2));
for PL: ( L < Ref(L, 1) AND L < Ref(L, -1) AND L < Ref(C, -2));

Below code snippet taken from ST's "TD Systems" afl:
Code:
function TD_Supply()
{
return ( H > Ref(H, 1) AND H > Ref(H, -1) AND H > Ref(C, -2));
}
function TD_Demand()
{
return ( L < Ref(L, 1) AND L < Ref(L, -1) AND L < Ref(C, -2));
}
See signature of "timepass" on how to post images. http://www.traderji.com/equities/47979-canteen-742.html#post591768
Use free and open source ShareX to upload pics with just a few mouse clicks. Quite easy to use, no complicated steps at all.
ShareX is easier than using steps in timepass signature.
 
Last edited:

Similar threads