Duplicate Buy/Sell Order Pairs on my Strategy Report

rubixcube49

New member
Plus
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:
UlvYIR1.jpeg


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:
Solution
It doesn't look like dup orders. if you look at the side column, you've got different orders shown there. one will be 'buy to close' immediately followed by a 'buy to open'.

I'd get rid of one of the 'buy orders'. you shouldn't need two. In the rare circumstance where I've needed additional orders in a strategy, it's usually a buy to close or a sell to close as a stop.

See what removing a buy side order does for you and let us know how it goes.

-mashume
It doesn't look like dup orders. if you look at the side column, you've got different orders shown there. one will be 'buy to close' immediately followed by a 'buy to open'.

I'd get rid of one of the 'buy orders'. you shouldn't need two. In the rare circumstance where I've needed additional orders in a strategy, it's usually a buy to close or a sell to close as a stop.

See what removing a buy side order does for you and let us know how it goes.

-mashume
 
Solution
Thanks for your reply, Mashume. I changed the buy order from BUY_AUTO to BUY_TO_OPEN and the sell order from SELL_AUTO to SELL_TO_CLOSE. This solved two problems: the initial SELL order disappeared and the duplicate BUY/SELL orders disappeared.
 

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