Abdull1996:
Hi, i added the feature of multiplier in my expert, that is if the last trade is negative then the ea will open the new trade with double the lot that was opened in the previous trade. My Problem is that the multiplyer doesnt mutliply in a correct way, i think it just generates a number higher than the previous one. So here is my code:
I am sure from every thing (BuyProfit,LastLot...)
So please help me, waiting for your help, and thanks in advance.
Is your buyprofit variable calculating correctly? make sure it cycles the historical trades correctly for the most recent profit. It should do something like this:
void LastClosedProfit() { if(Martingale == false){LotSize = Lots;return;} RecentProfit = 0; int Tic = 0; for (int trall=0; trall<OrdersHistoryTotal(); trall++) { OrderSelect(trall, SELECT_BY_POS, MODE_HISTORY); if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderTicket() > Tic && OrderProfit() !=0){Tic = OrderTicket();RecentProfit = OrderProfit();} } } }
Only problem I see with the above, is it doesn't return the profit of the last close order, it returns the profit of the last OPENED order. Not the same if there are multiple orders.
double LastClosedProfit(){ double RecentProfit = 0; datetime lastClosePrev = 0; for(int pos=0; pos < HistoryTotal(); pos++) if ( OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) // Only orders && OrderCloseTime() > lastClosePrev // not yet processed, && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() <= OP_SELL){ // Avoid cr/bal forum.mql4.com/32363 lastClose = OrderCloseTime(); RecentProfit = OrderProfit(); } return(RecentProfit); }
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 added the feature of multiplier in my expert, that is if the last trade is negative then the ea will open the new trade with double the lot that was opened in the previous trade. My Problem is that the multiplyer doesnt mutliply in a correct way, i think it just generates a number higher than the previous one. So here is my code:
I am sure from every thing (BuyProfit,LastLot...)
So please help me, waiting for your help, and thanks in advance.