My basis for this work comes from the excellent "Mimicking "Power X Strategy" by Markus Heitkoetter" Primary contributors were @cos251 and @SuryaKirnaC.
My Strategy report is showing duplicate Buy/Sell pairs. Here is the report:
The thinkscript which generated this report is here (with violations corrected):
I suspect the problem is with the AddOrder statements, but I don't know enough to correct it, and the existing info I reviewed was vague.
Thank you!!
My Strategy report is showing duplicate Buy/Sell pairs. Here is the report:

The thinkscript which generated this report is here (with violations corrected):
Code:
#REQUIREMENTS - RSI Set to 7, EXPONENTIAL
# Stoch Slow 14 and 3 WILDERS
# MACD 12,26,9 WEIGHTED
declare upper;
################################################################
########## Variables #########
################################################################
input paintBars = yes;
input tradetype = { "long", "short", default "both" };
################################################################
########## RSI #########
################################################################
input lengthRSI = 7;
input price = close;
input averageTypeRSI = AverageType.EXPONENTIAL;
def NetChgAvg = MovingAverage(averageTypeRSI, close - close[1], lengthRSI);
def TotChgAvg = MovingAverage(averageTypeRSI, AbsValue(close - close[1]), lengthRSI);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
################################################################
########## Stochastic Slow #########
################################################################
input over_boughtSt = 80;
input over_soldSt = 20;
input KPeriod = 14;
input DPeriod = 3;
input averageTypeStoch = AverageType.WILDERS;
def SlowK = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high, low, close, 3, averageTypeStoch).FullK;
def SlowD = reference StochasticFull(over_boughtSt, over_soldSt, KPeriod, DPeriod, high, low, close, 3, averageTypeStoch).FullD;
################################################################
########## MACD #########
################################################################
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageTypeMACD = AverageType.WEIGHTED;
def Value = MovingAverage(averageTypeMACD, close, fastLength) - MovingAverage(averageTypeMACD, close, slowLength);
def Avg = MovingAverage(averageTypeMACD, Value, MACDLength);
def Diff = Value - Avg;
#################################################################
##### Up/Down Trend Check/SCAN Variables #########
#################################################################
def UpTrend = if RSI > 50 and SlowK > 50 and Value > Avg then 1 else 0;
def DownTrend = if RSI < 50 and SlowK < 50 and Value < Avg then 1 else 0;
def NoTrend = if !UpTrend and !DownTrend then 1 else 0;
def LongBuy = if UpTrend == 1 and UpTrend[1] == 0 and NoTrend == 0 then 1 else 0;
def LongExit = if UpTrend[1] == 1 and UpTrend == 0 then 1 else 0;
def ShortSell = if (DownTrend == 1 or NoTrend == 1) and (DownTrend[1] == 0 and NoTrend[1] ==0) then 1 else 0;
def ShortExit = if DownTrend == 0 and DownTrend[1] == 1 then 1 else 0;
#
AddLabel(yes, if UpTrend == 1 then "::RSM-Signal:LONG" else if DownTrend == 1 then "::RSM-Signal:SHORT" else "::RSM-Signal:IDLE", if UpTrend == 1 then Color.GREEN else if DownTrend == 1 then Color.RED else Color.GRAY);
#
plot upArrow = if UpTrend == 1 and UpTrend[1] == 0 and NoTrend == 0 and (tradetype == tradetype.long or tradetype == tradetype.both) then low else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
upArrow.SetDefaultColor(Color.GREEN);
upArrow.SetLineWeight(4);
################################################################
########## Assign Price Color #########
################################################################
AssignPriceColor(if paintBars and UpTrend then Color.GREEN else if paintBars and DownTrend then Color.RED else if paintBars then Color.DARK_GRAY else Color.CURRENT);
##
## Show downArrow on the start of NoTrend (sideways) movement OR DownTrend movement
##
plot downArrow = if (DownTrend == 1 or NoTrend == 1) and (DownTrend[1] == 0 and NoTrend[1] == 0) and(tradetype == tradetype.short or tradetype == tradetype.both) then high else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
downArrow.SetDefaultColor(Color.RED);
downArrow.SetLineWeight(4);
################################################################
########## BUY ORDER #########
################################################################
AddOrder(OrderType.BUY_TO_OPEN,(UpTrend == 1 and UpTrend[1] == 0 and NoTrend == 0) and (tradetype == tradetype.long or tradetype == tradetype.both), open[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "LONG");
#
AddOrder(OrderType.BUY_AUTO,upArrow and (tradetype == tradetype.long or tradetype == tradetype.both), price = open[-1], tickcolor = Color.ORANGE, arrowcolor = Color.BLUE, name = "BUY");
################################################################
########## SELL ORDER #########
################################################################
AddOrder(OrderType.SELL_AUTO, downArrow and (tradetype == tradetype.short or tradetype == tradetype.both), open[-1], tickcolor = Color.YELLOW, arrowcolor = Color.MAGENTA, name = "SELL");
I suspect the problem is with the AddOrder statements, but I don't know enough to correct it, and the existing info I reviewed was vague.
Thank you!!
Last edited by a moderator: