need help!

 
//+------------------------------------------------------------------+
//|                                                       pirmas.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#define MAGICMA 7777


int     Count=0;
//--- input parameters
extern double    Lots           =0.1;
extern int       Slipage        =5;
extern double    MaximumRisk    = 0.02;
extern string    Order_Comment  ="";
extern double    StopLoss       =1000;
extern double    TakeProfit     =1000;
extern double    DecreaseFactor = 3;
extern double    MovingShift    = 6;

//+------------------------------------------------------------------+
extern int       cci_period     =80;
extern int       cci_applied_price = 0;

//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double cci_curr=iCCI(NULL,0,cci_period,cci_applied_price,0);
   double cci_prev=iCCI(NULL,0,cci_period,cci_applied_price,1);
   int    res;
//---- buy conditions
   if(cci_curr > 0 && cci_prev <= 0)  
     {
      res=OrderSend(Symbol(),OP_BUY,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      return;
     }
   if(cci_curr > 100 && cci_prev <= 100)
     {
      res=OrderSend(Symbol(),OP_BUY,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      return;
     }
   if(cci_curr > -100 && cci_prev <= 100)
     {
      res=OrderSend(Symbol(),OP_BUY,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      return;
     }
//---- sell conditions
   if(cci_curr < 0 && cci_prev >= 0)  
     {
      res=OrderSend(Symbol(),OP_SELL,Bid,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
      return;
     }
   if(cci_curr < 100 && cci_prev >= 100)
     {
      res=OrderSend(Symbol(),OP_SELL,Bid,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
      return;
     }
   if(cci_curr < -100 && cci_prev >= 100)
     {
      res=OrderSend(Symbol(),OP_SELL,Bid,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
      return;
     }
//----
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double cci_curr=iCCI(NULL,0,cci_period,cci_applied_price,0);
   
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //---- check order type 
      if(OrderType()==OP_BUY)
        {
         if(cci_curr < 0) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(cci_curr > 0) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         break;
        }
      }
     
//----
  }
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
  {
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();
//----

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

I finished my first EA.0 error(s) and 0 warning(s) after compiling.I put it on back test but EA desnt work,no rezults at all.Can somebody to check what is wrong in my code?

 
 
If there's no errors and stuff compiles, then you need to tell us what you want it to do. Otheriwse it's a succesful source :P
 
  1. void CheckForOpen()  {...
       if(cci_curr > 0 && cci_prev <= 0)  
         {
          res=OrderSend(Symbol(),OP_BUY,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
          return;
         }
       if(cci_curr > 100 && cci_prev <= 100)
         {
          res=OrderSend(Symbol(),OP_BUY,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
    1. The sends are all identical so combine
         if((cci_curr > 0 && cci_prev <= 0) 
         || (cci_curr > 100 && cci_prev <= 100)
         ){
            res=OrderSend(Symbol(),OP_BUY,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
    2. Always test return codes so you find out WHY
          res=OrderSend(Symbol(),OP_BUY,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      if (res < 0) Alert("OrderSend failed: ", GetLastError());
    3. OrderSend( string symbol, int cmd, double volume, double price...
    4. EAs must adjust for 5 digit brokers, TP, SL, AND slippage
      //++++ These are adjusted for 5 digit brokers.
      int     pips2points;    // slippage  3 pips    3=points    30=points
      double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
      int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
      int     init(){
          if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                      pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
          } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
          // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
      

  2. void CheckForClose()
    You MUST count DOWN when closing in the presense of multiple orders (multiple charts)
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol() ){              // and my pair.
    
 
WHRoeder:
    1. The sends are all identical so combine
    2. Always test return codes so you find out WHY
    3. OrderSend( string symbol, int cmd, double volume, double price...
    4. EAs must adjust for 5 digit brokers, TP, SL, AND slippage

  1. You MUST count DOWN when closing in the presense of multiple orders (multiple charts)

I tried fix my code.Can you check my errors? I got one error after compiling '\end_of_program-unbalanced left parenthesis.(103,1) I had a problem to find a place of this error.If I go to line to get a place of error the cursor moves to section of grey color out of code. EA is not adjusted for 5 digit broker at the moment.
//+------------------------------------------------------------------+
//|                                                       pirmas.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#define MAGICMA 7777


int     Count=0;
//--- input parameters
extern double    Lots           =0.1;
extern int       Slipage        =5;
extern double    MaximumRisk    = 0.02;
extern string    Order_Comment  ="";
extern double    StopLoss       =1000;
extern double    TakeProfit     =1000;
extern double    DecreaseFactor = 3;
extern double    MovingShift    = 6;
extern int       magic.number   =7777;

//+------------------------------------------------------------------+
extern int       cci_period     =80;
extern int       cci_applied_price = 0;

//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double cci_curr=iCCI(NULL,0,cci_period,cci_applied_price,0);
   double cci_prev=iCCI(NULL,0,cci_period,cci_applied_price,1);
   int    res;
//---- buy conditions
   if ((cci_curr > 0 && cci_prev <= 0)
   || (cci_curr > 100 && cci_prev <= 100)
   || (cci_curr > -100 && cci_prev <= 100)) 
     {
      res=OrderSend(Symbol(),OP_BUY,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
   if (res < 0) Alert("OrderSend failed: ", GetLastError());
      return;
     }
//---- sell conditions
   if((cci_curr < 0 && cci_prev >= 0)
   || (cci_curr < 100 && cci_prev >= 100)
   || (cci_curr < -100 && cci_prev >= 100))
     {
      res=OrderSend(Symbol(),OP_SELL,Bid,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
   if (res < 0) Alert("OrderSend failed: ", GetLastError());
      return;
     }
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double cci_curr=iCCI(NULL,0,cci_period,cci_applied_price,0);
   for(int pos = OrdersTotal()-1; pos >= 0 ; pos--)
      if (OrderSelect(pos, SELECT_BY_POS)
      &&  OrderMagicNumber()  == magic.number; 
      &&  OrderSymbol()       == Symbol() 
  }
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
  {
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();
//----

  }
 
el90ras:

I tried fix my code.Can you check my errors? I got one error after compiling '\end_of_program-unbalanced left parenthesis.(103,1) I had a problem to find a place of this error.If I go to line to get a place of error the cursor moves to section of grey color out of code. EA is not adjusted for 5 digit broker at the moment.
  1. Use /*comments*/ to remove portions until you track down where. The error message just points to the end.
  2. if (... } instead of if (... ) statement; }
       for(int pos = OrdersTotal()-1; pos >= 0 ; pos--)
          if (OrderSelect(pos, SELECT_BY_POS)
          &&  OrderMagicNumber()  == magic.number; 
          &&  OrderSymbol()       == Symbol() 
      }
    
 
forexCoder:
If there's no errors and stuff compiles, then you need to tell us what you want it to do. Otheriwse it's a succesful source :P

Hi,

no errors and no warnings after compiling.I put it on strategy tester and got no result at all.I changed inputs ant time frame and result was the same.Does it means my code will not work at all or samething is wrong?

 

Hi!

just replace this lines in your code, u missed Lots variable

void CheckForOpen() {
 ...
 res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
 ...
 res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
 ...
}
 
so look at the log, see the error message, reread my post #3
 

Hi,

First,Thank You to everyone for your attencion.Code is working .No profit at all ant code is not ajusted for 5 digit broker,but it is working.My first step to programming is done.I will work on it.If somebody has any ideas,you are welcom to modify a code.

//+------------------------------------------------------------------+
//|                                                       pirmas.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#define MAGICMA 7777


int     Count=0;
//--- input parameters
extern double    Lots           =0.1;
extern int       Slipage        =5;
extern double    MaximumRisk    = 0.02;
extern string    Order_Comment  ="";
extern double    StopLoss       =1000;
extern double    TakeProfit     =1000;
extern double    DecreaseFactor = 3;
extern double    MovingShift    = 6;

//+------------------------------------------------------------------+
extern int       cci_period     =80;
extern int       cci_applied_price = 0;

//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double cci_curr=iCCI(NULL,0,cci_period,cci_applied_price,0);
   double cci_prev=iCCI(NULL,0,cci_period,cci_applied_price,1);
   int    res;
//---- buy conditions
   if(cci_curr > 0 && cci_prev <= 0)  
     {
      res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      return;
     }
   if(cci_curr > 100 && cci_prev <= 100)
     {
      res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      return;
     }
   if(cci_curr > -100 && cci_prev <= 100)
     {
      res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Green);
      return;
     }
//---- sell conditions
   if(cci_curr < 0 && cci_prev >= 0)  
     {
      res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
      return;
     }
   if(cci_curr < 100 && cci_prev >= 100)
     {
      res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
      return;
     }
   if(cci_curr < -100 && cci_prev >= 100)
     {
      res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"Volume: "+Volume[0]+"Time: "+TimeCurrent(),MAGICMA,0,Red);
      return;
     }
//----
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double cci_curr=iCCI(NULL,0,cci_period,cci_applied_price,0);
   
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //---- check order type 
      if(OrderType()==OP_BUY)
        {
         if(cci_curr < 0) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(cci_curr > 0) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         break;
        }
      }
     
//----
  }
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
  {
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();
//----

  }
//+------------------------------------------------------------------+
 
WHRoeder:
so look at the log, see the error message, reread my post #3
Thank You for your attencion to my questions.It very helped me.
Reason: