Buying limit order if fail buy at market
Forums › ProRealTime English forum › ProOrder support › Buying limit order if fail buy at market
- This topic has 5 replies, 2 voices, and was last updated 7 years ago by
Bullets.
-
-
07/09/2018 at 7:39 AM #75613
Hi,
I just noticed my buy limit order was cancelled because the price never hit the 50MA on the next bar.
I’m wondering if there is a way to initially put buy at 50MA but should price not hit there in the next bar (hence limit order gets cancelled), if price is below 50MA buy at market (opening next bar), only if it didn’t buy at the 50MA.
Again sorry if I put the code in incorrectly? I just click on insert PRT code and type it in?
Let me know if this code below will work?
thanks
buy at limit else buy at market123456ma50 = Average[50](close)buy at ma50 limitif not on market and close < ma50 thenbuy at marketendif07/09/2018 at 7:49 AM #7561407/09/2018 at 7:55 AM #75615Your code will work and do what you ask but if you prefer to buy at the 50MA then LIMIT and STOP orders last for one bar only so if you want them to stay on the market then you have to re-add them at every bar. Just put the LIMIT or STOP order in your IF NOT ONMARKET with your entry conditions and it will be re-applied at every bar close where your conditions for entry are still true and you do not have a position already open.
123if not onmarket and (your conditions) thenbuy 1 contract at ma50 limitendif07/09/2018 at 8:13 AM #75616I currently have that code in your above format – but unfortunately it doesn’t work because my conditions include a low[1] <= ma50 and a high > ma50 along with some other specific things.
entry code123if not onmarket and crossflag and gapflag and low[1] <= ma50 and high > ma50 thenbuy at ma50 limitendifSo if the above conditions satisfy I buy at limit on the ma50. But if the next bar doesn’t get to the ma50, the trade is cancelled.
I want to take the trade on the next bar if its lower than the ma50 (this is the missing part).
So its a very specific condition which may not play out again on subsequent bars, so that code above doesn’t work in that type of loop, at least it didn’t in a live situation?
As my order history just shows my limit order was cancelled and that’s it.
07/09/2018 at 8:43 AM #75617I think I understand what you want. First you want to place a limit order and then if that is not filled then buy on the next bar if it closes below the MA but if that does not occur then go back to the start and look to buy at the MA limit. This might work – not tested and after very little coffee.
12345678910111213if not onmarket and crossflag and gapflag and low[1] <= ma50 and high > ma50 and orderflag = 0 thenbuy at ma50 limitorderflag = 1endifif not onmarket and orderflag and close < ma50 thenbuy 1 contract at marketorderflag = 0endifif not onmarket and orderflag and close > ma50 thenorderflag = 0endif07/09/2018 at 11:56 AM #75639Thanks for your help, I think the code does work, but I found something in the programming trading systems PDF which does what I’m after exactly.
It will level the limit order in @ the 50ma for at least 10 bars before cancelling.
Level Limit order in for 10 bars1234567891011121314ONCE NbBarLimit = 10if not onmarket and crossflag and gapflag and low[1] <= ma50 and close > ma50 thenMyLimitBuy = ma50MyIndex = Barindexendifif Barindex >= MyIndex + NbBarLimit thenMylimitbuy = 0endifif MylimitBuy > 0 and Not LongonMarket thenBuy 1 Contract at Mylimitbuy limitendif1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on