AlunParticipant
Average
How do I use the gain on an order in an IF decision?
POSITIONPERF
The instruction POSITIONPERF(n) returns: The performance (ratio gain/cost of the position)
So in order to use it in a condition you can do:
if positionperf(0) > 0 then
//we are in gain!!
endif
AlunParticipant
Average
Hi thank you for your reply.
When I have tried this it does not seem to work. I would like to exit greater than a gain value. Is this possible?
Alun– please do not double post. It just leads to wasted time and effort for those trying to help you if you post the same question in two places. I have deleted your other topic with an identical question.
You can do something like this:
takeprofit = 1000
if longonmarket and (close - positionprice) * countofposition > takeprofit then
sell at market
endif
if shortonmarket and (positionprice - close) * (0 - countofposition) > takeprofit then
exitshort at market
endif
which will check at the bar close if you are in the desired profit or alternatively just use:
set target $profit 1000
which places an order on the market to sell when up $1000 or whatever currency the instrument is in.
When I have tried this it does not seem to work. I would like to exit greater than a gain value. Is this possible?
Yes just set your gain value as a percentage, for example …
if positionperf(0) > 0.1 then //gain > 0.1%
Sell at Market
endif
AlunParticipant
Average
Will do! Apologies, very new to this.
AlunParticipant
Average
Vonasi, this seems to be exactly what I was looking for. Thanks