Mr_Wheeler
Active member
https://usethinkscript.com/threads/follow-line-indicator.9789/
my study - https://tos.mx/UHpXqwY
The orange label tells you how many shares you can purchase with the budget set in the configuration menu at the current price.
The green label tells you how many shares you can buy at the green arrow.
The blue, red,and white labels tell you the profit that you would have made if you bought in at the green arrow with the number of shares listed in the green label.
Think of all of this as an automatic stop loss study based on moving average lines.
a preview
my study - https://tos.mx/UHpXqwY
The orange label tells you how many shares you can purchase with the budget set in the configuration menu at the current price.
The green label tells you how many shares you can buy at the green arrow.
The blue, red,and white labels tell you the profit that you would have made if you bought in at the green arrow with the number of shares listed in the green label.
Think of all of this as an automatic stop loss study based on moving average lines.
a preview
Code:
input Budget = 2000;
def current_price = close;
def Share_Quantity_purchase_limit = Budget / current_price;
########### Moving Average Lines ###########
input price = close;
input fastLength = 9;
input medLength = 50;
input slowLength = 200;
input displace = 0;
input averageType = AverageType.WILDERS;
plot fastAvg = MovingAverage(averageType, price[-displace], fastLength);
plot medAvg = MovingAverage(averageType, price[-displace], medLength);
plot slowAvg = MovingAverage(averageType, price[-displace], slowLength);
fastAvg.SetDefaultColor(CreateColor(51, 204, 255));
medAvg.SetDefaultColor(CreateColor(255, 95, 95));
slowAvg.SetDefaultColor(Color.WHITE);
fastAvg.SetLineWeight(2);
medAvg.SetLineWeight(2);
slowAvg.SetLineWeight(2);
fastAvg.SetPaintingStrategy(PaintingStrategy.DASHES);
medAvg.SetPaintingStrategy(PaintingStrategy.DASHES);
slowAvg.SetPaintingStrategy(PaintingStrategy.DASHES);
#####################################################
# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
#https://usethinkscript.com/threads/follow-line-indicator.9789/
input BbPeriod = 9;
input BbDeviations = 1;
input UseAtrFilter = yes;
input AtrPeriod = 5;
input HideArrows = no;
def BBUpper = SimpleMovingAvg(close, BbPeriod) + StDev(close, BbPeriod) * BbDeviations;
def BBLower = SimpleMovingAvg(close, BbPeriod) - StDev(close, BbPeriod) * BbDeviations;
def BBSignal = if close > BBUpper then 1 else if close < BBLower then -1 else 0;
def TrendLine =
if BBSignal == 1 and UseAtrFilter == 1 then
Max(low - ATR(AtrPeriod), TrendLine[1])
else if BBSignal == -1 and UseAtrFilter == 1 then
Min(high + ATR(AtrPeriod), TrendLine[1])
else if BBSignal == 0 and UseAtrFilter == 1 then
TrendLine[1]
else if BBSignal == 1 and UseAtrFilter == 0 then
Max(low, TrendLine[1])
else if BBSignal == -1 and UseAtrFilter == 0 then
Min(high, TrendLine[1])
else if BBSignal == 0 and UseAtrFilter == 0 then
TrendLine[1]
else TrendLine[1];
def iTrend = if TrendLine > TrendLine[1] then 1 else if TrendLine < TrendLine[1] then -1 else iTrend[1];
plot buy_price = if iTrend[1] == -1 and iTrend == 1 and !HideArrows then TrendLine else Double.NaN;
buy_price.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
buy_price.SetDefaultColor(Color.GREEN);
buy_price.SetLineWeight(3);
plot sell_price = if iTrend[1] == 1 and iTrend == -1 and !HideArrows then TrendLine else Double.NaN;
sell_price.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
sell_price.SetDefaultColor(Color.WHITE);
sell_price.SetLineWeight(3);
plot buy_arrow = if iTrend[1] == -1 and iTrend == 1 and !HideArrows then TrendLine else Double.NaN;
buy_arrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy_arrow.SetDefaultColor(Color.GREEN);
buy_arrow.SetLineWeight(5);
plot sell_arrow = if iTrend[1] == 1 and iTrend == -1 and !HideArrows then TrendLine else Double.NaN;
sell_arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell_arrow.SetDefaultColor(Color.RED);
sell_arrow.SetLineWeight(5);
###### Math stuff for moving average profit labels ####
def arrow_purchase_price = Budget / iTrend ;
############labels###########
AddLabel(yes, Concat("current price shares = ", Round(Share_Quantity_purchase_limit)), Color.ORANGE);
def greenBuy = if iTrend[1] == -1 and iTrend == 1 and !HideArrows then TrendLine else greenBuy[1];
AddLabel(yes, Concat("buy arrow shares = ", Round(arrow_purchase_price / greenBuy, 0)), Color.GREEN);
AddLabel(yes, Concat("Profit at fastAvg = ", Round(Budget / greenBuy * fastAvg - Budget)), (CreateColor(51, 204, 255)));
AddLabel(yes, Concat("Profit at medAvg = ", Round( Budget / greenBuy * medAvg - Budget)), (CreateColor(255, 95, 95)));
AddLabel(yes, Concat("Profit at slowAvg = ", Round (Budget / greenBuy * slowAvg - Budget )), Color.WHITE);
########### Alerts########################
Alert(buy_arrow, "Time to buy!", Alert.BAR, Sound.Chimes);
Alert(sell_arrow, "Time to sell!", Alert.BAR, Sound.Bell);
def fastAvg_Alert = MovingAverage(averageType, price[-displace], fastLength) crosses MovingAverage(averageType, price[-displace], medLength);
Alert(fastAvg_Alert, "~~~~~fastAvg / medAvg cross over~~~~~", Alert.BAR, Sound.Chimes);
Last edited by a moderator: