A trend, momentum and cycle Trading System v3.0 (CSA)

i meant to create a strategy from this rather than an indicator
# A very basic order entry, repaint is a problem, as the strategy looks great on backtest but not so good in real time
# I used a 2 min time frame
#END OF CSA - trend, a momentum and a cycle based indicator for ThinkorSwim V3.2
#This is strictly a bullish by order type, adding this code at the end of the study, copy and selecting strategy tab create strategy, paste code.
input Contracts = 5;
def open_order = bullish[-displace];
def close_order = bearish[-displace];
#ORDERS
AddOrder(type = OrderType.BUY_TO_OPEN, open_order, tradeSize = Contracts, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(type = OrderType.SELL_TO_CLOSE, close_order, tradeSize = Contracts, name = "Close", tickcolor = Color.GRAY, arrowcolor = Color.GRAY);
 
Newbie here. Trying to learn how to create my own strategy within TOS. How are you backtesting, I don't see a script? Is the backtesting not in TOS? Also, does any of the studies repaint which would alter the backtest?
 
Newbie here. Trying to learn how to create my own strategy within TOS. How are you backtesting, I don't see a script? Is the backtesting not in TOS? Also, does any of the studies repaint which would alter the backtest?
Click on Studies then you will see a TAB for Strategies, click Create, then you must include some sort of AddOrder statement at the end of what ever you are using to signal the buy or sell
 
First off, thanks so much for the work you put into this @diazlaz!

Second, anyone else not able to get the global color settings to actually change the color of the paintbars function? I have no experience working with that function in thinkscript, so I wasn't able to fix it myself, either.
 
I am brand new here myself working on a different coding task, but I wonder during back-testing the scoring threshold numbers were changed... Maybe at one point there were more than 3 Bullish or Bearish indicators needed to color bars...

Have you tried increasing the thresholds and tested the results?

How would one go about editing the code to tweak the thresholds required to paint the bars?
 
As a very small contribution to the project, here is a modification I made to the paintbars section of the code in order to "show more gray" in the choppy areas as an indication you may want to stay out of the market (or trade using a strategy designed for choppiness). All it does is paint bars light gray if the ADX indicates it is a choppy market, and only paints green/red if it is trending. Just copy/paste this over the equivalent section in @diazlaz phenomenal code:

Code:
#COLORBARS
AssignPriceColor(
if PaintBars then
    if ADXPaintBarsMode then if ADX > ADXTrending then COLOR.ORANGE else COLOR.DARK_GRAY
    else
    if ADX < ADXTrending then color.light_gray
    else
    if bullish then COLOR.uptick else if bearish then COLOR.downtick
     else
     if enableNeutralMACDPainter then
      if macd_Val_1 > macd_Avg1 then COLOR.DARK_GREEN else COLOR.DARK_RED
     else
    COLOR.GRAY
else COLOR.CURRENT);
 
What does the Cyan/Grey/Yellow bar at the bottom of the chart indicate?
It indicates if the ADX is indicating a trending or choppy market. Gray means choppy, yellow means trending. In the options section of the study you can disable this by turning off the ADX bar. I recommend doing this if you use my code posted above, since it would be redundant (the candles would turn light gray if ADX was indicating a choppy market).
 
def open_order = bullish[-displace];
def close_order = bearish[-displace];
#ORDERS
AddOrder(type = OrderType.BUY_TO_OPEN, open_order, tradeSize = Contracts, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(type = OrderType.SELL_TO_CLOSE, close_order, tradeSize = Contracts, name = "Close", tickcolor = Color.GRAY, arrowcolor = Color.GRAY);

This worked great for the buy signal. I reversed the code to get a short signal but it doesnt work? Can you guide me on how to add the short signal as well so I can back test the strategy?

#Short Order
AddOrder(type = OrderType.SELL_TO_OPEN, close_order, tradeSize = Contracts, tickcolor = Color.RED, arrowcolor = Color.red, name = SHORT");
AddOrder(type = OrderType.SELL_TO_CLOSE, open_order, tradeSize = Contracts, name = "Close short", tickcolor = Color.GRAY, arrowcolor = Color.GRAY);
 
#Short Order
AddOrder(type = OrderType.SELL_TO_OPEN, close_order, tradeSize = Contracts, tickcolor = Color.RED, arrowcolor = Color.red, name = SHORT");
AddOrder(type = OrderType.SELL_TO_CLOSE, open_order, tradeSize = Contracts, name = "Close short", tickcolor = Color.GRAY, arrowcolor = Color.GRAY);
You were close, name = SHORT needed a " and its not SELL_TO_CLOSE its BUY_TO_CLOSE
 
You were close, name = SHORT needed a " and its not SELL_TO_CLOSE its BUY_TO_CLOSE

ah seems even with that correction, it plots every bar to sell and buy lol. I'd like to know when to begin my short but i Guess i can just juse the close indicator.
 
Three questions after reading 11 Pages of comments.

1 - Should this be added as a strategy or as a Study.
2 - I dont see anything but different colored bars. Should there be arrows of some sort or bubbles?
2b - How can I add indicator or alerts/arrows?
 
Last edited:
The Original posting is a Study, think of it as an information traffic light. It's got multiple signals it is monitoring. Some of them are not reliable to trade as a definitive, no repaint signal, So to make it a strategy as I posted a few times here you can add AddOrder statements and decide which of the many signals you want to create entry and exit signals from. Then once added create new Strategy under the Strategy tab
 
@diazlaz thank you ver much for the hard work done here for us. Can you please look at my questions below and get me answers?

1/ if I download the code in post#3 that means I don't need to download anything else?
2/ I understand that there is a delay or repaining issue in that strategy as Hekin Ashi added, how can I remove the HA so I continue using the strategy without it?
3/ I see the strategy setting options to enable and turning on and off things, are those options for determining the indicators in calculation of results or just to make labels not shown on chart?
 
@diazlaz thank you ver much for the hard work done here for us. Can you please look at my questions below and get me answers?

1/ if I download the code in post#3 that means I don't need to download anything else?
2/ I understand that there is a delay or repaining issue in that strategy as Hekin Ashi added, how can I remove the HA so I continue using the strategy without it?
3/ I see the strategy setting options to enable and turning on and off things, are those options for determining the indicators in calculation of results or just to make labels not shown on chart?
It's not a strategy. It's an information study that is monitoring multiple signals. So if 7 out of 10 signals are green light then its saying bullish. the threshold sets the number of signals you are accepting as valid to determine a trend bull or bear. Turning off signals like the HA then that reduces the number of available signals to validate the trend. So then it would be 7 out of 9 if you leave the threshold the same.
 
I find that the TTM_Trend() function is too complex (TOS buildin function). Without it, this code may run on Mobile and alert.
Anyone have a TTM_Trend() source code or similar indicators?
Thanks
 
I find that the TTM_Trend() function is too complex (TOS buildin function). Without it, this code may run on Mobile and alert.
Anyone have a TTM_Trend() source code or similar indicators?
Thanks
I truly do not know what the TTM trend is made out of...
 
@diazlaz @HighBredCloud I think you will like the solution to the sharp edges of the sharp geometry of the Schaff Wave - Shaff Trend rectangles, you can keep the standard time intervals recognized the world over for MACD just use this code you were already using here. https://usethinkscript.com/threads/price-trend-indicator-for-thinkorswim.13/page-3
Code:
input SWCA_fastlengthwave = 12;
input SWCA_slowlengthwave = 26;
Without being thrown off in odd time increments...
The solution is to use multiple Schaff time frames. Maybe 13 like the lower in this photo?
input SWCA_fastlengthwave = 12;
input SWCA_slowlengthwave = 26;
https://usethinkscript.com/threads/...swim.13/page-2#lg=_xfUid-1-1586461542&slide=0Does anyone have the code to this lower with the 13 moving averages?
Now I might have to do the subtraction step in the Schaff indicator multiple times but that shouldn't be resource intensive..
@vvcv does anybody have the code to this lower? If not I can figure it out but I would not present it in those bright neon lights I would just have a soft cloud behind the candlesticks and green & red for Bull Bear, AND yellow for narrowing & Black for close trade...
That is what I will do and then I will use some of there for prerequisites to see if bars should be colored at all or left black!
I think this will be popular. I think also require certain ADX minimum too
what is the ribbon you were referring in the attached screenshot?
 

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