AFL to plot line on next few bars

Joined
Jun 11, 2014
Messages
45
Likes
8
#1
Hi,
Is it possible plot lines only next few bars from selected value and it should not be extended after that. Please find sample image below. Thanks for the help



Thanks
 

colion

Active Member
Joined
Jun 26, 2007
Messages
201
Likes
108
#2
Here is one way:

bar = SelectedValue( barindex() ) - 1;
ext = Param( "Extend", 10, 3, 50, 1 );
piv = ParamToggle( "Pivot", "H | L" );
Plot( C, "", colorPaleGreen, styleBar );
Plot( IIf( BarIndex() > bar AND BarIndex() < bar + ext, IIf( piv == 0, SelectedValue( H ), SelectedValue( L ) ), Null ), "", colorRed );
 
Joined
Jun 11, 2014
Messages
45
Likes
8
#3
Thanks colion for the reply. Could you please help me to draw from specific bar as below?

Code:
PH = Ref(H,-5) < Ref(H,-3) AND Ref(H,-3) < Ref(H,-3) AND Ref(H,-2) < Ref(H,-3) AND Ref(H,-1) < Ref(H,-3)
When above condition is true, it has to draw from Ref(H,-3) to 10 bars. Thanks for your help
 

colion

Active Member
Joined
Jun 26, 2007
Messages
201
Likes
108
#4
There is not much change. Be sure that you understand the code and then it should get you going. Then you can modify it as needed to suit your needs.

ph = Ref(H,-5) < Ref(H,-3) AND Ref(H,-4) < Ref(H,-3) AND Ref(H,-2) < Ref(H,-3) AND Ref(H,-1) < Ref(H,-3);
bar = SelectedValue( BarIndex() ) - 1;
ext = Param( "Extend", 10, 3, 50, 1 );
Plot( C, "", IIf( ph, colorWhite, colorPaleGreen ), styleBar );
Plot( IIf( BarIndex() > bar - 3 AND BarIndex() < bar + ext, SelectedValue( Ref( H, -3 ) ), Null ), "", colorRed );
 
Last edited:
Joined
Jun 11, 2014
Messages
45
Likes
8
#5
There is not much change. Be sure that you understand the code and then it should get you going. Then you can modify it as needed to suit your needs.

ph = Ref(H,-5) < Ref(H,-3) AND Ref(H,-4) < Ref(H,-3) AND Ref(H,-2) < Ref(H,-3) AND Ref(H,-1) < Ref(H,-3);
bar = SelectedValue( BarIndex() ) - 1;
ext = Param( "Extend", 10, 3, 50, 1 );
Plot( C, "", IIf( ph, colorWhite, colorPaleGreen ), styleBar );
Plot( IIf( BarIndex() > bar - 3 AND BarIndex() < bar + ext, SelectedValue( Ref( H, -3 ) ), Null ), "", colorRed );
it is not working colion. Because we need to identify the index of the when the condition is true and draw from high of that bar... I tried all the ways... I think am missing something

Thanks
 

colion

Active Member
Joined
Jun 26, 2007
Messages
201
Likes
108
#6
it is not working colion. Because we need to identify the index of the when the condition is true and draw from high of that bar... I tried all the ways... I think am missing something

Thanks
Just click on the white bar (this finds the index) and the line that you want is drawn. If that is not what you want then I don't know what you want - you have to be more specific. For example, exactly which ph do you want to consider? The last?

 
Last edited:
Joined
Jun 11, 2014
Messages
45
Likes
8
#7
Thanks colion. The thing is that I don't want select any bar and draw from there. It has to identify the every pivot automatically and draw from that pivot to next 10 bar or till barcount. Please look at the code which I am using currently for PH and output.
Code:
PH = Ref(H,-4) < Ref(H,-2) AND Ref(H,-3) <= Ref(H,-2) AND Ref(H,-1) <= Ref(H,-2) AND Ref(H,0) < Ref(H,-2);
VW=ValueWhen(PH,Ref(H,-2),1);
fil = VW != Ref(VW,-1); 
Plot(IIf(fil,Null,VW),"PH",colorBrown,styleDots|styleStaircase|styleSwingDots|styleThick,Null,Null,-3);
 

colion

Active Member
Joined
Jun 26, 2007
Messages
201
Likes
108
#8
Fine, then keep it simple and use the built-in peak functions and adjustable parameters for peak change and line extension follows:

ext = Param( "Extend", 10, 3, 50, 1 );
delta = Param( "Change", .1, .1, 10, .1 );
Plot( C, "", colorblack, styleBar | stylethick );
Plot( IIf( PeakBars( H, delta ) > 0 AND PeakBars( H, delta ) < ext, peak( H, delta ), Null ), "", colorRed, styleThick );

If that is not what you want then post what you think the code should be even if it does not work.

 
Joined
Jun 11, 2014
Messages
45
Likes
8
#9
thank you. I don't think it will work out. Anyway I will try. Did you my previous post fully? Need to draw line from every PH. Since I am not aware peakBars, I will check again. thanks for the reply
 

colion

Active Member
Joined
Jun 26, 2007
Messages
201
Likes
108
#10
Thanks colion. The thing is that I don't want select any bar and draw from there. It has to identify the every pivot automatically and draw from that pivot to next 10 bar or till barcount. Please look at the code which I am using currently for PH and output.
Code:
PH = Ref(H,-4) < Ref(H,-2) AND Ref(H,-3) <= Ref(H,-2) AND Ref(H,-1) <= Ref(H,-2) AND Ref(H,0) < Ref(H,-2);
VW=ValueWhen(PH,Ref(H,-2),1);
fil = VW != Ref(VW,-1); 
Plot(IIf(fil,Null,VW),"PH",colorBrown,styleDots|styleStaircase|styleSwingDots|styleThick,Null,Null,-3);
Your definition of a peak is wrong. On the following chart the red bars are PH which are obviously not peaks.

 

Similar threads

Broker Special Offers