I'm trying to run some code as soon as an order is closed. I'm using TotalTrades and it works well unless the order is entered and closed in the same bar, like in the picture attached.
Would there be another way of doing it?
Thank you
Code: Select all
//Run as soon as an order is closed
Variables: oldTotalTrades(0);
if totaltrades > oldTotalTrades then begin //An order just got closed.
//Execute code here
value1 = value1 + 1; //just a counter of how many times this code was ran
print("Total executions = ", value1, " Totaltrades= ", totaltrades);
oldTotalTrades = totaltrades;
End
Total executions = 1204.00 Totaltrades= 1227.00
Total executions = 1205.00 Totaltrades= 1228.00
Total executions = 1206.00 Totaltrades= 1229.00
As you can see, the number of times the code was run is less than the number of total trades.