dedjene
New member
Good afternoon all,
I was wondering if there was a way to backtest strategies that will only long above the 200 EMA and short below it. In result, automatically filtering out the longs below the 200 EMA and shorts above.
The purpose of this question is to limit my trades and to theoretically not fight the trend.
Let's use the default MACD strategy provided by thinkorswim as an example.
How can we modify this code to achieve my desired result?
Thank you all,
Sincerely,
Dj
I was wondering if there was a way to backtest strategies that will only long above the 200 EMA and short below it. In result, automatically filtering out the longs below the 200 EMA and shorts above.
The purpose of this question is to limit my trades and to theoretically not fight the trend.
Let's use the default MACD strategy provided by thinkorswim as an example.
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2013-2021
#
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;
def diff = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;
AddOrder(OrderType.BUY_AUTO, diff crosses above 0, tickColor = GetColor(0), arrowColor = GetColor(0), name = "MACDStratLE");
AddOrder(OrderType.SELL_AUTO, diff crosses below 0, tickColor = GetColor(1), arrowColor = GetColor(1), name = "MACDStratSE");
How can we modify this code to achieve my desired result?
Thank you all,
Sincerely,
Dj