It is easier to do that for your second example where the total of the open positions is negative than it is for the first example where just any single position is negative.
Originally Posted by jidonk
You can do the second example easily from within the existing function that has already been descibed.
Before anything else, you must define a variable
In a new line between the OrderSelect() function and the if condition you then need to insert
Then, within the braces where the orders are counted and after orders_total;, you need to insert
What happens is that the function adds the profit from the current order to the previous total profit for every order that it counts. You can then use the value returned for total_open_profit to do your other things.