# Convert Thinkorswim indicator to AFL

Hello there,

I am new here and I have very very little coding experience and I would like someone to help me in converting thinkorswim code to afl. This code is for drawing trendlines and it is very complicated for me to convert to afl.

### Automatic Trend Line Code (courtesy of Mobius)

input TrendLineLength1 = 150;
input TrendLineLength2 = 80;
input TrendLineLength3 = 40;

def Inertia1 = InertiaAll(RSI, TrendLineLength1);
def Inertia2 = InertiaAll(RSI, TrendLineLength2);
def Inertia3 = InertiaAll(RSI, TrendLineLength3);

def TL_Bull1 = Inertia1 - (HighestAll(AbsValue(Inertia1 - RSI)) * 0.8);
def TL_Bear1 = Inertia1 + (HighestAll(AbsValue(Inertia1 - RSI)) * 0.8);
def slope1a = TL_Bull1 > TL_Bull1[1];
def slope1b = TL_Bear1 > TL_Bear1[1];

def TL_Bull2 = Inertia2 - (HighestAll(AbsValue(Inertia2 - RSI)) * 0.8);
def TL_Bear2 = Inertia2 + (HighestAll(AbsValue(Inertia2 - RSI)) * 0.8);
def slope2a = TL_Bull2 > TL_Bull2[1];
def slope2b = TL_Bear2 > TL_Bear2[1];

def TL_Bull3 = Inertia3 - (HighestAll(AbsValue(Inertia3 - RSI)) * 0.8);
def TL_Bear3 = Inertia3 + (HighestAll(AbsValue(Inertia3 - RSI)) * 0.8);
def slope3a = TL_Bull3 > TL_Bull3[1];
def slope3b = TL_Bear3 > TL_Bear3[1];
#Long length
plot TrendLine1a = if slope1a > 0 then TL_Bull1 else TL_Bear1;
TrendLine1a.SetStyle(Curve.FIRM);
TrendLine1a.SetLineWeight(1);
TrendLine1a.AssignValueColor(if slope1a and IsAscending(RSI, 10) then Color.WHITE else if slope1a then Color.WHITE else if !IsAscending(RSI, 10) then Color.WHITE else Color.WHITE);

plot TrendLine1b = if slope1b > 0 then TL_Bear1 else TL_Bull1;
TrendLine1b.SetStyle(Curve.FIRM);
TrendLine1b.SetLineWeight(1);
TrendLine1b.AssignValueColor(if slope1b and IsAscending(RSI, 10) then Color.WHITE else if slope1b then Color.WHITE else if !IsAscending(RSI, 10) then Color.WHITE else Color.WHITE);
#Medium length
plot TrendLine2a = if slope2a > 0 then TL_Bull2 else TL_Bear2;
TrendLine2a.SetStyle(Curve.FIRM);
TrendLine2a.SetLineWeight(1);
TrendLine2a.AssignValueColor(if slope2a and IsAscending(RSI, 10) then Color.LIGHT_GREEN else if slope2a then Color.LIGHT_GREEN else if !IsAscending(RSI, 10) then Color.MAGENTA else Color.MAGENTA);

plot TrendLine2b = if slope2b > 0 then TL_Bear2 else TL_Bull2;
TrendLine2b.SetStyle(Curve.FIRM);
TrendLine2b.SetLineWeight(1);
TrendLine2b.AssignValueColor(if slope2b and IsAscending(RSI, 10) then Color.LIGHT_GREEN else if slope2b then Color.LIGHT_GREEN else if !IsAscending(RSI, 10) then Color.MAGENTA else Color.MAGENTA);
#Short length
plot TrendLine3a = if slope3a > 0 then TL_Bull3 else TL_Bear3;
TrendLine3a.SetStyle(Curve.FIRM);
TrendLine3a.SetLineWeight(1);
TrendLine3a.AssignValueColor(if slope3a and IsAscending(RSI, 10) then Color.LIGHT_GREEN else if slope3a then Color.LIGHT_GREEN else if !IsAscending(RSI, 10) then Color.PINK else Color.PINK);

plot TrendLine3b = if slope3b > 0 then TL_Bear3 else TL_Bull3;
TrendLine3b.SetStyle(Curve.FIRM);
TrendLine3b.SetLineWeight(1);
TrendLine3b.AssignValueColor(if slope3b and IsAscending(RSI, 10) then Color.LIGHT_GREEN else if slope3b then Color.LIGHT_GREEN else if !IsAscending(RSI, 10) then Color.PINK else Color.PINK);

Your help will be much appreciated.

Thank you,

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