Invalid Lot

 
void CheckForOpen() {

   int    res;
   double entry,stop,profit;
   
   if (exit) return;
   
//---- buy conditions
   if (addbuy)  {
res=OpenAtMarket(OP_BUY,_1stlots);
if (res<=0) Print("Error opening BUY order : ",ErrorDescription(GetLastError()));
else AdjustStops();
   }
//---- sell conditions
   if (addsell)  {
res=OpenAtMarket(OP_SELL,_1stlots);
if (res<=0) Print("Error opening SELL order : ",ErrorDescription(GetLastError()));
else AdjustStops();
   }

   if (last==Time[0]) return;

   ord=CalculateCurrentOrders();

   if (ord!=0) CheckForClose();

   ord=CalculateCurrentOrders();

//---- buy conditions
   if (ord==0 && buysig)  {
res=OpenAtMarket(OP_BUY,LotsRisk(SL));
if (res<0) Print("Error opening BUY order : ",ErrorDescription(GetLastError()));
else { last=Time[0]; _1stlots=LotsRisk(SL); _1stentry=entryprice; AdjustStops(); }
   }
//---- sell conditions
   if (ord==0 && sellsig)  {
res=OpenAtMarket(OP_SELL,LotsRisk(SL));
if (res<=0) Print("Error opening SELL order : ",ErrorDescription(GetLastError()));
else { last=Time[0]; _1stlots=LotsRisk(SL); _1stentry=entryprice; AdjustStops(); }
   }
}
  
int OpenAtMarket(int mode,double lot) {
   int    res,tr,col;
   double openprice,sl,tp;
   tries=0;
   while (res<=0 && tries<OrderTriesNumber) {
      tr=0; while (tr<5 && !IsTradeAllowed()) { tr++; Sleep(5000); }
      RefreshRates();
      if (mode==OP_SELL) {
         openprice=Bid; 
         col=Red;
      } else {
         openprice=Ask;
         col=Blue;
      }
      entryprice=openprice;
      if(OrdersTotal() >= ExtMaxOrders) return(0);
      Print("Lots: ", Lots);
      res=OrderSend(Symbol(),mode,lot,openprice,slippage,sl,tp,EAName+MagicNumber,MagicNumber,0,col);
      tries++;
   }
   return(res);
}

Hello

I am getting invalid lots amount for OrderSend function.

on a Demo account but not on a back test.

Could someone please have a look at the code and point me in the right direction as to where I might have gone wrong.

And I am using what is below to calculate lot size

Alpari are a 5 digit broker.

//--- calculate current volume
double LotsRisk(int StopLoss)  {
  {
   double lot_min =MarketInfo(Symbol(),MODE_MINLOT);
   double lot_max =MarketInfo(Symbol(),MODE_MAXLOT);
   double lot_step=MarketInfo(Symbol(),MODE_LOTSTEP);
   double contract=MarketInfo(Symbol(),MODE_LOTSIZE);
   double LotsRisk;
//--- check data
   if(lot_min<0 || lot_max<=0.0 || lot_step<=0.0) 
     {
      Print("CalculateVolume: invalid MarketInfo() results [",lot_min,",",lot_max,",",lot_step,"]");
      return(0);
     }
   if(AccountLeverage()<=0)
     {
      Print("CalculateVolume: invalid AccountLeverage() [",AccountLeverage(),"]");
      return(0);
     }
//--- basic formula
   LotsRisk=NormalizeDouble(AccountFreeMargin()*ExtMaximumRisk*AccountLeverage()/contract/SL,2);
//--- additional calculation
//   ...
//--- check min, max and step
   LotsRisk=NormalizeDouble(LotsRisk/lot_step,0)*lot_step;
   if(LotsRisk<lot_min) LotsRisk=lot_min;
   if(LotsRisk>lot_max) LotsRisk=lot_max;
//---
   return(LotsRisk);
  }
  }
 

Replace

Print("Lots: ", Lots);
to

Print("Lots: ", lot);
and show us what is in logs.

 
Roger wrote >>

Replace

Print("Lots: ", Lots);
to

Print("Lots: ", lot);
and show us what is in logs.

Yes I saw that and changed it and has shown OrderSend function problem.

but I just can't see where I have gone wrong.

 

OK, again, raplace

Print("Lots: ", lot);
to

Print("Lots: ", lot," minlot - ",MarketInfo(Symbol(),MODE_MINLOT));

and show me what is in logs.

 
kiwi06 wrote >>

Hello

I am getting invalid lots amount for OrderSend function.

on a Demo account but not on a back test.

Could someone please have a look at the code and point me in the right direction as to where I might have gone wrong.

And I am using what is below to calculate lot size

Alpari are a 5 digit broker.

Change:

LotsRisk=NormalizeDouble(AccountFreeMargin()*ExtMaximumRisk*AccountLeverage()/contract/SL,2);

to:

LotsRisk=NormalizeDouble(AccountFreeMargin()*ExtMaximumRisk*AccountLeverage()/contract/StopLoss,2);

or:

LotsRisk=AccountFreeMargin()*ExtMaximumRisk*AccountLeverage()/contract/StopLoss;

 
Roger wrote >>

OK, again, raplace

Print("Lots: ", lot);
to

Print("Lots: ", lot," minlot - ",MarketInfo(Symbol(),MODE_MINLOT));

and show me what is in logs.

gidday Roger

2009.11.01 23:06:05 EPA EURCHF,H4: Lots: 0 minlot - 0.01
2009.11.01 23:06:05 EPA EURCHF,H4: invalid lots amount for OrderSend function
2009.11.01 23:06:05 EPA EURCHF,H4: Lots: 0 minlot - 0.01
2009.11.01 23:06:05 EPA EURCHF,H4: invalid lots amount for OrderSend function
2009.11.01 23:06:05 EPA EURCHF,H4: Lots: 0 minlot - 0.01
2009.11.01 23:06:05 EPA EURCHF,H4: MA=1.5094 BuyStop=1.5091

 
OK, next step:
replace:
if(lot_min<0 || lot_max<=0.0 || lot_step<=0.0)
to
if(lot_min<=0 || lot_max<=0.0 || lot_step<=0.0)
add after:
LotsRisk=NormalizeDouble(LotsRisk/lot_step,0)*lot_step;
if(LotsRisk<lot_min) LotsRisk=lot_min;
if(LotsRisk>lot_max) LotsRisk=lot_max;
this string:
Print("LotsRisk - ",LotsRisk);
and last question - Why do you have parameter int StopLoss in the function double LotsRisk(int StopLoss)
but inside you use SL parameter?
 

Thanks for your help guys I have managed to sort the problem out.

Cheers

Kiwi

 
Richard:

Thanks for your help guys I have managed to sort the problem out.

Cheers

Kiwi

pls how did you solve this problem i am having this issue as well
 
Damilare15:
pls how did you solve this problem i am having this issue as well

I doubt that he will answer after 12 years.