SLIM Ribbon Indicator for ThinkorSwim

@markos How can I convert this study into a strategy with buying and selling orders on the buy_signal and sell_signal? I tried adding the following but it did not work.

Code:
AddOrder(OrderType.BUY_TO_OPEN, Buy_Signal, tickColor = color.dark_green, arrowColor =  color.dark_green, name = "Buy 100");
 

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

@jrob0124 Take a look at the strategy section of this code: https://usethinkscript.com/threads/true-momentum-oscillator-for-thinkorswim.15/post-15141

Hopefully it will give you some inspiration.

Thanks @BenTen!

I did look at the above and compared it with the original indicator and the only additions it appears are two defs for buy\sell and two AddOrder method calls. I am very new to ThinkScript, though I have scripted in other languages before.

I tested both def conditions below and neither worked and remove the painting of the indicator altogether. Any guidance would be much appreciated.

Code:
# Backtesting Code
#def buy_test = Buy_Signal crosses above Momentum_Up;
def buy_test =  buysignal[1] == 0 and buysignal == 1;

AddOrder(OrderType.BUY_AUTO, condition = buy_test, price = close, 100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
.
 
@jrob0124 did you add the whole thing as a new strategy? Be sure to do that instead of adding on to your existing indicator.
 
@jrob0124 did you add the whole thing as a new strategy? Be sure to do that instead of adding on to your existing indicator.

And thats what happens when you try to script too late in the day LOL. Yes, I completely overlooked creating it as a strategy and was trying to update the indicator.

Now, I have it working, however, I am not sure it is the best way. Below is the code I am using. I had to go look back in the array for it to add the order to the correct bar. For some reason, it continued to add the order on the bar after the signal. Any thoughts?

Code:
AddOrder(OrderType.BUY_AUTO, condition = buy_signal[-1], price = close, 100, tickcolor = Color.DARK_GREEN, arrowcolor = Color.dark_GREEN, name = "Buy");
AddOrder(OrderType.SELL_AUTO, condition = Momentum_Down[-1], price = close, 0, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Sell");
 
I do not write scripts but am a user of scripts... I spend hours thumbing through one note and a I build charts. Amazing ideas on one note gads few limitations and such a great place to becoming acquainted with script. https://onedrive.live.com/redir?resid=2FF733D1BA1E1E79!404&authkey=!ABOXXFyQg1iUqFk&page=View&wd=target(01. LoungeArchive/Apr 2019.one|3fe5b787-b6ac-41a4-a449-9c825bce20df/Wednesday, April 10, 2019|0adf2906-0fef-4b2b-b3ee-383bf6fb3a5a/)

What a phenomenal resource, thank you!
 
I was doing some basic back testing, comparing this versus SuperTrend on various time frames, with ST appearing to be a clear winner in most cases.
 
I've been experimenting with a further modified version of the Slim Ribbon indicator that Markos had originally customized. I've converted it to a strategy along with integrating the SuperTrend ATR, slightly modified the sell signal conditions and a couple other minor tweaks. This is a very early beta version that still requires a good amount of testing and modification to the code, so I'm looking for other members they may be interested in trying it out and offering feedback.

All of the testing I've done so far has been long positions only (no short entries). I've been using this intraday primarily on 5min, 15min & 78 min time frames with pretty decent results (see screenshot below). Generally, I'll use the 78min for a short term swing trend confirmation, 15min to confirm intraday trend reversals & 5min for entries/exits. Buy signals are currently based on the parameters from the original indicator, while sell signals are a combination of the SuperTrendATR crossover and/or the sell signal parameter from the original study. I pretty much only pay attention to the strategy order entries/exit signals & not so much the arrows fired by the study (although I've left them active as early "warning" signals of trend changes in addition to testing/debugging purposes).

Most of the backtesting & performance analysis I've done so far has been on the /ES and haven't done any extensive backtesting on equities, although I have been using it on equities during my live trading as a trend confirmation tool and it's proved to be pretty helpful so far. Would be interested to do further equity backtesting with hard performance analysis.

As far as settings, I've set the default values to the settings that I've seen the best performance on based on the backtests so far (ATR mult: 1.2 & natr: 3). But, I'd be interested to see the performance based on other tweaks to the settings.

Note: this is a VERY, VERY early version of the script - so please keep that in mind when testing.

Early Performance Assessment:

Symbol: /ES
TimeFrame: 30 day/15min
PositionSize: 1 contract

eUiQnJV.png


Study link: https://tos.mx/veElNOu

Python:
#################################################################################
# SlimRibbonSuperTrend                                                          
# SlimRibbon study with SuperTrend ATR                                          
# Author: Eddielee394                                                           
# Version: 0.2                                                                  
# inspired by: SlimRibbon by Slim Miller and further customized by Markos       
#################################################################################

SetChartType(ChartType.CANDLE_TREND);

input price = close;

input superfast_length = 8;

input fast_length = 13;

input slow_length = 21;

input displace = 0;

input atrMult = 1.2;
#hint atrMult: increases the sensitivity of the ATR line

input nATR = 3;
#hint nATR:

input avgType = AverageType.HULL;
#hint avgType: sets the average type used to calculate the SuperTrendATR

input enableAlerts = no;
#hint enableAlerts: disables all alerts

input hideMovingAverages = yes;
#hint hideMovingAverages: hides all the moving average lines from the slimRibbon

input hideSuperTrendAtr = no;
#hint hideSuperTrendAtr: hides the SuperTrend ATR line

input tradesize = 1;

def ATR = MovingAverage(avgType, TrueRange(high, close, low), nATR);

def UP = HL2 + (atrMult * ATR);

def DN = HL2 + (-atrMult * ATR);

def ST = if close < ST[1] then UP else DN;

plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
SuperTrend.SetHiding(hideSuperTrendAtr);

def SuperTrendUP = if ST crosses below close[-1] then 1 else 0;
def isSuperTrendUP = SuperTrend > close;
def SuperTrendDN = if ST crosses above close[-1] then 1 else 0;
def isSuperTrendDN = SuperTrend < close;

#moving averages
def mov_avg8 = ExpAverage(price[-displace], superfast_length);

def mov_avg13 = ExpAverage(price[-displace], fast_length);

def mov_avg21 = ExpAverage(price[-displace], slow_length);

plot Superfast = mov_avg8;
Superfast.SetHiding(hideMovingAverages);

plot Fast = mov_avg13;
Fast.SetHiding(hideMovingAverages);

plot Slow = mov_avg21;
Slow.SetHiding(hideMovingAverages);


def buy = mov_avg8 > mov_avg13 and mov_avg13 > mov_avg21 and low > mov_avg8;

def stopbuy = mov_avg8 <= mov_avg13;

def buynow = !buy[1] and buy;

def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);

plot Buy_Signal = buysignal[1] == 0 and buysignal == 1;

Buy_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Buy_Signal.SetDefaultColor(Color.GREEN);

Buy_Signal.HideTitle();

plot Momentum_Down = buysignal[1] == 1 and buysignal == 0;

Momentum_Down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Momentum_Down.SetDefaultColor(Color.YELLOW);

Momentum_Down.HideTitle();

def sell = mov_avg8 < mov_avg13 and mov_avg13 < mov_avg21 and high < mov_avg8;

def stopsell = mov_avg8 >= mov_avg13;

def sellnow = !sell[1] and sell;

def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);


plot Sell_Signal = sellsignal[1] == 0 and sellsignal;

Sell_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Sell_Signal.SetDefaultColor(Color.RED);

Sell_Signal.HideTitle();

plot Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;

Momentum_Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

Momentum_Up.SetDefaultColor(Color.YELLOW);

Momentum_Up.HideTitle();

plot Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;

Colorbars.Hide();

Colorbars.DefineColor("Buy_Signal_Bars", Color.GREEN);

Colorbars.DefineColor("Sell_Signal_Bars", Color.RED);

Colorbars.DefineColor("Neutral", Color.YELLOW);

AssignPriceColor(if Colorbars == 1 then Colorbars.Color("buy_signal_bars") else if Colorbars == 2 then Colorbars.Color("Sell_Signal_bars") else  Colorbars.Color("neutral"));

#Orders
def sellTrigger = if SuperTrendDN or Sell_Signal then 1 else 0;
def buyTrigger = Buy_Signal;

AddOrder(OrderType.BUY_TO_OPEN, condition = buyTrigger, price = close, tradeSize = tradesize, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Buy");

AddOrder(OrderType.SELL_TO_CLOSE, condition = sellTrigger, price = close[-1], tradeSize = tradesize, tickcolor = Color.PINK, arrowcolor = Color.DARK_RED, name = "Sell");


#Alerts

Alert(condition = enableAlerts and buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

Alert(condition = enableAlerts and buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

Alert(condition = enableAlerts and sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

Alert(condition = enableAlerts and sellsignal[1] == 1 and sellsignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

#end strategy
 
It's looking good keep at it. I think the best quick implementation would be sorting out consolidated periods. It losses lots of gains to chop looking at the floating p/l. It would also save you a little on fees/poor fills.
 
So I have been testing something similar as far as trend trading, and I think there are a few tools to help with the elimination of chop trades. I will see what I can produce for you testing out the z-score ( https://tos.mx/jXHKqap ) and i will test out ergodic
 
-- Will this work for intraday?
-- Will this work for SPY?

Please refer to the original post.


All of the testing I've done so far has been long positions only (no short entries). I've been using this intraday primarily on 5min, 15min & 78 min time frames with pretty decent results (see screenshot below).

Most of the backtesting & performance analysis I've done so far has been on the /ES and haven't done any extensive backtesting on equities, although I have been using it on equities during my live trading as a trend confirmation tool and it's proved to be pretty helpful so far. Would be interested to do further equity backtesting with hard performance analysis.
 
I think the best quick implementation would be sorting out consolidated periods. It losses lots of gains to chop looking at the floating p/l.
Yeah, most definitely. That's one of the caveats with this strategy, is that performance suffers hard during choppy periods. Lots of churn. Also, I don't have hard data to support this thesis but I feel like there's a lower win probability when a buy signal triggers while price is below the ATR. I was thinking about tweaking the buy conditions a bit to avoid those scenarios, but wanted to compile some more data on this current version of the strategy first.


So I have been testing something similar as far as trend trading, and I think there are a few tools to help with the elimination of chop trades. I will see what I can produce for you testing out the z-score ( https://tos.mx/jXHKqap ) and i will test out ergodic
Cool, sounds good. Whatever you're willing to share would be super helpful.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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