Indicates the percent of gain or loss of the Nth previous position.
The instruction POSITIONPERF(n) returns: The performance (ratio gain/cost of the position) of the n-th last position closed if n>0 (not including brokerage fees) The performance (ratio gains/cost of the position) of the currently open position if n=0 (not including brokerage fees)
If n is not specified, we suppose that n=0. PositionPerf=PositionPerf(0).
Syntax:
1 |
PositionPerf(N) |
I don’t understand how this command counts the percentage of profit (or loss).
For example, I would like to change my S/L if I reach a profit of 0.30%. I’ve tried with “IF POSITIONPRICE >= 0.3” but no result.
Something happens only when I write “IF POSITIONPRICE >= 0”.
Use positionperf, not positionprice.
Oui, erreur dans le code ci-dessus, je pensais bien à POSITIONPERF, mais rien n’arrive quand je mets “if POSITIONPERF > 0.3 then…”
GRAPH POSITIONPERF permettra de connaître le pourcentage de performance lors d’un backtest. Le seuil sera alors facilement réglable dans le code.
Super astuce qui permet d’afficher (comme un indicateur) une variable. Merci.
I was using positionperf(1) to work out if the last trade was a “win” or a “loss” – which was very useful for adjusting position size and skipping trades – it was working fine until today but now it’s stopped working in all my codes and I can’t understand why
@nicolas could you please test the following snippet to see if it’s just my setup?
the problem seems to be that suddenly it cannot calculate positionperf(1)
positionperf2 = positionperf(1)
//graph positionperf
//graph positionperf(1) coloured (255,0,0)
if positionperf2 positionperf2[1] then
if positionperf2 > 0 then
lossrunno = 0
winrunno = winrunno + 1
endif
if positionperf2 < 0 then
winrunno = 0
lossrunno = lossrunno + 1
endif
endif
It has been reported some problems with instructions related to backtest since an update made 2 days ago. I think that it will fixed by end of the week.
Hi, i have seen an old interesting message from you about adjusting position based on the calculation of win and loss. Could i ask you if you can provide the entire code you used to manage your positions ?
Thank you
thanks Nicolas, it’s working again now… it’s a bit worrying that these glitches can occur especially for those running “live” code… but also quite good that the problem has been resolved quickly. Many thanks for a quick response! 🙂
Hi @Nicolas, if I want to use positionperf to skip trade if the last long position is a loss, then skip long position for the day, and similarly for short position. How can I code to make it work? Many thanks in advance !
You should ask for that particular question in the forums.