Hello,
I need help with creating a code that exits a trade 2 ATR’s above entry price:
ex.
if close>high[1] then
buy 10000 cash at market
Is that Possible?
Thanks
When you place your buy order you can not know the entry price you will get so we have to assume it is the same as the close price. Once we are ‘onmarket’ we can adjust the exit price based on our actual entry price as we now know it.
We use pending limit orders to exit at the better price.
p = 10 //ATR period
if not onmarket and close>high[1] then
buy 1 contract at market
myatr = averagetruerange[p](close)*2
tp = close + myatr
sell at tp limit
endif
if onmarket then
tp = positionprice + myatr
sell at tp limit
endif