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
ma50 = Average[50](close)
buy at ma50 limit
if not on market and close < ma50 then
buy at market
endif
Topic moved to the ProOrder forum as this is not an indicator based topic. Please try to post in the correct forum with future posts 🙂
Your 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.
if not onmarket and (your conditions) then
buy 1 contract at ma50 limit
endif
I 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.
if not onmarket and crossflag and gapflag and low[1] <= ma50 and high > ma50 then
buy at ma50 limit
endif
So 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.
I 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.
if not onmarket and crossflag and gapflag and low[1] <= ma50 and high > ma50 and orderflag = 0 then
buy at ma50 limit
orderflag = 1
endif
if not onmarket and orderflag and close < ma50 then
buy 1 contract at market
orderflag = 0
endif
if not onmarket and orderflag and close > ma50 then
orderflag = 0
endif
Thanks 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.
ONCE NbBarLimit = 10
if not onmarket and crossflag and gapflag and low[1] <= ma50 and close > ma50 then
MyLimitBuy = ma50
MyIndex = Barindex
endif
if Barindex >= MyIndex + NbBarLimit then
Mylimitbuy = 0
endif
if MylimitBuy > 0 and Not LongonMarket then
Buy 1 Contract at Mylimitbuy limit
endif