Subhag Ghosh Trend Signal For ThinkOrSwim

Hey @samer800 excellent job!! I found this script on TV and it seems fairly easy to covert, but I am breaking my head over this. If you could help with this, I would really appreciate it!!! Thank you in advanc!

This is the script:

//Trend Analyzer can be used in gauge the market underlying current.
// Use 3x to 4x higher time frame and trade in direction of the trend.
// e.g. If you are trading on 3 min chart and you can set indicator time frame to 15 min, if you see the indicator is buy, you should look for buy opportunity instead of sell and vice versa.

//@version=3
study("Subhag Ghosh Trend Signal", overlay=false)
ha_t = ticker
col_red = #ff0000
col_green = #00ff00
fast_length = input(title="Fast Length", defval=3)
slow_length = input(title="Slow Length", defval=10)
src = input(title="Source", defval=close)
res_60 = input('15', title="Higher Time Frame 1 ")
trend_60 = security(ha_t, res_60, ((ema(src, fast_length) - ema(src, slow_length))/src)*100)
prev_trend_60 = security(ha_t, res_60, ((ema(src[5], fast_length) - ema(src[5], slow_length))/src[5])*100)
trend_status_60 = trend_60 > prev_trend_60
plot(1, title="Trend Visualizer", color=(trend_status_60 ? col_green : col_red), linewidth=24, transp=0)
check the below. I added options to change the mov avg type and aggregation.

CSS:
#//Trend Analyzer can be used in gauge the market underlying current.
#// Use 3x to 4x higher time frame and trade in direction of the trend.
#// e.g. If you are trading on 3 min chart and you can set indicator time frame to 15 min, if you see the indicator is buy, you should look for buy opportunity instead of sell and vice versa.
#//@version=3
#study("Subhag Ghosh Trend Signal", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 11/2022 - request from useThinkscript.com memeber
declare lower;
input fast_length = 3;    # "Fast Length"
input slow_length = 10;    # "Slow Length"
input MovAvg = AverageType.EXPONENTIAL;
input agg = AggregationPeriod.FIFTEEN_MIN;

def na = Double.NaN;
def src = close(Period=agg);
def fast_EMA = MovingAverage(MovAvg, src, fast_length);
def slow_EMA =  MovingAverage(MovAvg, src, slow_length);
def prev_fast_EMA = MovingAverage(MovAvg, src[5], fast_length);
def Prev_slow_EMA =  MovingAverage(MovAvg, src[5], slow_length);

def trend_60 = ((fast_EMA -slow_EMA)/src)*100;
def prev_trend_60 = ((prev_fast_EMA - Prev_slow_EMA )/src[5])*100;

def trend_status_60 = trend_60 > prev_trend_60;
plot "0" =  if isNaN(close) then na else 0;
"0".AssignValueColor(if trend_status_60 then Color.GREEN else Color.RED);
"0".SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
plot "1" = if isNaN(close) then na else 1;    # "Trend Visualizer"
"1".SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
"1".AssignValueColor(if trend_status_60 then Color.GREEN else Color.RED);

#----- End Code
 
check the below. I added options to change the mov avg type and aggregation.

CSS:
#//Trend Analyzer can be used in gauge the market underlying current.
#// Use 3x to 4x higher time frame and trade in direction of the trend.
#// e.g. If you are trading on 3 min chart and you can set indicator time frame to 15 min, if you see the indicator is buy, you should look for buy opportunity instead of sell and vice versa.
#//@version=3
#study("Subhag Ghosh Trend Signal", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 11/2022 - request from useThinkscript.com memeber
declare lower;
input fast_length = 3;    # "Fast Length"
input slow_length = 10;    # "Slow Length"
input MovAvg = AverageType.EXPONENTIAL;
input agg = AggregationPeriod.FIFTEEN_MIN;

def na = Double.NaN;
def src = close(Period=agg);
def fast_EMA = MovingAverage(MovAvg, src, fast_length);
def slow_EMA =  MovingAverage(MovAvg, src, slow_length);
def prev_fast_EMA = MovingAverage(MovAvg, src[5], fast_length);
def Prev_slow_EMA =  MovingAverage(MovAvg, src[5], slow_length);

def trend_60 = ((fast_EMA -slow_EMA)/src)*100;
def prev_trend_60 = ((prev_fast_EMA - Prev_slow_EMA )/src[5])*100;

def trend_status_60 = trend_60 > prev_trend_60;
plot "0" =  if isNaN(close) then na else 0;
"0".AssignValueColor(if trend_status_60 then Color.GREEN else Color.RED);
"0".SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
plot "1" = if isNaN(close) then na else 1;    # "Trend Visualizer"
"1".SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
"1".AssignValueColor(if trend_status_60 then Color.GREEN else Color.RED);

#----- End Code
Excellent!! Spot on!!! Thank you again!
 
@Luna - I hate to be that guy.. unsolicited word of caution - my backtesting results had shown some discrepancies.

B7zUo7i.png
 
@Luna - I hate to be that guy.. unsolicited word of caution - my backtesting results had shown some discrepancies.

B7zUo7i.png
expected to have some discrepancies between TV and TOS since both handle the data source differently. may someone can look to the code further.

I just did minor change in the code below you may try. I added lookback period option so you can adjust mom length. :)

CSS:
#//Trend Analyzer can be used in gauge the market underlying current.
#// Use 3x to 4x higher time frame and trade in direction of the trend.
#// e.g. If you are trading on 3 min chart and you can set indicator time frame to 15 min, if you see the indicator is buy, you should look for buy opportunity instead of sell and vice versa.
#//@version=3
#study("Subhag Ghosh Trend Signal", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 11/2022 - request from useThinkscript.com memeber
declare lower;
input lookbackPeriod = 5;
input fast_length = 3;    # "Fast Length"
input slow_length = 10;    # "Slow Length"
input MovAvg = AverageType.EXPONENTIAL;
input agg = AggregationPeriod.FIFTEEN_MIN;

def na = Double.NaN;
def src = close(Period=agg);
def src5 = close(Period=agg)[lookbackPeriod];
def fast_EMA = MovingAverage(MovAvg, src, fast_length);
def slow_EMA =  MovingAverage(MovAvg, src, slow_length);
def prev_fast_EMA = MovingAverage(MovAvg, src5, fast_length);
def Prev_slow_EMA =  MovingAverage(MovAvg, src5, slow_length);

def trend_60 = ((fast_EMA -slow_EMA)/src)*100;
def prev_trend_60 = ((prev_fast_EMA - Prev_slow_EMA )/src5)*100;

def trend_status_60 = trend_60 > prev_trend_60;
plot "0" =  if isNaN(close) then na else 0;
"0".AssignValueColor(if trend_status_60 then Color.GREEN else Color.RED);
"0".SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
plot "1" = if isNaN(close) then na else 1;    # "Trend Visualizer"
"1".SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
"1".AssignValueColor(if trend_status_60 then Color.GREEN else Color.RED);


# End Code
 
expected to have some discrepancies between TV and TOS since both handle the data source differently. may someone can look to the code further.

I just did minor change in the code below you may try. I added lookback period option so you can adjust mom length. :)

CSS:
#//Trend Analyzer can be used in gauge the market underlying current.
#// Use 3x to 4x higher time frame and trade in direction of the trend.
#// e.g. If you are trading on 3 min chart and you can set indicator time frame to 15 min, if you see the indicator is buy, you should look for buy opportunity instead of sell and vice versa.
#//@version=3
#study("Subhag Ghosh Trend Signal", overlay=false)
# Converted and mod by Sam4Cok@Samer800 - 11/2022 - request from useThinkscript.com memeber
declare lower;
input lookbackPeriod = 5;
input fast_length = 3;    # "Fast Length"
input slow_length = 10;    # "Slow Length"
input MovAvg = AverageType.EXPONENTIAL;
input agg = AggregationPeriod.FIFTEEN_MIN;

def na = Double.NaN;
def src = close(Period=agg);
def src5 = close(Period=agg)[lookbackPeriod];
def fast_EMA = MovingAverage(MovAvg, src, fast_length);
def slow_EMA =  MovingAverage(MovAvg, src, slow_length);
def prev_fast_EMA = MovingAverage(MovAvg, src5, fast_length);
def Prev_slow_EMA =  MovingAverage(MovAvg, src5, slow_length);

def trend_60 = ((fast_EMA -slow_EMA)/src)*100;
def prev_trend_60 = ((prev_fast_EMA - Prev_slow_EMA )/src5)*100;

def trend_status_60 = trend_60 > prev_trend_60;
plot "0" =  if isNaN(close) then na else 0;
"0".AssignValueColor(if trend_status_60 then Color.GREEN else Color.RED);
"0".SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
plot "1" = if isNaN(close) then na else 1;    # "Trend Visualizer"
"1".SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
"1".AssignValueColor(if trend_status_60 then Color.GREEN else Color.RED);


# End Code
@samer800 - Yes! Thank you :) .. The screenshot that I posted is from TV - source code definitely could use a facelift.
TBH Nadaraya-Watson: Rational Quadratic Kernel is more reliable.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
485 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