Futures strategy: Wide Ranging Days In ThinkOrSwim

danB

New member

Hello community,

After posting a request for help to code a strategy taken from the book " A Complete Guide to the Futures Market Technical Analysis and Trading Systems, Fundamental Analysis, Options, Spreads, and Trading Principles" by Jack D. Schwager and Mark Etzkorn, Mr. @Svanoy did a terrific job with the script: https://usethinkscript.com/threads/wide-ranging-days.9294/#post-88073

This strategy is based on "Wide Ranging Days". I'll leave a transcprit of the part of the book which includes the basic definitions and describes the strategy:
Definitions
Wide-ranging day. A day on which the volatility ratio (VR) is greater than k (e.g., k = 2). The
VR is equal to today’s true range divided by the average true range of the past N-day period
(e.g., N = 10).
Price trigger range (PTR). The range defined by the highest true high and lowest true low in
the interval between N1 days before the most recent wide-ranging day to N2 days after. Note
that the PTR cannot be defined until N2 days after a wide-ranging day. (If N2 = 0, the PTR
would be defined as of the close of the wide-ranging day itself.) The PTR will be redefined each
time there is a new wide-ranging day (i.e., N2 days after such an event).
Trading Signals
Buy case. On a close above the high of the PTR, reverse from short to long.
Sell case. On a close below the low of the PTR, reverse from long to short.
Daily Checklist
To generate trading signals, perform the following steps each day:
1. If short and today’s close is above the high of the PTR, liquidate short and go long.
2. If long and today’s close is below the low of the PTR, liquidate long and go short.
3. Check whether exactly N2 days have elapsed since the most recent wide-ranging day. If this
condition is met, redefine the PTR.
 
Last edited by a moderator:

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

@danB
Cleaned up the code.
FIXEDThe number of bars displayed to the right of close can be up to and including the value of Days_After. FIXED

Code:
#Wide Ranging Days
#Introduced by danB
#Coded by Svanoy

input length = 10;
input averageType = AverageType.WILDERS;
input Days_Before = 1;
input Days_After = 2;

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);

#AddChartBubble(WideRangingDay[Days_After],low,True_Low,color.white,no);
#AddChartBubble(WideRangingDay[Days_After],high,True_High,color.white,yes);

plot PTRH = True_High;
plot PTRL = True_Low;

plot UpSignal = if WideRangingDay then low else Double.NaN;
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetDefaultColor(Color.CYAN);

input StartDate = 20220104;
def Days = DaysFromDate(StartDate);
AddCloud(if Days == 0 then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, Color.LIGHT_GRAY);
def price = close;

AddOrder(OrderType.BUY_AUTO, price crosses above PTRH and Days >= 0, tradeSize = 1, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "WideLong");
AddOrder(OrderType.SELL_AUTO, price crosses below PTRL and Days >= 0, tradeSize = 1, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "WideShort");
 
Last edited by a moderator:
What does this look like on TOS? Do you have a screen shot?
Here you go
UsommrL.png
 
Last edited by a moderator:
Can someone please post it where the blue dash line that connects the wide short and wide long be remove as an option. I had a great trading day with it today.
 
Can someone please post it where the blue dash line that connects the wide short and wide long be remove as an option. I had a great trading day with it today.
Hello, which time frame did you use? As it's posted in the book is thought to be used pn the daily chart but I would prefer to trade smaller time frames so if it worked for you that's great to hear.
 
Nothing is shown on the chart. what does it supposed to do?
Plz read above, we don't know why it does that, but in order for the study to show you can only have up to Days After bars to the right of the chart, otherwise it won't work.
 
Hello, which time frame did you use? As it's posted in the book is thought to be used pn the daily chart but I would prefer to trade smaller time frames so if it worked for you that's great to hear.

. Futures i was trading the 5M time Frame. I went back 90 days to check and i saw something positive before i traded today. Waiting to see something on stocks options to try it on the daily time frame.
 
For those using this strategy, I recommend playing with the days before/days after (or "bars before/bars after" if you use it on a lower time frame such as the 5 min chart) and analyze which provides better results for you. As the book which the strategy was taken from suggest, there's a trade off between the number of falls signals and the entry price. If you use fewer days/bars before/after you enter trades at better prices and you get buy and sell signals, but some of them can be false signals or signals that end up being lossing trades. With more days before/after you get less signals but they "filter" most of the losing trades (not all of them, of course) at the cost of entering the trades not at such great prices. However, it seems that the filtering of the bad trades more than compensates entering the trade at higher/lower prices. The book suggests using 2 days before and 4 days after to calculate the PTR and the backtest on the 5 min charts confirms that it provides better results than other setups for me.
 
For those using this strategy, I recommend playing with the days before/days after (or "bars before/bars after" if you use it on a lower time frame such as the 5 min chart) and analyze which provides better results for you. As the book which the strategy was taken from suggest, there's a trade off between the number of falls signals and the entry price. If you use fewer days/bars before/after you enter trades at better prices and you get buy and sell signals, but some of them can be false signals or signals that end up being lossing trades. With more days before/after you get less signals but they "filter" most of the losing trades (not all of them, of course) at the cost of entering the trades not at such great prices. However, it seems that the filtering of the bad trades more than compensates entering the trade at higher/lower prices. The book suggests using 2 days before and 4 days after to calculate the PTR and the backtest on the 5 min charts confirms that it provides better results than other setups for me.
Hi Dan,
Thank you for sharing this startegy. Are you using any another indicators to avoid bade trades?
Thank you!
 
Hi Dan,
Thank you for sharing this startegy. Are you using any another indicators to avoid bade trades?
Thank you!
Hello, I'm not using any other indicators, just playing around with the numbers of candles before and after the wide ranging day to build the price trigger range and trusting your technical analysis, i,e. I won´t buy just below a support even if a buying signal shows, I'll just wait for the next one or watch how the price action develops and if the price breaks the support. Using 2 bars before and 4 days after should filter as much of the bad trades as possible.
 
Hello, I'm not using any other indicators, just playing around with the numbers of candles before and after the wide ranging day to build the price trigger range and trusting your technical analysis, i,e. I won´t buy just below a support even if a buying signal shows, I'll just wait for the next one or watch how the price action develops and if the price breaks the support. Using 2 bars before and 4 days after should filter as much of the bad trades as possible.
Hi Dan ,
Thanks for the strategy. Do we need change any dates in the strategy settings. It is defaulted as 20220104.

regards,
Krishna
 
Hell
Hi Dan ,
Thanks for the strategy. Do we need change any dates in the strategy settings. It is defaulted as 20220104.

regards,
Krishna
Hello, If you want to backtest it you just set the date to the starting day of the period. Otherwise you can leave it that way.
 
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
 
Last edited by a moderator:
Hello community,

After posting a request for help to code a strategy taken from the book " A Complete Guide to the Futures Market Technical Analysis and Trading Systems, Fundamental Analysis, Options, Spreads, and Trading Principles" by Jack D. Schwager and Mark Etzkorn, Mr. @Svanoy did a terrific job with the script: https://usethinkscript.com/threads/wide-ranging-days.9294/#post-88073

This strategy is based on "Wide Ranging Days". I'll leave a transcprit of the part of the book which includes the basic definitions and describes the strategy:

The script below is coded as a strategy. The only caveat is that it won't plot any lines or trading signals if you have set an empty space to the right of the chart. That is, for the code to work you need to set the expansion area of the time axis to 0 (zero) bars to the right. We don't know why it does that, maybe someone can provide help with that. I will be trying this myself with some micro lots on different futures markets (indexes and commodities) and provide some feedback. Meanwhile, any comments, improvements or help are appreciated. Cheers, Here's the code.

edited by mod:
How does it actually Work? some instructions for the strategy?
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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