Hi, this is the first time i have ever posted on the website, so apologies if i don’t follow the correct protocols, or have posted in the wrong place.
I am struggling with the backtesting software and a strategy i have been working on. My aim is to use Stop Orders to enter the market, with CumulateOrders True as often more than one trade will be open at once. the problem i run into is that it will send multiple Orders to the market with a single trigger; i.e. when my signal triggers i place a Stop Order to buy at a certain price above the current close, and this will cause multiple orders at market.
to give more details, the set up is as follows:
wait until price is above 21 SMA – set direction to 1
wait for a single candle pullback, use this as a signal bar, place a buy level 2pts above, and sell level below
when a signal bar occurs (the single candle pullback) i set up the system with “Buysystem”; this is so that if the price goes below the sell height before activating the trade, it will cancel the setup and never take the trade off that bar, and look for a new setup.
if the trade is activated, the “Buysystem” will turn off as well.
the trouble is, even though the “Buysystem” reverts to zero, another order to market is often placed, if the price carries up in the direction, as far as i am aware this should not happen as it should only buy when the “Buysystem” is on…?
i have noticed this problem with a few of my systems, and my main one is way to long (and probably poorly written) to include here, so i have written a simple one to get to the bottom of this problem. i have also noticed the same thing happens when i want to exit the position (when countofposition is more than 1 obviously). in general, i am only wanting to buy once per trigger (or exit once per exit trigger), not twice as is often happening.
one quick fix i found is:
if not (COUNTOFshortSHARES[0] < COUNTOFshortSHARES[1]) then
, or
if COUNTOFshortSHARES[0] = COUNTOFshortSHARES[1])then
these will work, however if there are two consecutive signals, then it means the second order wont go through until the bar after that (leaving a bar between), which is bad for exiting the trade as the trade will possible continue unwanted.
i have commented out the sellshort orders to solve one issue at a time.
i have attached photos below of what i am relating to. i have circled with a dotted red circle to show the double orders, i have also held the mouce over one of the orders so that it shows the “BuySystem” zeros out when the first order is place and so the second order should not occur.
sorry if i have described the situation poorly…
defparam flatafter = 160000
timok = time > 080000 AND time < 160000
sma = average[21](close)
if close > sma then
direction = 1
elsif close < sma then
direction = -1
else
direction = 0
endif
if direction = 1 then
if NOT Buysystem then
if high[1] = highest[3](high) AND high[1] <> high[2] then
buyheight = high[1] + 2
sellheight = (Min(Min(Low[0], Low[1]) - 2, Close - 4))
Buysystem = 1
endif
endif
endif
if Buysystem AND timok then
if low <= sellheight then
Buysystem = 0
endif
BUY 1 SHARES AT buyheight stop
if high >= buyheight - 0.5 then // minus spread
Buysystem = 0
endif
endif
//if direction = -1 then
//if NOT sellshortsystem then
//if low[1] = lowest[3](low) AND low[1] <> low[2] then
//sellshortheight = high[1] + 2
//exitshortheight = Max(Max(High[0], High[1]) + 2, Close + 4)
//sellshortsystem = 1
//endif
//endif
//endif
//if sellshortsystem AND timok then
//if low <= exitshortheight then
//sellshortsystem = 0
//endif
//BUY 1 SHARES AT sellshortheight stop
//if high >= sellshortheight then
//sellshortsystem = 0
//endif
//endif
if Not timok then
Buysystem = 0
sellshortsystem = 0
endif
if onmarket then
set target profit 10
set stop loss 10
endif
graphonprice sma
graphonprice buyheight coloured(0,0,150)
graphonprice sellheight coloured(150,0,0)
graph Buysystem