Donchian Strategy stopped considering ATR

jrsnell

New member
I've been using the Donchian strategy for a while now at Thinkorswim. After a little break for a couple of months, I've come back to the platform and the strategy no longer works properly. I reached out to their support and they are clueless as to what happened.

I have it set up as Long Only, enter on a violation of the upper DC line (set at 20) and then to either exit at a violation of the lower DC (20) or an actual weekly close below the ATR set at 50,3,3.

The strategy now does not plot the ATR and it seems like it might fire off the first instance, but then never again. I am plotting the ATR 50,3 separately to cross-check the strategy and it's obvious that the ATR part of the strategy is just ignored.

Schwab is going to have a developer look at the code and see if they can figure out if something got corrupted or was changed, but it could be some extended period of time before they get to it.

My inputs are 20,20,50,3,3,SIMPLE

Below is the code from my instance of it on the editor... is there anyone who can see what the trouble might be?

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2014-2023
#

input entryLength = 40;
input exitLength = 15;
input atrLength = 20;
input atrFactor = 0.9;
input atrStopFactor = 4.0;
input atrAverageType = AverageType.SIMPLE;

def entryUpper = Highest(high, entryLength)[1];
def entryLower = Lowest(low, entryLength)[1];
def exitUpper = Highest(high, exitLength)[1];
def exitLower = Lowest(low, exitLength)[1];

def atr = reference ATR(length = atrLength, "average type" = atrAverageType);
def volatilityOk = TrueRange(high, low, close)[1] < atrFactor * atr[1];

def buyToOpen = (atrFactor == 0 or volatilityOk) and high > entryUpper;
def sellToOpen = (atrFactor == 0 or volatilityOk) and low < entryLower;
def buyToClose = high > exitUpper;
def sellToClose = low < exitLower;

def position = {default none, long, short};
position = if (buyToOpen or (position[1] == position.long and !sellToClose)) then position.long
    else if (sellToOpen or (position[1] == position.short and !buyToClose)) then position.short
    else position.none;

plot BuyStop;
plot CoverStop;
if (position[1] == position.short) {
    BuyStop = Double.NaN;
    CoverStop = exitUpper;
} else {
    BuyStop = entryUpper;
    CoverStop = Double.NaN;
}

plot ShortStop;
plot SellStop;
if (position[1] == position.long) {
    ShortStop = Double.NaN;
    SellStop = exitLower;
} else {
    ShortStop = entryLower;
    SellStop = Double.NaN;
}

BuyStop.SetDefaultColor(GetColor(3));
CoverStop.SetDefaultColor(GetColor(6));
ShortStop.SetDefaultColor(GetColor(4));
SellStop.SetDefaultColor(GetColor(5));

AddOrder(OrderType.BUY_TO_OPEN, buyToOpen, tickcolor = GetColor(3), arrowcolor = GetColor(3), name = "DonchianLE");
AddOrder(OrderType.SELL_TO_OPEN, sellToOpen, tickcolor = GetColor(4), arrowcolor = GetColor(4), name = "DonchianSE");
AddOrder(OrderType.SELL_TO_CLOSE, sellToClose, tickcolor = GetColor(5), arrowcolor = GetColor(5), name = "DonchianLX");
AddOrder(OrderType.BUY_TO_CLOSE, buyToClose, tickcolor = GetColor(6), arrowcolor = GetColor(6), name = "DonchianSX");

def entryPrice = EntryPrice();

AddOrder(OrderType.SELL_TO_CLOSE, if atrStopFactor != 0 then low < entryPrice - atrStopFactor * atr else no, tickcolor = GetColor(5), arrowcolor = GetColor(7), name = "DonchianATRLX");
AddOrder(OrderType.BUY_TO_CLOSE, if atrStopFactor != 0 then high > entryPrice + atrStopFactor * atr else no, tickcolor = GetColor(6), arrowcolor = GetColor(8), name = "DonchianATRSX");
 

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