
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I am trying to update and reference multiple SL values using a function TrailingStop()
When I have two positions open and I iterate through them selecting ticket by index I am able to update the two different SL Values.
I do this for each position and store the SL value in an Array
The TrailingStop Function Successfully Iterates through position[0] and position[1] and I end up with correct values in the SLArr
But when I have closed one position and there is only one position left (normally position number 2 at index 1) the for iteration having decreased total positions only ever loops over position[0] which is now the old position[1]
As I reference the SL Array using the for iteration count I am only ever able to get the value for SLArr[0] while the value I need is stored in SLArr[1]
I am having trouble accessing the second value because the for loop is at position 0 and thus when I attempt to reference the SL value for the second value using the one function it is not able to recognize that position[0] has just been closed and to reference the values for position[1]
I hope this makes sense I recon if I was able to define what is happening better and describe it more correctly I would be half way to a solution.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I have come up with a way to get around this but it requires that I am able to perform some function when a position is closed and so far I have not been able to find an easy way to run some code for example updating a variable when a position closes using the inbuilt stoploss's built into the CTrade Trade.Buy and Trade.Sell functions.
If anyone has an easy way to execute some code when a SL on a position is triggered and the position is closed let me know.