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