If we have more than one order open and need to compute the total of OrderProfit() and the total of OrderCommission() is this the right way to get it ?
Thanks in advance for any clarification on the above
Luis
Hi RaptorUK,
Thank you for your attention to my issue.
Sorry but I'm feeling a little confused. In essence I'm looking to start trail once the total of open orders are in profit. for that the way I'm see the question the total of profit orders - total of order commission should result at least of a value above 0.
With that in mind the code below should do what I'm looking or is something wrong here ?
TotalOrderProfit = 0; TotalOrderCommission = 0; TotalOrderSwap = 0; MLots = 0; for(int cnt = OrdersTotal()-1; cnt >= 0; cnt--) {//11 if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))continue; {//12 if(OrderSymbol() == Symbol()&& OrderMagicNumber() == MagicNumber) {//13 TotalOrderProfit += OrderProfit(); TotalOrderCommission += OrderCommission(); TotalOrderSwap += OrderSwap(); OrderLots(); if(MLots <= OrderLots())MLots = NormalizeDouble(OrderLots() * Multiplier,2); if(MathAbs(TotalOrderProfit) - MathAbs (TotalOrderCommission) > 0)Trail(); }//13 }//12 }//11 return(0); }//0
Could I get from you your opinion ?
best regards
Luis
Could I get from you your opinion ?
Why are you using MathAbs() ? it's no good using other people's code if you don't understand it. MathAbs(-10000) - MathAbs(-200) is always going to be > 0 even though you have a 10000 loss . . .
Why are you calling Trail() before you have the TotalOrderProfit figure ? you call Trail() from within the loop, you only have the total profit when you have summed the profit for all your orders, and this is only done when the loop is complete.
With that in mind the code below should do what I'm looking or is something wrong here ?
Why not create a function that computes total profit, such as:
double CumulativeProfit() { double profit = 0; for (int cnt = OrdersTotal()-1; cnt >= 0; cnt--) if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) profit = profit + OrderProfit() + OrderCommission() + OrderSwap(); return (profit); }
And then use that function to determine if/when you wish to implement a trailing stoploss. For example:
if (CumulativeProfit() > 0) Trail(); // This function call is taken from your example, so I'm not sure what it does or doesn't do.
Why not create a function that computes total profit, such as:
And then use that function to determine if/when you wish to implement a trailing stoploss. For example:
Almost, but it won't work, your profit is not a running total and will return the profit figure for just one order.
Use . .
profit = profit + OrderProfit() + OrderCommission() + OrderSwap();
Almost, but it won't work, your profit is not a running total and will return the profit figure for just one order.
Use . .
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I've a question regarding arithmetic operation between OrderProfit() and OrderCommission().
Say that I want to find out when a n order is in profit, I mean if an order has it's own commission which is fixed then order "clean" profit should be OrderProfit() minus OrderCommission().
So if one have this code;
means that Profit is the result of OrderProfit() - OrderCommission() ?
Other question regarding more of the same if the above is right is;
If we have more than one order open and need to compute the total of OrderProfit() and the total of OrderCommission() is this the right way to get it ?
Thanks in advance for any clarification on the above
Luis