Problem with lot

[Deleted]  

i just start learnig how to coding, and somehow i managed to finish 1 EA.

So i BT and the result is pretty fair, but when i try the EA in demo acc, i get some problem...

here what i get invalid lots amount for OrderSend function, i try to solve the problem by myself by reading some forum posts, but since i beginner, i just can't solve it...

this is the source of the EA, can someone tell me how to fix that....

extern int TakeProfit = 10;
extern int PipStep = 10;
extern int Slippage = 3;
extern double Lots = 0.1;
extern double Multiply = 2.0;
extern int MaxTrade = 11;
extern bool UseTime = TRUE;
extern int HourStart = 00;
extern int HourEnd = 24;


/*-- \---------------------\ --*/
string EAName = "EA MartiDemon"; //Name
string EAComment = "Syguitara"; // Variabel
int EAMagicNumber = 2211; // Magic Number
double SetPoint = 0; // SetPoint variable for 4 /5 dgt broker

int BarCount;
int Current;
bool TickCheck = true;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

SetBroker();

//----
return(0);
}


//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

int iTrade=0;

double Buy1_1 = iOpen(NULL, PERIOD_D1, + 1);
double Buy1_2 = iClose(NULL, PERIOD_D1, Current + 1);
double Buy2_1 = iOpen(NULL, PERIOD_H4, Current + 1);
double Buy2_2 = iClose(NULL, PERIOD_H4, Current + 1);
double Buy3_1 = iOpen(NULL, PERIOD_H1, Current + 1);
double Buy3_2 = iClose(NULL, PERIOD_H1, Current + 1);
double Buy4_1 = iOpen(NULL, PERIOD_M30, Current + 1);
double Buy4_2 = iClose(NULL, PERIOD_M30, Current + 1);
double Buy5_1 = iOpen(NULL, PERIOD_M15, Current + 1);
double Buy5_2 = iClose(NULL, PERIOD_M15, Current + 1);
double Buy6_1 = iOpen(NULL, PERIOD_M5, Current + 1);
double Buy6_2 = iClose(NULL, PERIOD_M5, Current + 1);

double Sell1_1 = iOpen(NULL, PERIOD_D1, Current + 1);
double Sell1_2 = iClose(NULL, PERIOD_D1, Current + 1);
double Sell2_1 = iOpen(NULL, PERIOD_H4, Current + 1);
double Sell2_2 = iClose(NULL, PERIOD_H4, Current + 1);
double Sell3_1 = iOpen(NULL, PERIOD_H1, Current + 1);
double Sell3_2 = iClose(NULL, PERIOD_H1, Current + 1);
double Sell4_1 = iOpen(NULL, PERIOD_M30, Current + 1);
double Sell4_2 = iClose(NULL, PERIOD_M30, Current + 1);
double Sell5_1 = iOpen(NULL, PERIOD_M15, Current + 1);
double Sell5_2 = iClose(NULL, PERIOD_M15, Current + 1);
double Sell6_1 = iOpen(NULL, PERIOD_M5, Current + 1);
double Sell6_2 = iClose(NULL, PERIOD_M5, Current + 1);

Comment(EAName); // Display

/* -- if no op start function --*/
/* -- op logic --*/
if(OrdersTotal()==0)
{

if(Buy1_1 < Buy1_2 && Buy2_1 < Buy2_2 && Buy3_1 < Buy3_2 && Buy4_1 < Buy4_2 && Buy5_1 < Buy5_2 && Buy6_1 < Buy6_2)
{
/*-- Order Buy --*/
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, Ask+TakeProfit*SetPoint, EAComment, EAMagicNumber);

}

if (Sell1_1 > Sell1_2 && Sell2_1 > Sell2_2 && Sell3_1 > Sell3_2 && Sell4_1 > Sell4_2 && Sell5_1 > Sell5_2 && Sell6_1 > Sell6_2)
{
/*-- Order Sell --*/
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, Bid-TakeProfit*SetPoint, EAComment, EAMagicNumber);
}

}

/* -- Martidemon, there you go!! --*/
if(OrdersTotal()>=1)
{
GoMartingale();
}

//----
return(0);
}
//+------------------------------------------------------------------+

/*--for a picky one--*/
void SetBroker()
{
if (Digits==3 || Digits==5) // 5
{SetPoint=Point*10;}
else // 4
{SetPoint=Point;}
}

void GoMartingale()
{
int iCount = 0;
double LastOP = 0;
double LastLots = 0;
bool LastIsBuy = FALSE;
int iTotalBuy = 0;
int iTotalSell = 0;
int Spread=0;

Spread= MarketInfo(Symbol(), MODE_SPREAD);


for(iCount=0;iCount<OrdersTotal();iCount++)
{

OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);

if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(LastOP==0) {LastOP=OrderOpenPrice();}
if(LastOP>OrderOpenPrice()) {LastOP=OrderOpenPrice();}
if(LastLots<OrderLots()) {LastLots=OrderLots();}
LastIsBuy=TRUE;
iTotalBuy++;

/* dont blow your money */
if(iTotalBuy==MaxTrade) {return(0);}
}

if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(LastOP==0) {LastOP=OrderOpenPrice();}
if(LastOP<OrderOpenPrice()) {LastOP=OrderOpenPrice();}
if(LastLots<OrderLots()) {LastLots=OrderLots();}
LastIsBuy=FALSE;
iTotalSell++;

/* stop it */
if(iTotalSell==MaxTrade) {return(0);}
}

}

/* downtrend...., bid (*/
if(LastIsBuy)
{
if(Bid<=LastOP-(Spread*SetPoint)-(PipStep*SetPoint))
{
OrderSend(Symbol(), OP_BUY, Multiply*LastLots, Ask, Slippage, 0, Ask+TakeProfit*SetPoint, EAComment, EAMagicNumber);
ModifyTP();
LastIsBuy=FALSE;
return(0);
}
}
/* sell...., Ask (*/
else if(!LastIsBuy)
{
if(Ask>=LastOP+(Spread*SetPoint)+(PipStep*SetPoint))
{
OrderSend(Symbol(), OP_SELL, Multiply*LastLots, Bid, Slippage, 0, Bid-TakeProfit*SetPoint, EAComment, EAMagicNumber);
ModifyTP();
return(0);
}
}

}

/*-- TP function --*/
void ModifyTP()
{
int iCount=0;
double NewTP=0;

/*- Take TP from last value -*/
for(iCount=0;iCount<OrdersTotal();iCount++)
{

OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);

/*-- all buy, make one tp --*/
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(NewTP==0) {NewTP=OrderTakeProfit();}
if(NewTP>OrderTakeProfit()) {NewTP=OrderTakeProfit();}

}

/*-- all sell, make one tp --*/
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(NewTP==0) {NewTP=OrderTakeProfit();}
if(NewTP<OrderTakeProfit()) {NewTP=OrderTakeProfit();}
}

}

/*- change all op to the new tp -*/
for(iCount=0;iCount<OrdersTotal();iCount++)
{

OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);

/*- lalalalalala -*/
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);
}

/*- lulululululu -*/
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);
}

}
}//+------------------------------------------------------------------+


i do my best to solve it but my 'best' is not good enogh i think.....

 
syguitara:

i just start learnig how to coding, and somehow i managed to finish 1 EA.

So i BT and the result is pretty fair, but when i try the EA in demo acc, i get some problem...

here what i get invalid lots amount for OrderSend function, i try to solve the problem by myself by reading some forum posts, but since i beginner, i just can't solve it...

this is the source of the EA, can someone tell me how to fix that....

i do my best to solve it but my 'best' is not good enogh i think.....

Hi syguitara,

1. When posting code, use SRC button is better than using code text field

2. Your lot calculation should follow the rules of MarketInfo() function - click that, and they are :

MarketInfo (Symbol(), MODE_MINLOT );
MarketInfo (Symbol(), MODE_LOTSTEP);
MarketInfo (Symbol(), MODE_MAXLOT);

Can you rewrite your code now ? just the lot calculation, we'll help you correct it.


[Deleted]  
onewithzachy:

Hi syguitara,

1. When posting code, use SRC button is better than using code text field

2. Your lot calculation should follow the rules of MarketInfo() function - click that, and they are :

Can you rewrite your code now ? just the lot calculation, we'll help you correct it.



thank you before for the guide for SCR button, n for the the code, of course i will do it, i'll be back soon after i rewrite the code...
once again im very greatful that some willing to help me....
[Deleted]  

can you tell me more spesific about rewrite the lot calculation, im at lost here...

and one more thing, i just noticed that the problem occur when i attach the EA to multiple charts, since with only 1 chart, the EA work normally...

 
syguitara:

can you tell me more spesific about rewrite the lot calculation, im at lost here...

and one more thing, i just noticed that the problem occur when i attach the EA to multiple charts, since with only 1 chart, the EA work normally...

hi syguitara,

Lot is MODE_MINLOT and how many MODE_STEPLOT as long as not bigger that MODE_MAXLOT.

Can you write the code ? it's only 11 lines :)

the first 5 are ... :D

  double min_lot, step_lot, max_lot;
  int step;
  
  min_lot  = MarketInfo (Symbol(), MODE_MINLOT);
  step_lot = MarketInfo (Symbol(), MODE_LOTSTEP);
  max_lot  = MarketInfo (Symbol(), MODE_MAXLOT);

I don't know the answer why the EA does not work on multiple chart, so let's solve the lot first.


 

Hi syguitara,

I think this

if(OrdersTotal()==0) 

is the main cause why your EA does not work on multiple chart/symbol.

Just imagine what happen when you attach the first EA,then imagine again what happen when you attach the second, and the third, and so on.

[Deleted]  

hi one....

the next 6 lines....?

to be honest i just want to write 6 lines of i dont know, but i'll try

    lots = MathRound(lots/ls) * ls;
    if (lots < minLot) lots = 0;    // or minLot
    else
    if (lots > minLot) lots = step_lot;    
    return(lots);
}

well, just think im tryin to joking here....


if(OrdersTotal()==0) 

so what are you suggest me for that problem?

 

Hi syguitara,

Alright, your next 6 lines may be different than mine. Here's my next 6 lines

double CHECK_LOT (double lot)
  {
  double min_lot, step_lot, max_lot;
  int step;
  
  min_lot  = MarketInfo (Symbol(), MODE_MINLOT);
  step_lot = MarketInfo (Symbol(), MODE_LOTSTEP);
  max_lot  = MarketInfo (Symbol(), MODE_MAXLOT);
  
  if (lot < min_lot) return(0);
  
  lot   = lot - min_lot;
  step  = lot/step_lot;
  
  lot   = min_lot + step*step_lot;
  if (lot > max_lot) lot = max_lot;
  
  return (lot);
  }

Compiled, but not checked.

As for the problem of OrdersTotal() == 0, you have to check the magic number.

[Deleted]  
i see, it's true that i've been playing with that magic number yesterday,...
thanks a lot, i'll fix the problem now...