MQL4 - automated forex trading   /  

Forum

Need help with simple EA

Back to topics list To post a new topic, please log in or register

avatar
7
darzanmihai 2010.03.05 13:08 

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);
}
Betting Modeling as Means of Developing "Market Intuition"

Betting Modeling as Means of Developing "Market Intuition"

The article dwells on the notion of "market intuition" and ways of developing it. The method described in the article is based on the modeling of financial betting in the form of a simple game.


avatar
426
Ruptor 2010.03.05 19:34 

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.



avatar
7
darzanmihai 2010.03.05 21:25 
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...


avatar
4328
WHRoeder 2010.03.06 20:08 
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.


avatar
7
darzanmihai 2010.03.06 23:33 
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

Back to topics list  

To add comments, please log in or register