Range Breakout EA MT5 issues
Modified two functions:
bool ClosePositions(){ for(int i=PositionsTotal()-1; i>=0; i--){ ulong ticket = PositionGetTicket(i); if(ticket<=0){Print("Failed to get position ticket"); return false;} if(!PositionSelectByTicket(ticket)){Print("Failed to select position by ticket"); return false;} long magicnumber; if(!PositionGetInteger(POSITION_MAGIC,magicnumber)){Print("Failed to get position magicnumber"); return false;} if(!magicnumber == InpMagicNumber){ trade.PositionClose(ticket); if(trade.ResultRetcode()!=TRADE_RETCODE_DONE){ Print("Failed to close position: " +(string)trade.ResultRetcode()+":"+trade.ResultRetcodeDescription()); return false; } } } return true; }
int CountOpenPositions(){ int counter = 0; for(int i=PositionsTotal()-1; i>=0; i--){ ulong ticket = PositionGetTicket(i); if(ticket<=0){Print("Failed to get positions ticket"); ExpertRemove();return -1;} if(!PositionSelectByTicket(ticket)){Print("Failed to select position by ticket"); return-1;} ulong magicnumber; if(!PositionGetInteger(POSITION_MAGIC,magicnumber)){Print("Failed to get position magicnumber"); return -1;} if(InpMagicNumber==magicnumber){counter++;} } return counter; }
Mostly it trades as it should but there are some moments or days when range is not removed after trade is closed. I don't understand where the problem occurs. Is it something with my tester, broker or what?
timmytrade #:
Looks like it waits for previous trade to close before going for a new setup.
Mostly it trades as it should but there are some moments or days when range is not removed after trade is closed. I don't understand where the problem occurs. Is it something with my tester, broker or what?


I wrote that code by some youtube programming channel.
No errors, compiles fine but in tester DrawingObjects doesn't look right(specially range) and finally it stops taking trades(probably because of that buggy range)