Please remember what I said : this earlier made post will only make it more vague. But it gives some insight and from there you should be able to get it working.
Main culprit remains : That If condition does not work out for you and now the Set Stop Profit will work against you.
Ask questions when needed.
I don’t know exactly what the idea is behind Set Stop Profit, but it does not work out the way you use it (also see below at the Disclaimer).
https://www.prorealcode.com/documentation/set-stop-profit/
The other day someone was fighting with Set Target Loss ? same thing I guess (but I did not try that). I think it was @ashehzi.
The commands feel a bit “bad” to me . So what you you mean set a Stop for profit ? we set TARGETs for profit. And we set STOPS for loss (protection).
I never used these commands, so undoubtedly I am wrong all over. Fact is, that it just does not work as advertised (which is without further context).
In between the lines 😉
I myself can be easily confused by the fact that I would use Set Stop Loss for the exact same, with the notice that I would set this when in profit. Notice that this just works (well) and that Set Stop Profit with that is redundant or not understood by me.
So Killer, try the one attached. See at the bottom.
If OnMarket then
set target $Profit ProfitParam //80
endif
Now it works exactly as you would expect it. **
Notice that I (re)activated the spread, so that you can even better check that it works. Play with that; set it to e.g. 40 and see the results.
Mind the ProfitParam I added for even easier checking.
The Set $Profit vs Set Profit does not make a difference in this 1 point instrument case (1 point is 1 euro).
I could be important that I tried this under V12, but I don’t think so, because you could not get it to work yourself either. However :
Your trailing is not working well. See the white GraphOnPrice line (line 60). But I am sure you will easily solve that now, now it starts to work in the base.
**): But it depends; the sheer fact that you use it under the condition of the trailing, suggests that you want to use it under the price, so that if the price drops the exit occurs and the profit is taken. This makes the culprit one thing only : your trailing condition is not right (and it isn’t).
Regards,
Peter
Disclaimer : I feel that Set Stop Profit can be used differently (like we can set Stops or Limits at the wrong side of the Price) and possibly this is related to having more contracts (or better : cumulated orders), but Nicolas’ documentation does not talk about that. And in any event without further context, the command as described places the exit at the wrong side of the Price and goes out immediately.
So to me it feels like Set Stop Profit can be used to lock in profit (price drops too much, so let’s take some of the profit). Thus from the documentation (I only read Nicolas’s) :
Allows you to place a stop at X points / % / € / unit above the entry price of the position (for a buy order or below for a sellshort order).
It would imply that you first are above the entry price and then at a certian stage apply the Set Stop Profit.