Trying to wite a MQL4 code

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
11
Eddiedewaal 2015.05.06 15:04 #
 
Thank you
avatar
Moderator
3427
GumRai 2015.05.07 00:10 #
 

Is this in a function?

for(int i=OrdersTotal(); i<0; --i)
{
   OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);

   if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&OrderProfit()>0)   
      {
      return(1);
      }
   if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&OrderProfit()<0)
      {
      return(0);
      }  
   if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&OrderProfit()>0)
      {
      return(0);
      }  
   if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&OrderProfit()<0)
      {
      return(1);
      }

 If not, why are you using return in a loop?

Why are you using the value of OrdersTotal and then checking History? 

OrdersTotal can only be a positive number or zero, so your loop will not run with i<0.  

avatar
11
Eddiedewaal 2015.05.07 13:30 #
 
GumRai:

Is this in a function?

 If not, why are you using return in a loop?

Why are you using the value of OrdersTotal and then checking History? 

OrdersTotal can only be a positive number or zero, so your loop will not run with i<0.  

Chances are its way wrong. Only stated with MQL4 this week. I tried some of the other "last profit" codes in the forum. Cant seem to get it right though.

 

string last;
for(int i=OrdersHistoryTotal()-1;i>=0;i--)
 {
   OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS,MODE_HISTORY);
   
   if(OrderSymbol()==Symbol() && OrderMagicNumber()==magicnumber)
    {
       //for buy order
       if(OrderProfit() > 0) Alert("profit");
       else if(OrderProfit() < 0) Alert("loss");
    }
 }

 

This is another piece of code I am trying.

 Ill keep at it til I get it right. 

avatar
11
Eddiedewaal 2015.05.07 13:31 #
 
GumRai:

Is this in a function?

 If not, why are you using return in a loop?

Why are you using the value of OrdersTotal and then checking History? 

OrdersTotal can only be a positive number or zero, so your loop will not run with i<0.  

Yes it is in a function
Back to topics list   | 1 2  

To add comments, please log in or register