Previous Support Level and Value

Hello everyone,

Hope all is well.

Recently, I try to learn in writing AFL. I have no background in computer programing language. I am learning from published AFL in the forum. However, this time I need favors from advance users in forum to create additional line which content previous value of support (Redline). Before I am asking this issue to forum, I already try to look answers from previous topic / posting in this forum. I am sorry if I am not smart enough exploring the achieves.

My current AFL as follows

Plot( C, "Close", ParamColor("Color", colorDefault ), styleCandle|styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

_SECTION_BEGIN("TRAILING");

StopLength = (2 * ATR(14) );
BuySL = Cross(MA(C,10),Ref(MA(C,10),-1)) AND C>MA(C,10) AND C>O; 
SellSL = 0;

ApplyStop(stopTypeTrailing, stopModeBars, stopLength, 1, True, 1);
Intrade = Flip(BuySL, SellSL);
SetOption("EveryBarNullCheck", True);
Stopline = IIf(intrade, HighestSince(BuySL, ((H+L)/2 - StopLength)), Null);
Plot(Stopline, "",colorRed, styleStaircase|StyleThick|styleNoLabel|styleNoTitle,0,0,0,1);

_SECTION_END();

for( i = 0; i < BarCount; i++ );
PlotText("____________________________________________________ TS "+WriteVal(Stopline,1.0),i-31,SelectedValue(Stopline),colorGreen);

Based on the above picture, I want to plottext to describe the support value as my previous support

the blue lines are where the previous support line ploted.

Thank you for your help and assistence.

Regards,
Febri

If you want the value when the support line changed, you can use something like

previous_stopline=valuewhen(stopline!=ref(stopline,-1),ref(stopline,-1));

I noticed also that there is additional semicolon for the loop

for( i = 0; i < BarCount; i++ )

If you want to plot only at end -31 then remove the loop
use the plot text i as barcount

I can see you are using ApplyStop(), but this is purely a backtester function and will not evaluate in your charting code.

Look at in-place backtesting by Equity( ... ), various modes to apply stops.
AFL Function Reference - EQUITY

It is not clear, you want to plot all previous support ie. stops, or just one previous support from the current stop line

Hi mmha,
Thank you for your advise. it works well.

Hi nsm51,
Thank you for your correction. I really appricate it.

Regards,
Febri

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.