Exit and Reenter same bar
Forums › ProRealTime English forum › ProOrder support › Exit and Reenter same bar
- This topic has 37 replies, 4 voices, and was last updated 5 years ago by dburgh.
-
-
05/08/2018 at 1:36 PM #69994
Hello,
Is it possible to have a strategy exit on the next open but then re-enter on that same open for next trade?
For example, in an existing position on Monday. On Monday’s close the exit condition is true (and so is the entry condition). So on Tuesday’s open we should exit existing trade but also enter next trade (because of Monday’s signal).
Any help is greatly appreciated,
Dburgh
05/08/2018 at 4:45 PM #7000405/09/2018 at 2:39 PM #7007605/09/2018 at 3:23 PM #70081This will do the trick, at the end of each bar it first closes any open trade (no matter their direction), then it opens a new one according to your conditions:
123456789IF OnMarket THENSELL AT MARKETEXITSHORT AT MARKETENDIF..IF My_Conditions THENBUY/SELLSHORT ......ENDIFSince each strategy is executed at the closing of every bar, on a Daily TF each day it’ll close the previous day’s trade and eventually enter a new one.
05/09/2018 at 4:58 PM #70083Hey, this makes sense. However, I am still unable to get the desired effect.
Can you try a simple example.
Entry: buy if low[0] <= low[1]
Exit: hold for 1 bar
I have tried a few iterations and this is the closest I can get to desired results, but it still does not exit and re-enter on the same bar. Thanks for the help.
if onmarket and barindex – tradeindex >= 0 then
sell at market
endifif low[0] <= low[1] and not onmarket then
buy 1 shares at market
endifAttachment: The trade inside the yellow box has correct entry. The bar prior to the entry bar did have the entry rule true (low[0] <= low[1]). The exit is also correct. However, we should have also re-entered on the small green bar (exit bar) because the entry bar also had low[0] <= low[1]
05/09/2018 at 5:16 PM #70087You need not check how many bars have elapsed, if you put this code at the very beginning of your strategy (just after DEFPARAMs and CONSTANT/VARIABLE initialization):
1234IF OnMarket THENSELL AT MARKETEXITSHORT AT MARKETENDIFyour trades won’t live longer than a SINGLE bar!
Try this one (I tested it on Gbp/Chf, 1-hour TF, from May 1st till now)
1-bar TRADES12345678910DEFPARAM CumulateOrders = falseIF OnMarket THENSELL AT MARKETEXITSHORT AT MARKETENDIFif low[0] <= low[1] and not onmarket thenbuy 1 shares at marketendif05/09/2018 at 5:27 PM #70089Thank you for your help on this. However, in your example, it is still not doing what I’d expect and am asking.
You can see that the entry inside the yellow box is correct. However, how come it does not re-enter on the exit bar (with red arrow above)? The previous bar (which we entered on) had entry condition true.
Thanks
05/09/2018 at 6:36 PM #70102Run this verion and you’ll see the differences:
12345678910DEFPARAM CumulateOrders = trueIF OnMarket THENSELL AT MARKETEXITSHORT AT MARKETENDIFif low[0] <= low[1] then//and not onmarket thenbuy 1 shares at marketendifSetting the first line to TRUE and commenting the ONMARKET condition in line 8 changes the behaviour of ProOrder.
I think this is may be due to ONMARKET requiring a candle to be considered TRUE when a trade is started, but I am not sure about this, let’s hope @Nicolas help us when back to work from sunbathing!
05/09/2018 at 6:39 PM #7010305/09/2018 at 6:45 PM #70105There must be something wrong with your system, I ran it on both GbpChf and DAX, 1-hour TF, from the beginning till now and both executed more than 12,000 trades, ALL of them closed after ONE bar!
05/09/2018 at 6:48 PM #7010605/10/2018 at 1:36 PM #70135Set cumulateorders=true and count in variables if we are on market or not:
12345678910111213DEFPARAM CumulateOrders = truedefparam preloadbars=0IF OnMarket and count=1 THENSELL AT MARKETEXITSHORT AT MARKETcount=0ENDIFif low[0] <= low[1] and count=0 then//and not onmarket thenbuy 1 shares at marketcount=1endifYou will prevent cumulating orders while allowing close and open of orders on the same candle. Is that what you wanted?
1 user thanked author for this post.
05/10/2018 at 1:45 PM #7013805/14/2018 at 1:10 PM #7035105/14/2018 at 1:21 PM #70355It seems you’ve already been given solutions.
-
AuthorPosts
Find exclusive trading pro-tools on