TrendLine AFL code

I am trying to convert the Pine script code to AFL for the Autotrend Line.
@fxshrat can you help me

// Pine Script Code
//@version=5
indicator("Trendlines with Breaks [LuxAlgo]",overlay=true)
length = input.int(14)
k      = input.float(1.,'Slope',minval=0,step=.1)
method = input.string('Atr','Slope Calculation Method',
  options=['Atr','Stdev','Linreg'])
show   = input(false,'Show Only Confirmed Breakouts')
//----
upper = 0.,lower = 0.
slope_ph = 0.,slope_pl = 0.
src = close
n = bar_index
//----
ph = ta.pivothigh(length,length)
pl = ta.pivotlow(length,length)
slope = switch method
    'Atr'      => ta.atr(length)/length*k
    'Stdev'    => ta.stdev(src,length)/length*k
    'Linreg'   => math.abs(ta.sma(src*bar_index,length)-ta.sma(src,length)*ta.sma(bar_index,length))/ta.variance(n,length)/2*k

slope_ph := ph ? slope : slope_ph[1]
slope_pl := pl ? slope : slope_pl[1]

upper := ph ? ph : upper[1] - slope_ph
lower := pl ? pl : lower[1] + slope_pl
plot(upper,'Upper',color = ph ? na : #26a69a,offset=-length)
plot(lower,'Lower',color = pl ? na : #ef5350,offset=-length)
_SECTION_BEGIN("Trendlines with Breaks ");

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

length 	= Param("Length",14,1,20,1);
K      	= Param("Length",1,1,10,0.1);//input.float(1.,'Slope',minval=0,step=.1)
Method 	= ParamList("Slope Calculation Method","ATR|StDev|Linreg"); //input.string('Atr','Slope Calculation Method',options=['Atr','Stdev','Linreg'])
Show   	= ParamToggle("Show Only Confirmed Breakouts","NO|YES",1); //input(false,'Show Only Confirmed Breakouts')
src 	= ParamField("Price field",-1);

upper = 0;lower = 0;
slope_ph = 0;slope_pl = 0;
n = barindex();

ph = Ref(HHV(H,length),-1);
pl = Ref(LLV(L,length),-1);
slope = LinearReg(C,length)/2*k;

Plot(IIf(PH==Ref(PH,-1),PH,Null),"PH",colorBlack);
slope_ph = IIf(ph , slope ,Ref(slope_ph,-1));
slope_pl = IIf(PL , slope ,Ref(slope_pl,-1));
upper = IIf(ph , ph ,(Ref(upper,-1)- slope)); //ph ? ph : upper[1] - slope_ph
lower = IIf(pl , pl ,Ref(lower,-1)- slope_pl); //pl ? pl : lower[1] + slope_pl

Plot(upper,"upper",colorBlack);

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