Salut,
Say I have an MA plotted on the price chart, and the price is currently sitting under the MA.
I want to buy when the MA is touched, but I don’t want to buy at next open… I want to buy at the price of the MA on that same bar. Is this possible to code please?
Many thanks.
Hi, not exactly because the system always wait until the current bar is finished to open a new position.
But you can still open a position in the next candle at the same price where the last bar was touched with a LIMIT order.
REM Moving Average
mm = Average[x](close) // x = periods of ma
// buy = your conditions to go in
IF NOT LongOnMarket AND buy = 1 THEN
BUY 1 CONTRACT AT mm[1] LIMIT
ENDIF
Hope it helps you.
Hello, if the price is “currently sitting under the MA”, the pending order would be a STOP one and not a LIMIT one, or I miss something here.. sorry got a cold.. 😐
Thank you very much Adolfo for helping people around here!!!
I’m glad if can help even one person.
Nicolas, I mean, in my example we are buying when the price comes to touch MA after a long movement, we go with the trend after a pullback.
Greetings!
Adolfo, PRT finds an error on this line. Unfortunately I’m very new to coding this platform…
IF NOT LongOnMarket AND BUY=1 THEN
Thank you.
PS price is touches on a price above the current price, so yes Nicolas that’s right, probably a STOP order.
Maybe you are not using “BUY=1”. So I should be wrong.
You want to BUY when the price CROSSES UNDER MA? When the price is rising and touch MA you want to buy, right?
Can you give more details please?
I want to buy when the price rises to touch the MA (which lies above it), with an entry price == MA on the same day.
Thank you. 🙂
Then should be something like this, but it will always buy when it occours.
REM Moving Average
mm = Average[x](close) // x = define MA periods you want to use
// Your conditions to buy
// You are not in, and price was under MA
IF NOT LongOnMarket AND High<mm THEN
BUY 1 CONTRACT AT mm STOP
ENDIF
Let me know if works for you!
Thank you, it appears to work fine. I just have to go through the trade list and check.
🙂
This is something similar to what I need, Where do I put this in my current code?