i am getting the unknown ticket number and order close error 4108 when i backtest my ea using moving averages
while(true) { bool result = OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); if(result !=true) { Print("Closing failed"); } else Print("Closing Succesful"); }
Please use the insert code button when pasting code.
You never break from the while loop.

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
void CheckForMaTrade()
{
double PreviousMustard = iMA(NULL,0,MustardMA,MustardMaShift,MustardMaMethod,MustardMaAppliedTo,2);
double CurrentMustard = iMA(NULL,0,MustardMA,MustardMaShift,MustardMaMethod,MustardMaAppliedTo,1);
double PreviousWater = iMA(NULL,0,WaterMA,WaterMaShift,WaterMaMethod,WaterMaAppliedTo,2);
double CurrentWater = iMA(NULL,0,WaterMA,WaterMaShift,WaterMaMethod,WaterMaAppliedTo,1);
double PreviousBlood = iMA(NULL,0,BloodMA,BloodMaShift,BloodMaMethod,BloodMaAppliedTo,2);
double CurrentBlood = iMA(NULL,0,BloodMA,BloodMaShift,BloodMaMethod,BloodMaAppliedTo,1);
if (PreviousMustard > PreviousBlood && CurrentMustard < CurrentBlood) OrderEntry(1);OrderClosing(1);
if(PreviousMustard < PreviousWater && CurrentMustard > CurrentWater) OrderEntry(2);OrderClosing(2);
if(PreviousMustard > PreviousWater && CurrentMustard < CurrentWater) OrderEntry(3);OrderClosing(3);
if(PreviousBlood < PreviousWater && CurrentBlood > CurrentWater) OrderEntry(4);OrderClosing(4);
if(PreviousBlood > PreviousWater && CurrentBlood < CurrentWater) OrderEntry(5);OrderClosing(5);
}
void OrderEntry ( int direction)
{
if(direction == 0)
if(OpenOrdersThisPair(Symbol())==0)
int buyticket1=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*pips,Ask+TakeProfit*pips,"buy robot",MagicNumber,0,Green);
if(OpenOrdersThisPair(Symbol())==0)
int buyticket2=OrderSend (Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*pips,Bid-TakeProfit*pips," Sell robot ",MagicNumber4,0,Red);
if(direction == 2)
if(OpenOrdersThisPair(Symbol())==1)
int buyticket3 =OrderSend (Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*pips,Ask+TakeProfit*pips,"buy robot",MagicNumber2,0,Green);
if(direction == 3)
if(OpenOrdersThisPair(Symbol())==1)
int sellticket1 =OrderSend (Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*pips,Bid-TakeProfit*pips," Sell robot ",MagicNumber5,0,Red);
if(direction == 4)
if(OpenOrdersThisPair(Symbol())==2)
int sellticket2 =OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*pips,Ask+TakeProfit*pips,"buy robot",MagicNumber3,0,Green);
if(direction == 5)
if(OpenOrdersThisPair(Symbol())==2)
int sellticket3 =OrderSend (Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*pips,Bid-TakeProfit*pips," Sell robot ",MagicNumber6,0,Red);
}
void OrderClosing (int direction)
{
if(direction ==0)
if(OrderSymbol()==Symbol ())
{
for(int i=OrdersTotal()-1; i >=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber4)
{
while(true)
{
bool result = OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
if(result !=true)
{
Print("Closing failed");
}
else Print("Closing Succesful");
}
}
}
else Print ("When Selecting a trade,error",GetLastError(),"occured");
}
}
//////////////////////////////////////////////
if(direction ==1)
if(OrderSymbol()==Symbol ())
{
for(int i=OrdersTotal()-1; i >=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber5)
{
while(true)
{
bool result = OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
if(result !=true)
{
Print("Closing failed");
}
else
Print("cLOSING SUCCESFUL");
}
}
}
else Print ("When Selecting a trade,error",GetLastError(),"occured");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
if(direction ==2)
if(OrderSymbol()==Symbol ())
{
for(int i=OrdersTotal()-1; i >=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber6)
{
while(true)
{
bool result = OrderClose(OrderTicket(),OrderLots(),Ask,3,Green);
if(result !=true)
{
Print("CLOSING FAILED");
}
else
Print("Closing Succesful");
}
}
}
else Print ("When Selecting a trade,error",GetLastError(),"occured");
}
}
/////////////////////////////////////////////////////////////////////////////////
if(direction ==3)
if(OrderSymbol()==Symbol ())
{
for(int i=OrdersTotal()-1; i >=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber)
{
while(true)
{
bool result = OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
if(result !=true)
{
Print("Closing Failed");
}
else Print ("Closing Succesfull");
}
}
}
else Print ("When Selecting a trade,error",GetLastError(),"occured");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
if(direction ==4)
if(OrderSymbol()==Symbol ())
{
for(int i=OrdersTotal()-1; i >=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber2)
{
while(true)
{
bool result = OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
if(result !=true)
{
Print("CLOSING FAILED");
}
else Print("Closing SUCCESFUL");
}
}
}
else Print ("When Selecting a trade,error",GetLastError(),"occured");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
if(direction ==5)
if(OrderSymbol()==Symbol ())
{
for(int i=OrdersTotal()-1; i >=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType() == OP_BUY && OrderMagicNumber()==MagicNumber3)
{
while(true)
{
bool result = OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
if(result !=true)
{
Print ("Closing Failed");
}
else Print ("Closing SUCCESFUL");
}
}
}
else Print ("When Selecting a trade,error",GetLastError(),"occured");
}
}
}