When I write this code in my bot, the code checks for every close whether the current position is 10 points plus and then closes the trade. Quasi an exit without a TP. If the position is 100 points plus, it closes as well as if the position is 11 points plus. The same with the second code, only then time-dependent. Is that correct or do I have a mistake in my thinking?
If longonmarket and Close>Positionperf+10*pipsize then
sell at market
endif
If longonmarket and Time=120000 and Close>Positionperf+10*pipsize then
sell at market
endif
JSParticipant
Senior
Calculation PositionPerf example:
Open position at 100
Close position at 110
Then PositionPerf = (110 – 100) / 100 = 0,1
JSParticipant
Senior
Or:
Open position at 100
Current price 108
(Current)PositionPerf = (108 -100) / 100 = 0,08
To calculate the number of pips gained (or lost, if negative) so far, for a single position:
PipsGain = PositionPerf * PositionPrice / PipSize
for all positions (the output is the same as above if you only have one position open):
PositionPerf * PositionPrice / PipSize * abs(CountOfPosition)
So the correct code to check if profit is 10+ pips:
If longonmarket and (PositionPerf * PositionPrice / PipSize) >= 10 then
sell at market
endif
Thanks, this function could be quite useful with different TP distances. Or as an exit from the market in profit in the evening or Friday evening.