Need help with simple EA

 

I am working on a simple EA but I get the error 131 and this is because of the variable

ultimul_lot

in the function OpenOrder where I make:

ultimul_lot*multiply_lots;

ultimul_lot gets the value 1.#INF but I do not understand why...


The ideea is that if the last trade was not profitable it will double the last trade's lots; if the last trade was profitable the next trade will have the initial no. of lots ("loturi").


Could someone help me on this isue?




#property copyright "Darzan Mihai"
#property link      "www.digitalenergy.ro"


extern int SignalGap = 10;
extern double loturi=0.1;
extern double multiply_lots=3;
int gi_80 = 24;
string sugestie;
double ultimul_profit;
double ultimul_lot;

int init() {
   sugestie="";
   ultimul_lot=0.1;
   ultimul_profit=0;
   return (0);
}

int start() {
   int l_highest_24;
   int l_lowest_28;
   sugestie="";   
   int li_20 = 2;
   
   double Sell_pos,Buy_pos;
   
   for (int li_12 = li_20; li_12 >= 0; li_12--) {
      l_highest_24 = iHighest(NULL, 0, MODE_HIGH, gi_80, li_12 - gi_80 / 2);
      l_lowest_28 = iLowest(NULL, 0, MODE_LOW, gi_80, li_12 - gi_80 / 2);
      if (li_12 == l_highest_24) {Sell_pos = High[l_highest_24] + SignalGap * Point;sugestie="sell";}//sell
      if (li_12 == l_lowest_28)  {Buy_pos  =  Low[l_lowest_28]  - SignalGap * Point;sugestie="buy" ;}//buy
      if (li_12 != l_lowest_28 && li_12 != l_highest_24){sugestie="";}//asteapta
   }
   Display_Info();
   Print("------",ultimul_lot,"------- 1");
   int cntb = count_ord("b");
   int cnts = count_ord("s");
   if (sugestie=="buy" && cntb==0){OrderOp(sugestie);}
   if (sugestie=="sell" && cnts==0){OrderOp(sugestie);}
   //Print("------",ultimul_lot,"------- 2");
   return (0);
}

void Display_Info() {
   int li_4 = IndicatorCounted();
   Comment("Sugestie: "+sugestie+"\n",
            "Ultimul profit: "+ultimul_profit+"\n",
            "Ultimul lot: "+ultimul_lot);
}

void OrderOp(string sugestie){
   double CurrStopOutLvl = NormalizeDouble(AccountMargin()*100/AccountEquity(),2);
   if(sugestie!=""){
      ultimul_profit = CloseAllSymbol(sugestie);
     // Print("------",ultimul_lot,"-------");
      ultimul_lot = OpenOrder(sugestie);
      //Print("------",ultimul_lot,"-------");
   }      
}

double CloseAllSymbol(string sugestie){
   double profit=0;
   
   for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) {
      OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol()) {
         profit +=OrderProfit();
         if (OrderType() == OP_BUY && sugestie=="sell") {OrderClose(OrderTicket(), OrderLots(), Bid, 3, Blue);}
         if (OrderType() == OP_SELL && sugestie=="buy"){OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red );}         
      }
   }
   if (profit!=0){return (profit);}else{return(ultimul_profit);}
}

double OpenOrder(string sugestie){  
   double loturi_x=ultimul_lot;
   if (ultimul_profit<0){loturi_x=ultimul_lot*multiply_lots;}else{loturi_x=loturi;}
   if (sugestie=="buy" && count_ord("b")==0){//buy
      OrderSend(Symbol(), OP_BUY, loturi_x, Ask, 0, 0, 0, NULL, 0, 0, SeaGreen); 
   }else if(sugestie=="sell" && count_ord("s")==0){//sell
      OrderSend(Symbol(), OP_SELL,loturi_x, Bid, 0, 0, 0, NULL, 0, 0, Crimson);
   }
   Sleep(3000);   
   return(loturi_x);
}

int count_ord(string tip="s"){
   int count=0;
   for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) {
      OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol()) {
         if (OrderType() == OP_BUY && tip=="b") {count+=1;}
         if (OrderType() == OP_SELL && tip=="s"){count+=1;}         
      }
   }
   return (count);
}
 

What does this mean?

"ultimul_lot gets the value 1.#INF but I do not understand why..."

Is the lot value 1?

If it is then there should not be a problem.

 
Ruptor:

What does this mean?

"ultimul_lot gets the value 1.#INF but I do not understand why..."

Is the lot value 1?

If it is then there should not be a problem.


first of all, thx for reply!


1.#INF means infinite (such as x/0) and that is not ok...

 
extern double multiply_lots=3;
int init() {   ultimul_lot=0.1; //...}

void OrderOp(string sugestie){//...
      ultimul_lot = OpenOrder(sugestie);
}
double OpenOrder(string sugestie){  
   double loturi_x=ultimul_lot;
   if (ultimul_profit<0){loturi_x=ultimul_lot*multiply_lots;}else{loturi_x=loturi;}
//...
   return(loturi_x);
}

On the first call to OpenOrder ultimul_lot=0.1 and after OrderOp sets it to 0.1*3 or 0.3.

On the second call it becomes 0.9. Third 2.7, etc becomes infinite quickly.

 
WHRoeder:

On the first call to OpenOrder ultimul_lot=0.1 and after OrderOp sets it to 0.1*3 or 0.3.

On the second call it becomes 0.9. Third 2.7, etc becomes infinite quickly.

you are corect...thx

Reason: