Futures strategy: Wide Ranging Days In ThinkOrSwim

Hey @danB - Thanks for the strat. I think I may be misunderstanding something. It sounds like the recommended timeframe for this is daily with a 2 /4 bar look back/forward. When I load that into ToS and look at FloatingPL its a sea of red. The first bar on the chart is 1/25/21 and I set the start date parameter to the same. Are you able to see what I am misunderstanding? Thank you.

ECy53ry.jpg

a8UQdyY.jpg
Hello, Originally in the book which introduces the strategy it is used at the daily time frame, hence the name "Wide ranging days". However, other users here tried using it in a lower time frame, such as the 5 min chart, and it works beautifully. I suggest you try the 5 min chart.
 
Hello, Originally in the book which introduces the strategy it is used at the daily time frame, hence the name "Wide ranging days". However, other users here tried using it in a lower time frame, such as the 5 min chart, and it works beautifully. I suggest you try the 5 min chart.
Hey @danB - So I spent a fair amount of time with this today on an ES 5 day/5 min chart and could not find any combination of parameters that resulted in a positive P&L over 5 days. Would you be so kind as to share the settings that you have found to work well on a 5 min chart? TIA.
 
Hey @danB - So I spent a fair amount of time with this today on an ES 5 day/5 min chart and could not find any combination of parameters that resulted in a positive P&L over 5 days. Would you be so kind as to share the settings that you have found to work well on a 5 min chart? TIA.
Hello, I use 2 days before, 4 after. I am looking at the /ES right now. I have my chart set up with a 30 day period and I see a profit of 7K, see the image attached.

Baohuvb.png


I agree the numbers are not impressive. This is an "always-in" strategy, meaning that you either have a long or short position, and just wait for the opposite signal if you are having a losing trade. I have seen other strategies, such as this one that include a stop loss in the code. Maybe adding one here can improve the P&L figures. Hope it helps.
 
Hello, I use 2 days before, 4 after. I am looking at the /ES right now. I have my chart set up with a 30 day period and I see a profit of 7K, see the image attached. I agree the numbers are not impressive. This is an "always-in" strategy, meaning that you either have a long or short position, and just wait for the opposite signal if you are having a losing trade. I have seen other strategies, such as this one that include a stop loss in the code. Maybe adding one here can improve the P&L figures. Hope it helps.
Thanks for taking the time to response @danB. I see the same results on a 30day/5 min chart, though looking at that chart I do also see that the last 5 days of the period show a loss. I'm going to keep playing around with it. I've also ordered the book that this idea came from.
 
I'm still playing around with this. Here's the best I've got so far. Designed for /ES on a 5 min chart. Changes from the original are:

1. Long trades only
2. Stop is the midpoint between PTRH and PTRL
3. Trade will exit on the last bar of the futures trading session
4. Added a variable for slippage (default 0.25 points per trade)
5. Added a variable for commissions (set to my commission rate of 0.12 points * $50 = $6)

I've looked at a good number of historical periods using onDemand and it holds up pretty well with an upward sloping profit curve.

Ruby:
#Wide Ranging Days Strategy - Long Only
#Original code by Svanoy.   Modified by Matt Ward Feb 2nd 2022.
#https://usethinkscript.com/threads/futures-strategy-wide-ranging-days-in-thinkorswim.9767

input length = 10;
input averageType = AverageType.WILDERS;
input Days_Before = 1;
input Days_After = 2;
input ExcludeDowntrend = Yes;
input DowntrendEMA1 = 5;
input DowntrendEMA2 = 9;
input DowntrendEMA3 = 14;
input Slippage = 0.25;
input Commission = 0.12;

def WideRangingDay = TrueRange(high, close, low) / ATR(length, averageType) > 1.6;

def Signal = if IsNaN(close[Days_After]) then Signal[Days_After] else WideRangingDay[Days_After];
def ValidBarNumber = if !IsNaN(BarNumber()) then BarNumber() else ValidBarNumber[1];
def WideRangingDayStartBarID = if Signal then ValidBarNumber[Days_After + Days_Before] else WideRangingDayStartBarID[1];
def WideRangingDayEndBarID = if Signal then ValidBarNumber else WideRangingDayEndBarID[1];

def True_High = fold th = ValidBarNumber - WideRangingDayEndBarID
                to ValidBarNumber - WideRangingDayStartBarID + 1
                with THC = GetValue(high, ValidBarNumber - WideRangingDayEndBarID)
                do if THC > GetValue(high, th) then THC else GetValue(high, th);

def True_Low = fold tl =  ValidBarNumber - WideRangingDayEndBarID
               to ValidBarNumber - WideRangingDayStartBarID + 1
               with TLC = GetValue(low, ValidBarNumber - WideRangingDayEndBarID)
               do if TLC < GetValue(low, tl) then TLC else GetValue(low, tl);

plot PTRH = True_High;
plot PTRL = True_Low;
plot MidLevel = ((PTRH-PTRL)/2)+PTRL;

input StartDate = 19501201;
def Days = DaysFromDate(StartDate);

def DownTrend = MovingAverage(averageType.EXPONENTIAL, OHLC4[-1], DowntrendEMA1) < MovingAverage(averageType.EXPONENTIAL, OHLC4[-1], DowntrendEMA2) and MovingAverage(averageType.EXPONENTIAL, OHLC4[-1], DowntrendEMA2) < MovingAverage(averageType.EXPONENTIAL, OHLC4[-1], DowntrendEMA3);
def EntryCondition = high crosses above PTRH and Days >= 0 and !(ExcludeDowntrend and DownTrend);
def EntryPrice = PTRH;
def ExitCondition1 = low crosses below ((PTRH-PTRL)/2)+PTRL;
def ExitCondition2 = if SecondsTillTime(1655) == 0 and SecondsFromTime(1655) == 0 then 1 else 0;
def ExitPrice = if ExitCondition1 then ((PTRH-PTRL)/2)+PTRL else if ExitCondition2 then open else 0;

def ExitNow = ExitCondition1 or ExitCondition2;

AddOrder(OrderType.BUY_TO_OPEN, EntryCondition, price = EntryPrice+Slippage+Commission, tradeSize = 1, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "");
AddOrder(OrderType.SELL_TO_CLOSE, ExitNow, price = ExitPrice-Slippage-Commission, tradeSize = 1, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "");
 
Last edited:
@_Merch_Man_
First of all, Great Work!
But... I did notice an error in your definition of EntryCondition.
Current definition will result in false buy signals and impossible entry prices.
There will be a false buy signal at the yellow arrow and if you wait until bar close then the price should be at the orange arrow.
x4SFZhT.png


You have to either change:
Code:
def EntryCondition = close crosses above PTRH and Days >= 0;
to:
Code:
def EntryCondition = high crosses above PTRH and Days >= 0;
to make the entry price valid.
kFxPAmL.png

Or change it to:
Code:
def EntryCondition = close[1] crosses above PTRH[1] and Days >= 0;
and change your AddOrder entry price to: open+Slippage+Commission
WhqVeWS.png


Again you've done a Great Job, I just didn't want your results to get skewed with impossible data.
 
Thank you @Svanoy! I've modified the entry condition in the post above. I also added new logic that gives you the option to NOT open trades if the market is in a downtrend. I've defined a downtrend as (by default) the 5 EMA < 9 EMA < 14 EMA. Thanks again for your feedback. My book arrived yesterday evening so I'll be reading more about this strategy and continuing to play around.
 
WOW! Svanoy and DanB, and Merchman thanks! And M.Ward, I've a modified Matt-Ward (Ver 1/30/22) run with what i left on the other thread (sorry about that). Note with the latest change, a real solid indicator in low time frames. Surprise, this indicator will kill!

excellent!

Now to make into a scanner, uh, anyone?
 
Last edited:
WOW! Svanoy and DanB, and Merchman thanks! And M.Ward, I've a modified Matt-Ward (Ver 1/30/22) run with what i left on the other thread (sorry about that). Note with the latest change, a real solid indicator in low time frames. Surprise, this indicator will kill!

excellent!

Now to make into a scanner, uh, anyone?
@Adeodatus Can you please link to the combined/modified code?
 
Last edited by a moderator:
13393[/ATTACH]']
sdVTi36.jpg
Only tagged it "Svanoy_2" to remember what to look for in the upper.


Lower, a modified trending indicator: https://usethinkscript.com/threads/combined-trend-indicators-for-thinkorswim.10055/

So follow the STC Trend for color change, see when it changed?
At bottom! STC Trend change to blue, (or whichever color you make it)
Watch where STC Wave changed to green & crosses 27 line.
AvgExp Wave only indicate Relevant Volume, it does not separately indicate buyer/seller volumes. (Yellow)
The green/red line along the bottom is polarity, positive or negative


I did not write this code
 

Attachments

  • sdVTi36.jpg
    sdVTi36.jpg
    427.9 KB · Views: 115
Last edited by a moderator:

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
283 Online
Create Post

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