A study that combines the "follow line indicator" with a study that has 3-M.As, and labels that tell you what profit you can make at each of the M.A

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
BOVwTPA.png

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:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I added "profit @ green label" to show you how much money you would be up or down if you bought in at the green arrow. You can use that information to decide where you want to set stop losses with the help of the other labels.
https://tos.mx/nfYzKba
jpbP2sV.png

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###########




def greenBuy = if iTrend[1] == -1 and iTrend == 1 and !HideArrows then TrendLine else greenBuy[1];

AddLabel(yes, Concat("current price shares = ", Round(Share_Quantity_purchase_limit)), Color.ORANGE);
AddLabel(yes, Concat("buy arrow shares = ", Round(arrow_purchase_price / greenBuy, 0)), Color.GREEN);
AddLabel(yes, Concat("price = ", Round (greenBuy)), Color.GREEN);
AddLabel(yes, Concat("Profit @ GreenArw = ", Round (Budget / greenBuy  * current_price - Budget)), Color.GREEN);
AddLabel(yes, Concat("MovAvg = ", Round(fastAvg)), (CreateColor(51, 204, 255)));
AddLabel(yes, Concat("Profit @ fastAvg = ", Round(Budget / greenBuy  * fastAvg - Budget)), (CreateColor(51, 204, 255)));
AddLabel(yes, Concat("MovAvg = ", Round(medAvg)), (CreateColor(255, 95, 95)));
AddLabel(yes, Concat("Profit @ medAvg = ", Round( Budget / greenBuy  * medAvg - Budget)), (CreateColor(255, 95, 95)));
AddLabel(yes, Concat("MovAvg = ", Round (slowAvg)), Color.WHITE);
AddLabel(yes, Concat("Profit @ 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.Ring);

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:
@Mr_Wheeler Thank you for your recent contributions to the community. I believe this latest contribution is missing "Declare Lower". Without it, the study will display on the Upper portion of the Chart.

Code:
Declare Lower;

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###########




def greenBuy = if iTrend[1] == -1 and iTrend == 1 and !HideArrows then TrendLine else greenBuy[1];

AddLabel(yes, Concat("current price shares = ", Round(Share_Quantity_purchase_limit)), Color.ORANGE);
AddLabel(yes, Concat("buy arrow shares = ", Round(arrow_purchase_price / greenBuy, 0)), Color.GREEN);
AddLabel(yes, Concat("price = ", Round (greenBuy)), Color.GREEN);
AddLabel(yes, Concat("Profit @ GreenArw = ", Round (Budget / greenBuy  * current_price - Budget)), Color.GREEN);
AddLabel(yes, Concat("MovAvg = ", Round(fastAvg)), (CreateColor(51, 204, 255)));
AddLabel(yes, Concat("Profit @ fastAvg = ", Round(Budget / greenBuy  * fastAvg - Budget)), (CreateColor(51, 204, 255)));
AddLabel(yes, Concat("MovAvg = ", Round(medAvg)), (CreateColor(255, 95, 95)));
AddLabel(yes, Concat("Profit @ medAvg = ", Round( Budget / greenBuy  * medAvg - Budget)), (CreateColor(255, 95, 95)));
AddLabel(yes, Concat("MovAvg = ", Round (slowAvg)), Color.WHITE);
AddLabel(yes, Concat("Profit @ 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.Ring);

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


Hope this helps...

Good Luck and Good Trading...
 
Here's an updated script that has more labels.

https://tos.mx/TRy7B25

8j99uuP.png
Hi thanks for all your effort and help. Can i get alerts on my phone and can i get alerts when the day arrow comes on without I have to click on the stock? oftentimes I don't see the stock early enough. Thanks in advance for your response.
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

BOVwTPA.png



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);
Hi Mr. Wheeler, Can i get the alerts for DAY on my phone? And how do I get alerts to notify me without having to click on the stock in TOS? I would like the alert immediately as it signals the arrow. Thank in advance for your response.
 
I added "profit @ green label" to show you how much money you would be up or down if you bought in at the green arrow. You can use that information to decide where you want to set stop losses with the help of the other labels.


https://tos.mx/nfYzKba
jpbP2sV.png




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###########




def greenBuy = if iTrend[1] == -1 and iTrend == 1 and !HideArrows then TrendLine else greenBuy[1];

AddLabel(yes, Concat("current price shares = ", Round(Share_Quantity_purchase_limit)), Color.ORANGE);
AddLabel(yes, Concat("buy arrow shares = ", Round(arrow_purchase_price / greenBuy, 0)), Color.GREEN);
AddLabel(yes, Concat("price = ", Round (greenBuy)), Color.GREEN);
AddLabel(yes, Concat("Profit @ GreenArw = ", Round (Budget / greenBuy  * current_price - Budget)), Color.GREEN);
AddLabel(yes, Concat("MovAvg = ", Round(fastAvg)), (CreateColor(51, 204, 255)));
AddLabel(yes, Concat("Profit @ fastAvg = ", Round(Budget / greenBuy  * fastAvg - Budget)), (CreateColor(51, 204, 255)));
AddLabel(yes, Concat("MovAvg = ", Round(medAvg)), (CreateColor(255, 95, 95)));
AddLabel(yes, Concat("Profit @ medAvg = ", Round( Budget / greenBuy  * medAvg - Budget)), (CreateColor(255, 95, 95)));
AddLabel(yes, Concat("MovAvg = ", Round (slowAvg)), Color.WHITE);
AddLabel(yes, Concat("Profit @ 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.Ring);

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);
I added "profit @ green label" to show you how much money you would be up or down if you bought in at the green arrow. You can use that information to decide where you want to set stop losses with the help of the other labels.


https://tos.mx/nfYzKba
jpbP2sV.png




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###########




def greenBuy = if iTrend[1] == -1 and iTrend == 1 and !HideArrows then TrendLine else greenBuy[1];

AddLabel(yes, Concat("current price shares = ", Round(Share_Quantity_purchase_limit)), Color.ORANGE);
AddLabel(yes, Concat("buy arrow shares = ", Round(arrow_purchase_price / greenBuy, 0)), Color.GREEN);
AddLabel(yes, Concat("price = ", Round (greenBuy)), Color.GREEN);
AddLabel(yes, Concat("Profit @ GreenArw = ", Round (Budget / greenBuy  * current_price - Budget)), Color.GREEN);
AddLabel(yes, Concat("MovAvg = ", Round(fastAvg)), (CreateColor(51, 204, 255)));
AddLabel(yes, Concat("Profit @ fastAvg = ", Round(Budget / greenBuy  * fastAvg - Budget)), (CreateColor(51, 204, 255)));
AddLabel(yes, Concat("MovAvg = ", Round(medAvg)), (CreateColor(255, 95, 95)));
AddLabel(yes, Concat("Profit @ medAvg = ", Round( Budget / greenBuy  * medAvg - Budget)), (CreateColor(255, 95, 95)));
AddLabel(yes, Concat("MovAvg = ", Round (slowAvg)), Color.WHITE);
AddLabel(yes, Concat("Profit @ 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.Ring);

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);
Hi is there a scan for Day arrow alerts? Thanks!
 
for some reason putting in buy arrow is true within any amount of bars always give me "No matching symbols". Something is off about the scan
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
206 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top