Error in Journal...
2024.01.30 00:36:36.832 Trades '24046': failed market sell 0.07 GBPJPY, close #6130450 buy 0.06 GBPJPY 188.082 [Invalid volume]
"iStartLots" is 0.13 as input double. tk is the ticket (position.Ticket()).
What have i done wrong? 0.07 was closed, but I still got the error.
I have confirmed that lot step is 0.01, therefore it is not the lotstep issue.
print lot before partial close
Note this is just strategy tester report...
Print("Partial Lot to be closed is "+DoubleToString(lot));
msg in journal
2024.01.30 11:51:58.300 Core 1 2021.01.26 14:03:57 Partial Lot to be closed is 0.07000000
so, the msg works.
I will have to wait for another partial closed trade now.
Note this is just strategy tester report...
msg in journal
2024.01.30 11:51:58.300 Core 1 2021.01.26 14:03:57 Partial Lot to be closed is 0.07000000
so, the msg works.
I will have to wait for another partial closed trade now.
I understand the issue now.
I use asynchronised trading, which often gives me error "Position Dosent Exist" -- when a group of trades is closed.
So, when part of a trade 0.13 is closed, ie 0.07 then 0.06 remains, so, instead of getting the error Position doesnt exist, i get the Volume is Invalid instead.
Maybe someone can give me idea to avoid this when using asynch? Heres my close trades function...
void CloseTrades(int total, int trades, int profitDirection, ulong worst, int no2close = 99) { double c; c=0; ulong tk; int neg = 0; bool loss = info.Equity()/(MaxEqu[0]+eqplus)<0.85; bool dir = equ<0.85*bal; // no2close = equ>MaxEqu[2]?99:no2close; int toClose=fmin(no2close,6); for(int k=PositionsTotal()-1; k>=0; k--) { if(posi.SelectByIndex(k)) { if(PositionGetTicket(k)<=0 || PositionGetTicket(k)!=posi.Ticket()) break; if(posi.Symbol()!=_Symbol || (posi.Magic()>0 && posi.Magic()!=iMagicNumber)) continue; ++c; typ=posi.Type(); sw=posi.Swap(); pft=posi.Profit(); xltv = (ltv>iStartLots)? (ltv / iStartLots - 1) * xcm : 0; net = pft+iMinimalProfit+sw-xcm-xltv; tk=posi.Ticket(); if(net>0 || (no2close == 99 && typ!=profitDirection)) { trade.PositionClose(posi.Ticket(),iSlippage); continue; } if(neg<toClose) for(int i=0; i<toClose; ++i) { if(worsTics[i]>0 && tk==worsTics[i]) { tk=posi.Ticket(); ltv=posi.Volume(); ++neg; worsTics[i]=0; if(profitDirection!=typ || loss || no2close!=99) trade.PositionClose(tk,iSlippage); else if(ltv<=0.05 || ltv<iStartLots) trade.PositionClose(tk,iSlippage); else if(ltv>0.05) { double lot = NormalizeDouble(fmax(0.01,0.01*round(iStartLots*0.5/0.01)),2); Print("Partial Lot to be closed is "+DoubleToString(lot)); trade.PositionClosePartial(tk,lot,iSlippage); //ExpertRemove(); //trade.PositionClosePartial(posi.Ticket(),,iSlippage); } } } } } if(total!=PositionsTotal() || trades!=c) closed = true; }
do you think this would help?
else if(ltv>0.05) { double lot = NormalizeDouble(fmax(0.01,0.01*round(iStartLots*0.5/0.01)),2); Print("Partial Lot to be closed is "+DoubleToString(lot)); if(posi.Volume()==ltv) trade.PositionClosePartial(tk,lot,iSlippage); //ExpertRemove(); //trade.PositionClosePartial(posi.Ticket(),,iSlippage); }
seems that I had a very similar issue in 2020 haha.
https://www.mql5.com/en/forum/339064
i am going to re read the debugging material mentioned in the responses from back then.
- 2020.04.30
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Error in Journal...
"iStartLots" is 0.13 as input double. tk is the ticket (position.Ticket()).
What have i done wrong? 0.07 was closed, but I still got the error.
I have confirmed that lot step is 0.01, therefore it is not the lotstep issue.