New to Coding need a little Help

 
So I made an EA solely for entries a couple weeks ago and now I'm looking to turn my robot to fully automated my problem here is I'm getting error now with TotalNooforders() with my code now when I applied an exit strategy using RSI.  Please can someone help me here's the code
extern    int MagicNumber = 12345;
extern    double lots = 0.10;
extern    int stopLoss = 1000;
extern    int takeProfit = 2000;
extern    int Slippage = 0;
void OnTick()
  {
  if (TotalNoOfOrders() > 0) {
        return;
    
     
    double ema = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, 0);
    double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0);
    double adx = iADX(NULL, 0, 14, PRICE_CLOSE, 0, 0);    
    
     
    if ((ema > ema2)&&(adx > 50)) {
        if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips", MagicNumber, 0, Blue)) {
            Print("Buy order succeeded!");
        }
    }


    if ((ema < ema2)&&(adx > 50)) {
        if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips", MagicNumber,0, Red)) {
            Print("Sell order succeeded!");
        }
    }

//---
  {
         if(OrderType()==OP_BUY)  
           {
              if((iRSI(NULL,0,14,PRICE_HIGH,0)>70)) //here is my close buy rule
              {
                   OrderClose(OrderSymbol(),OrderLots(),OrderClosePrice(),0,Red);
              }  
              
           }
         else 
           {
           if(OrderType()==OP_SELL)
             {
                if((iRSI(NULL,0,14,PRICE_LOW,0)<30)) // here is my close sell rule
                {
                   OrderClose(OrderSymbol(),OrderLots(),OrderClosePrice(),0,Red);
                }  
              }
           }
        }
   
  
//+------------------------------------------------------------------+



int TotalNoOfOrders(){ 
   int cnt, total; 
   int i = 0;
   total = OrdersTotal(); 
   for(cnt=0;cnt<total; cnt++){ 
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
         i++; 
   }
   return(i);
}
}
}
 
Angel Dickinson:
So I made an EA solely for entries a couple weeks ago and now I'm looking to turn my robot to fully automated my problem here is I'm getting error now with TotalNooforders() with my code now when I applied an exit strategy using RSI.  Please can someone help me here's the code

Hi,

I hope this can help :)

int TotalNoOfOrders()
{ 
   int cnt=0, total, ticket; 
   total = OrdersTotal(); 
   for(int i=total-1; i>=0; i--)
   {
      ticket=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()>=2 || OrderMagicNumber()!=MagicNumber) continue;
      
      cnt++; 
   }
   return(cnt);
}

and also, your opening order :

if ((ema > ema2)&&(adx > 50)) {
        if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips", MagicNumber, 0, Blue)) {
            Print("Buy order succeeded!");
        }

might need some modification like this :

     ResetLastError();
     ticket=OrderSend(Symbol(),OP_BUY,NormalizeDouble(lots,2),Ask,your_slippage,your_sl,your_tp,your_log,MagicNumber,0,clrBlue);
     if(ticket<=0)
     {
      
      error=GetLastError();     
      //-- do something for errors ....

     }
     else 
     { 
       Print("Buy order succeeded!");
       //-- do something for succesful order
     }

Good luck (^̮^)

 
Angel Dickinson:
So I made an EA solely for entries a couple weeks ago and now I'm looking to turn my robot to fully automated my problem here is I'm getting error now with TotalNooforders() with my code now when I applied an exit strategy using RSI.  Please can someone help me here's the code

Hi, do you have double post here? https://www.mql5.com/en/forum/211537

You have been greatly assisted by the master coder there.
EA only opens trades 1 by 1
EA only opens trades 1 by 1
  • 2017.07.18
  • www.mql5.com
So I built an EA only for entries nothing else...
 
Angel Dickinson:
So I made an EA solely for entries a couple weeks ago and now I'm looking to turn my robot to fully automated my problem here is I'm getting error now with TotalNooforders() with my code now when I applied an exit strategy using RSI.  Please can someone help me here's the code

extern    int MagicNumber = 12345;
extern    double lots = 0.10;
extern    int stopLoss = 1000;
extern    int takeProfit = 2000;
extern    int Slippage = 0;

int TotalNoOfOrders(int cnt, int i)
   {
   for(;cnt<OrdersTotal(); cnt++)
      {
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
         i++;
      }
   return(i);   
   }
   

void OnTick()
  {
  if (TotalNoOfOrders(0,0) > 0) {
        return;
    
     
    double ema = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, 0);
    double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0);
    double adx = iADX(NULL, 0, 14, PRICE_CLOSE, 0, 0);    
    
     
    if ((ema > ema2)&&(adx > 50)) {
        if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips", MagicNumber, 0, Blue)) {
            Print("Buy order succeeded!");
        }
    }


    if ((ema < ema2)&&(adx > 50)) {
        if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips", MagicNumber,0, Red)) {
            Print("Sell order succeeded!");
        }
    }

//---
  {
         if(OrderType()==OP_BUY)  
           {
              if((iRSI(NULL,0,14,PRICE_HIGH,0)>70)) //here is my close buy rule
              {
                   OrderClose(OrderSymbol(),OrderLots(),OrderClosePrice(),0,Red);
              }  
              
           }
         else
           {
           if(OrderType()==OP_SELL)
             {
                if((iRSI(NULL,0,14,PRICE_LOW,0)<30)) // here is my close sell rule
                {
                   OrderClose(OrderSymbol(),OrderLots(),OrderClosePrice(),0,Red);
                }  
              }
           }
        }
   
 
//+------------------------------------------------------------------+




}
}


I changed only the function TotalNoOfOrders, but if it will be doing what you want, I don't know.

 
Yohana Parmi:

Hi,

I hope this can help :)

and also, your opening order :

might need some modification like this :

Good luck (^̮^)

Ok after looking at your code my problem doesn't lie in the entry it lies in the exit strategy I'm guessing its a problem with the TotalNoOfOrders function but now I'm getting these errors on the code you provided. attached a screenshot of the errors. and here is the code modified with TotalNoOfOrders you gave me
extern    int MagicNumber = 12345;
extern    double lots = 0.10;
extern    int stopLoss = 1000;
extern    int takeProfit = 2000;
extern    int Slippage = 0;
void OnTick()
  {
  if (TotalNoOfOrders() > 0) {
        return;
    
     
    double ema = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, 0);
    double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0);
    double adx = iADX(NULL, 0, 14, PRICE_CLOSE, 0, 0);    
    
     
    if ((ema > ema2)&&(adx > 50)) {
        if (OrderSend(Symbol(), OP_BUY, lots, Ask, 3, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips", MagicNumber, 0, Blue)) {
            Print("Buy order succeeded!");
        }
    }


    if ((ema < ema2)&&(adx > 50)) {
        if (OrderSend(Symbol(), OP_SELL, lots, Bid, 3, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips", MagicNumber,0, Red)) {
            Print("Sell order succeeded!");
        }
    }
}
}
//---
         if(OrderType()==OP_BUY)  
           {
              if((iRSI(NULL,0,14,PRICE_HIGH,0)>70)) //here is your close buy rule
              {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
              }  
              
           }
         else 
           {
           if(OrderType()==OP_SELL)
             {
                if((iRSI(NULL,0,14,PRICE_LOW,0)<30)) // here is your close sell rule
                {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red);
                }  
              }
           }
  
//+------------------------------------------------------------------+



int TotalNoOfOrders()
{ 
   int cnt=0, total, ticket; 
   total = OrdersTotal(); 
   for(int i=total-1; i>=0; i--)
   {
      ticket=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()>=2 || OrderMagicNumber()!=MagicNumber) continue;
      
      cnt++; 
   }
   return(cnt);
}
 
Yohana Parmi:

Hi, do you have double post here? https://www.mql5.com/en/forum/211537

You have been greatly assisted by the master coder there.

Ok so I applied your code fully even with the modified code for opening trade but now I'm getting these errors? I have tried everything I know any help? Attached is the picture of the errors. And why do I see an error of return value of 'OrderClose' should be checked?

extern    int MagicNumber = 12345;
extern    double lots = 0.10;
extern    int stopLoss = 1000;
extern    int takeProfit = 2000;
extern    int Slippage = 0;
void OnTick()
  {
  if (TotalNoOfOrders() > 0) {
        return;
    
     
    double ema = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, 0);
    double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0);
    double adx = iADX(NULL, 0, 14, PRICE_CLOSE, 0, 0);    
    
     
    if ((ema > ema2)&&(adx > 50)) {
        ResetLastError();
     ticket=OrderSend(Symbol(),OP_BUY,NormalizeDouble(lots,2), Ask, Slippage, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips" ,MagicNumber,0, clrBlue);
     if(ticket<=0)
     {
      
      error=GetLastError();     
      //-- do something for errors ....

     }
     else 
     { 
       Print("Buy order succeeded!");
       //-- do something for succesful order
     }
        }
    }


    if ((ema < ema2)&&(adx > 50)) {
        ResetLastError();
     ticket=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lots,2),Bid, Slippage, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips" ,MagicNumber,0,clrRed);
     if(ticket<=0)
     
     {
      
      error=GetLastError();     
      //-- do something for errors ....

     }
     else 
     { 
       Print("Sell order succeeded!");
       //-- do something for succesful order
     }
        }
    

  {
         if(OrderType()==OP_BUY)  
           {
              if((iRSI(NULL,0,14,PRICE_HIGH,0)>70)) //here is your close buy rule
              {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
              }  
              
           }
         else 
           {
           if(OrderType()==OP_SELL)
             {
                if((iRSI(NULL,0,14,PRICE_LOW,0)<30)) // here is your close sell rule
                {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red);
                }  
              }
           }
        }
     }      
        
  
//+------------------------------------------------------------------+



int TotalNoOfOrders()
{ 
   int cnt=0, total, ticket; 
   total = OrdersTotal(); 
   for(int i=total-1; i>=0; i--)
   {
      ticket=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()>=2 || OrderMagicNumber()!=MagicNumber) continue;
      
      cnt++; 
   }
   return(cnt);
}
 
Angel Dickinson:

Ok so I applied your code fully even with the modified code for opening trade but now I'm getting these errors? I have tried everything I know any help? Attached is the picture of the errors.


Check again,

1. Where "}" is needed?

if (TotalNoOfOrders() > 0) {
        return;
    
     
    double ema = i

2.  You don't have ticket as global variable.

if ((ema < ema2)&&(adx > 50)) {
        ResetLastError();
     ticket=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lots,2),Bid, Slippage, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips" ,MagicNumber,0,clrRed);
     if(ticket<=0)
int TotalNoOfOrders()
{ 
   int cnt=0, total, ticket; 
   total = OrdersTotal(); 
   for(int i=total-1; i>=0; i--)
   {
      ticket=OrderSelect(i,SELECT_BY

define ticket at above :

extern    int takeProfit = 2000;
extern    int Slippage = 0;
//-------
int ticket, error;

void OnTick()
  {
int TotalNoOfOrders()
{ 
   int cnt=0, total; 
   total = OrdersTotal(); 
   for(int i=total-1; i>=0; i--)
   {
 

There, that was "a little Help", as you called it...

If you can't get it done, ask for a lot of help, not just a little, or you can please try Freelance here: https://www.mql5.com/en/job

Freelance service at MQL5.com
Freelance service at MQL5.com
  • www.mql5.com
Orders for the development of automated trading programs
 
Marco vd Heijden:

There, that was "a little Help", as you called it...

If you can't get it done, ask for a lot of help, not just a little, or you can please try Freelance here: https://www.mql5.com/en/job


Thanks  ͡ᵔ ͜ʖ ͡ᵔ )

 
Yohana Parmi:

Thanks  ͡ᵔ ͜ʖ ͡ᵔ )

Marco vd Heijden:

There, that was "a little Help", as you called it...

If you can't get it done, ask for a lot of help, not just a little, or you can please try Freelance here: https://www.mql5.com/en/job


Well I did mention I'm new to this and yes I did ask for a little help at first because I thought the TotalNoOfOrders was the only issue but then when I applied the code given to me by Yohana I got more errors and now my entry rules is coming up with the undeclared identifier and that wasn't happening before is what I'm saying. So ok yes I do need a lot of help now

 
Angel Dickinson:

Well I did mention I'm new to this and yes I did ask for a little help at first because I thought the TotalNoOfOrders was the only issue but then when I applied the code given to me by Yohana I got more errors and now my entry rules is coming up with the undeclared identifier and that wasn't happening before is what I'm saying. So ok yes I do need a lot of help now


I have sent you first error identification above.

Did you updated it and try again (^̮^)

----

Did you know, work in programming is exciting. But sometimes it can be frustrating if our logic has not got there yet.

Happy coding and never give up.

--- or you can easily use this service : Freelance here: https://www.mql5.com/en/job, by requesting the source code.
Freelance service at MQL5.com
Freelance service at MQL5.com
  • www.mql5.com
Orders for the development of automated trading programs
Reason: