Mr_Wheeler
Active member
Hey @Mr_Wheeler
Any way to add targets too, especially variable amount targets like 1:2, 1:2.5, etc.
Come again?
This is what I now use.
https://tos.mx/roSB5Kk
Hey @Mr_Wheeler
Any way to add targets too, especially variable amount targets like 1:2, 1:2.5, etc.
I would have to think about what you're asking but I could create alerts for your script that you could configure/enable in the options. Those are straight forward.The version I added from your post shows the follow line value at the change. That would typically be the stop value for most trades. In the video, TradingView has a risk/rewaard indicator so you can show your risk amount and then use a multiple for your target such as 2:1, 3:1. That is what I was asking about. Thanks again too for your share.
Could you post a script instead of the TOS shareable link...just tried to open to no avail? I swear that function rides the short bus to school some days and just wants to be difficult
# Follow Line Indicator
# Coverted to ToS from TV by bigboss. Original © Dreadblitz
input BbPeriod = 21;
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 = if iTrend[1]==-1 and iTrend==1 and !HideArrows then TrendLine else Double.NaN;
buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
buy.SetDefaultColor(Color.GREEN);
buy.SetLineWeight(3);
plot sell = if iTrend[1]==1 and iTrend==-1 and !HideArrows then TrendLine else Double.NaN;
sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
sell.SetDefaultColor(Color.RED);
sell.SetLineWeight(3);
plot tline = TrendLine;
tline.AssignValueColor(if iTrend > 0 then CreateColor(33,150,243) else CreateColor(255,82,82));
tline.SetLineWeight(2);
############################################
## Define BuySignal and SellSignal above
## or uncomment them out below and set
## them to your buy/sell conditions
##
## If using stops, define them below
############################################
###------------------------------------------------------------------------------------------
input showSignals = yes;
input showLabels = yes;
input showBubbles = yes;
input useStops = no;
input useAlerts = no;
###------------------------------------------------------------------------------------------
############################################
## Create Signals -
## FILL IN THIS SECTION IF NOT DEFINED ABOVE
##
############################################
def BuySignal = iTrend[1]==-1 and iTrend==1; # insert condition to create long position
def SellSignal = iTrend[1]==1 and iTrend==-1; # insert condition to create short position
def BuyStop = if !useStops then 0 else if 0<0 then 1 else 0 ; # insert condition to stop in place of the 0<0
def SellStop = if !useStops then 0 else if 0<0 then 1 else 0 ; # insert condition to stop in place of the 0>0
#######################################
## Maintain the position of trades
#######################################
def CurrentPosition; # holds whether flat = 0 long = 1 short = -1
if (BarNumber()==1) OR isNaN(CurrentPosition[1]) {
CurrentPosition = 0;
}else{
if CurrentPosition[1] == 0 { # FLAT
if (BuySignal) {
CurrentPosition = 1;
} else if (SellSignal){
CurrentPosition = -1;
} else {
CurrentPosition = CurrentPosition[1];
}
} else if CurrentPosition[1] == 1 { # LONG
if (SellSignal){
CurrentPosition = -1;
} else if (BuyStop and useStops){
CurrentPosition = 0;
} else {
CurrentPosition = CurrentPosition[1];
}
} else if CurrentPosition[1] == -1 { # SHORT
if (BuySignal){
CurrentPosition = 1;
} else if (SellStop and useStops){
CurrentPosition = 0;
} else {
CurrentPosition = CurrentPosition[1];
}
} else {
CurrentPosition = CurrentPosition[1];
}
}
def isLong = if CurrentPosition == 1 then 1 else 0;
def isShort = if CurrentPosition == -1 then 1 else 0;
def isFlat = if CurrentPosition == 0 then 1 else 0;
# If not already long and get a BuySignal
Plot BuySig = if (!isLong[1] and BuySignal and showSignals) then 1 else 0;
BuySig.AssignValueColor(color.cyan);
BuySig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySig.SetLineWeight(5);
Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);
Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);
# If not already short and get a SellSignal
Plot SellSig = if (!isShort[1] and SellSignal and showSignals) then 1 else 0;
SellSig.AssignValueColor(color.cyan);
SellSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSig.SetLineWeight(5);
Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Ding);
Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Ding);
# If long and get a BuyStop
Plot BuyStpSig = if (BuyStop and isLong[1] and showSignals and useStops) then 1 else 0;
BuyStpSig.AssignValueColor(color.light_gray);
BuyStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BuyStpSig.SetLineWeight(3);
# If short and get a SellStop
Plot SellStpSig = if (SellStop and isShort[1] and showSignals and useStops) then 1 else 0;
SellStpSig.AssignValueColor(color.light_gray);
SellStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SellStpSig.SetLineWeight(3);
#######################################
## Orders
#######################################
def isOrder = if CurrentPosition == CurrentPosition[1] then 0 else 1; # Position changed so it's a new order
# If there is an order, then the price is the next days close
def orderPrice = if (isOrder and (BuySignal or SellSignal)) then close else orderPrice[1];
#######################################
## Price and Profit
#######################################
def profitLoss;
if (!isOrder or orderPRice[1]==0){
profitLoss = 0;
} else if ((isOrder and isLong[1]) and (SellSig or BuyStpSig)){
profitLoss = close - orderPrice[1];
} else if ((isOrder and isShort[1]) and (BuySig or SellStpSig)) {
profitLoss = orderPrice[1] - close;
} else {
profitLoss = 0;
}
# Total Profit or Loss
def profitLossSum = compoundValue(1, if isNaN(isOrder) or barnumber()==1 then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);
# How many trades won or lost
def profitWinners = compoundValue(1, if isNaN(profitWinners[1]) or barnumber()==1 then 0 else if isOrder and profitLoss > 0 then profitWinners[1] + 1 else profitWinners[1], 0);
def profitLosers = compoundValue(1, if isNaN(profitLosers[1]) or barnumber()==1 then 0 else if isOrder and profitLoss < 0 then profitLosers[1] + 1 else profitLosers[1], 0);
def profitPush = compoundValue(1, if isNaN(profitPush[1]) or barnumber()==1 then 0 else if isOrder and profitLoss == 0 then profitPush[1] + 1 else profitPush[1], 0);
def orderCount = (profitWinners + profitLosers + profitPush) - 1;
# Current Open Trade Profit or Loss
def TradePL = If isLong then Round(((close - orderprice)/TickSize())*TickValue()) else if isShort then Round(((orderPrice - close)/TickSize())*TickValue()) else 0;
# Convert to actual dollars based on Tick Value for bubbles
def dollarProfitLoss = if orderPRice[1]==0 or isNaN(orderPrice[1]) then 0 else round((profitLoss/Ticksize())*Tickvalue());
# Closed Orders dollar P/L
def dollarPLSum = round((profitLossSum/Ticksize())*Tickvalue());
# Split profits or losses by long and short trades
def profitLong = compoundValue(1, if isNan(profitLong[1]) or barnumber()==1 then 0 else if isOrder and isLong[1] then profitLong[1]+dollarProfitLoss else profitLong[1],0);
def profitShort = compoundValue(1, if isNan(profitShort[1]) or barnumber()==1 then 0 else if isOrder and isShort[1] then profitShort[1]+dollarProfitLoss else profitShort[1],0);
def countLong = compoundValue(1, if isNaN(countLong[1]) or barnumber()==1 then 0 else if isOrder and isLong[1] then countLong[1]+1 else countLong[1],0);
def countShort = compoundValue(1, if isNaN(countShort[1]) or barnumber()==1 then 0 else if isOrder and isShort[1] then countShort[1]+1 else countShort[1],0);
# What was the biggest winning and losing trade
def biggestWin = compoundValue(1, if isNaN(biggestWin[1]) or barnumber()==1 then 0 else if isOrder and (dollarProfitLoss > 0) and (dollarProfitLoss > biggestWin[1]) then dollarProfitLoss else biggestWin[1], 0);
def biggestLoss = compoundValue(1, if isNaN(biggestLoss[1]) or barnumber()==1 then 0 else if isOrder and (dollarProfitLoss < 0) and (dollarProfitLoss < biggestLoss[1]) then dollarProfitLoss else biggestLoss[1], 0);
# What percent were winners
def PCTWin = round((profitWinners/orderCount)*100,2);
# Average trade
def avgTrade = round((dollarPLSum/orderCount),2);
#######################################
## Create Labels
#######################################
AddLabel(showLabels, GetSymbol()+" Tick Size: "+TickSize()+" Value: "+TickValue(), color.white);
AddLabel(showLabels, "Closed Orders: " + orderCount + " P/L: " + AsDollars(dollarPLSum), if dollarPLSum > 0 then Color.GREEN else if dollarPLSum< 0 then Color.RED else Color.GRAY);
AddLabel(if !IsNan(orderPrice) and showLabels then 1 else 0, "Closed+Open P/L: "+ AsDollars(TradePL+dollarPLSum), if ((TradePL+dollarPLSum) > 0) then color.green else if ((TradePL+dollarPLSum) < 0) then color.red else color.gray);
AddLabel(showLabels, "Avg per Trade: "+ AsDollars(avgTrade), if avgTrade > 0 then Color.Green else if avgTrade < 0 then Color.RED else Color.GRAY);
AddLabel(showLabels, "Winners: "+ PCTWin +"%",if PCTWin > 50 then color.green else if PCTWin > 40 then color.yellow else color.gray);
AddLabel(showLabels, "MaxUp: "+ AsDollars(biggestWin) +" MaxDown: "+AsDollars(biggestLoss), color.white);
AddLabel(showLabels, "Long Profit: " +AsDollars(profitLong), if profitLong > 0 then color.green else if profitLong < 0 then color.red else color.gray);
AddLabel(showLabels, "Short Profit: " +AsDollars(profitShort), if profitShort > 0 then color.green else if profitShort < 0 then color.red else color.gray);
AddLabel(if !IsNan(CurrentPosition) and showLabels then 1 else 0, "Open: "+ (If isLong then "Bought" else "Sold") + " @ "+orderPrice, color.white);
AddLabel(if !IsNan(orderPrice) and showLabels then 1 else 0, "Open Trade P/L: "+ AsDollars(TradePL), if (TradePL > 0) then color.green else if (TradePl < 0) then color.red else color.gray);
#######################################
## Chart Bubbles for Profit/Loss
#######################################
AddChartBubble(showSignals and showBubbles and isOrder and isLong[1], low, "$"+dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else color.Red, 0);
AddChartBubble(showSignals and showBubbles and isOrder and isShort[1], high, "$"+dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else color.Red, 1);
#AssignPriceColor(if CurrentPosition == 1 then color.green else if CurrentPosition == -1 then color.red else color.gray);
Could you post a script instead of the TOS shareable link...just tried to open to no avail? I swear that function rides the short bus to school some days and just wants to be difficult
# 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);
plot tline = TrendLine;
tline.AssignValueColor(if iTrend > 0 then CreateColor(33,150,243) else CreateColor(255,82,82));
tline.SetPaintingStrategy(PaintingStrategy.DASHES);
tline.SetLineWeight(2);
########### Alerts
Alert(buy_arrow, "Time to buy!", Alert.Bar, Sound.Chimes);
Alert(sell_arrow, "Time to sell!", Alert.Bar, Sound.Bell);
Added a P/L to the study on the version from post #3
@bigboss @JP782 Thank you guys so much for sharing this. Question, how do I adjust the values to make this react much quicker? I've messed with it myself in the settings and it doesn't really react quicker and some values I enter might make the indicator even disappear. In this screenshot, you can see how the up arrow appears at 10AM and then the down arrow appear at 11:30AM. Any way to adjust it to make these arrows appear a little sooner? To be specific a few candles sooner would provide better entries and exits.Hi @JP782 - Here is the follow line indicator implemented in thinkscript. I'm curious to hear your thoughts on the strategy!
Code:# Follow Line Indicator # Coverted to ToS from TV by bigboss. Original © Dreadblitz input BbPeriod = 21; 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 = if iTrend[1]==-1 and iTrend==1 and !HideArrows then TrendLine else Double.NaN; buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP); buy.SetDefaultColor(Color.GREEN); buy.SetLineWeight(3); plot sell = if iTrend[1]==1 and iTrend==-1 and !HideArrows then TrendLine else Double.NaN; sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); sell.SetDefaultColor(Color.RED); sell.SetLineWeight(3); plot tline = TrendLine; tline.AssignValueColor(if iTrend > 0 then CreateColor(33,150,243) else CreateColor(255,82,82)); tline.SetLineWeight(2);
@Mr_Wheeler - just a simplr scan for a given time increment such as 15min, when the follow line and/or (if possible to combine 2 indicators in one scan) the Hull Suite bothturn the same color. I would be happy with a scan that just shows the change from red to blue on the follow line on a 15min time frame. I have fooled with the parameters available to scan for with the follow line but can't seem to get any matches so I know I am doing something wrong. Thanks for any assistance.What would you want in such a scan?
At its core, this indicator is using a ratcheting trailstop that ratchets when price pokes a 1 standard deviation bollinger band. By default, the trailstop ratches to a 5 period 1 ATR distance away from price. To make it more responsive, disabling the ATR filter makes a big difference because it rachets the line to the high/low instead of also buffering in ATR.@bigboss @JP782 Thank you guys so much for sharing this. Question, how do I adjust the values to make this react much quicker? I've messed with it myself in the settings and it doesn't really react quicker and some values I enter might make the indicator even disappear. In this screenshot, you can see how the up arrow appears at 10AM and then the down arrow appear at 11:30AM. Any way to adjust it to make these arrows appear a little sooner? To be specific a few candles sooner would provide better entries and exits.
input bbdeviations = 1.0;
Have you tried something like this:@Mr_Wheeler - just a simplr scan for a given time increment such as 15min, when the follow line and/or (if possible to combine 2 indicators in one scan) the Hull Suite bothturn the same color. I would be happy with a scan that just shows the change from red to blue on the follow line on a 15min time frame. I have fooled with the parameters available to scan for with the follow line but can't seem to get any matches so I know I am doing something wrong. Thanks for any assistance.
follow_line_indicator()."buy" is equal to 1 or follow_line_indicator()."sell" is equal to 1
Thank you I will give this a try tonight.At its core, this indicator is using a ratcheting trailstop that ratchets when price pokes a 1 standard deviation bollinger band. By default, the trailstop ratches to a 5 period 1 ATR distance away from price. To make it more responsive, disabling the ATR filter makes a big difference because it rachets the line to the high/low instead of also buffering in ATR.
The second important setting I've found to speed it up is reduce the bb standard deviations to 0.1 so that the line ratches more often.
To do the second change you'll need to modify the input bbdeviations line to support values between 0 and 1 like this:
Code:input bbdeviations = 1.0;
hope that helps!
So I did disable ATR and set the bbdeviation to .1 which those arrows did appear like 10 minutes/2 candles earlier. I guess I'll be also using the 1 minute time frame for an even earlier entry lol. Thank you againAt its core, this indicator is using a ratcheting trailstop that ratchets when price pokes a 1 standard deviation bollinger band. By default, the trailstop ratches to a 5 period 1 ATR distance away from price. To make it more responsive, disabling the ATR filter makes a big difference because it rachets the line to the high/low instead of also buffering in ATR.
The second important setting I've found to speed it up is reduce the bb standard deviations to 0.1 so that the line ratches more often.
To do the second change you'll need to modify the input bbdeviations line to support values between 0 and 1 like this:
Code:input bbdeviations = 1.0;
hope that helps!
c_follow_line_with_price_label()."buy_arrow" is true within 15 bars
If you don't mind, can you share this chart? Thanks!I haven't done any modifications so far but in my flex chart I have two studies. A momentum and a 3 day moving average study.
https://tos.mx/kWOYufR
https://tos.mx/KnWRVYT
If you took profit with the 9 MDA line's current price with you getting into the trade with purchasing price your study told you/me to buy, then you would have 4000 dollars of profit at the time of my screen shot.
https://usethinkscript.com/threads/what-is-the-best-oscillator-for-tops-and-bottoms.10133/post-90400If you don't mind, can you share this chart? Thanks!
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.