Hi all, first time poster so please be gentle.
I’ve used the ProRealTime charts for quite a while, and have programmed quite a few indicators to operate as I’d like. I’ve only recently been dabbling with automating my trading, and I can’t seem to find the code to automatically change the stop loss or target profit if I’m in a trade too long.
When I trade manually, if I’m in a trade for an hour, then I look to get out. If I’m in profit at that point, I move the stop loss to break even so I’m in a no loss trade. If I’m behind in a trade, I move the target profit to break even so I’ve got more chance of avoiding a loss.
I’ve tried a few if/else bits of code, but I can’t seem to achieve what I want for some reason. I found a way to automatically close a trade after an hour, but not to change the target/loss as I’ve described above. Any pointers, even if it’s to say it can’t be done, would be much appreciated.
Many thanks in advance.
You can count the number of bars since the trade was opened with the simple calculation of BARINDEX minus TRADEINDEX. The price you traded at is TRADEPRICE or POSITIONPRICE for cumulated positions. So use a STOP order to sell at that price.
if onmarket and barindex - tradindex >= 4 then
sell at positionprice stop
endif
I’ve moved your topic to the ProOrder forum as it is not an indicator question.