how to add indicator code into expertadvisor code ?? - page 4

 

how to write open only 1 way ??

because my ea open both direction position, buy and sell.

i just edit the code and add the else; on there,

is it correct ??

here is the code .

      if ((diClose0<diMA1))&&(ZigZagLow){
         OpenBuy();
         return(0);
      }
      else;

      if ((diClose2>diMA3))&&(ZigZagHigh){
         OpenSell();
         return(0);
      }
 
albert_lim83:

finally done the variable problem,

now is only

( - function definition unexpected

) - unbalanced right parenthesis...

is it l left put ( and ) on my code??

You have this . . . .

double zag, zig; b=0; while(a<2) {

. . . where is your closing } ?

 
if (!ExistPositions()){

      if ((diClose0<diMA1))&&(ZigZagLow){
         OpenBuy();
         return(0);
      }
      else;

      if ((diClose2>diMA3))&&(ZigZagHigh){
         OpenSell();
         return(0);
      }
   }
   
   return (0);
}

bool ExistPositions() {
for (int i=100; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol()) {
return(True);
}
} 
} 
return(false);
}
void OpenBuy() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLot(); 
   ldStop = GetStopLossBuy(); 
   ldTake = GetTakeProfitBuy(); 
   lsComm = GetCommentForOrder(); 
   OrderSend(Symbol
(),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,0,0,clOpenBuy); 
 
} 
void OpenSell() { 
   double ldLot, ldStop, ldTake; 
   string lsComm; 
   ldLot = GetSizeLot(); 
   ldStop = GetStopLossSell(); 
   ldTake = GetTakeProfitSell(); 
   lsComm = GetCommentForOrder(); 
   OrderSend(Symbol
(),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,0,0,clOpenSell); 

} 
string GetCommentForOrder() { return(Name_Expert); } 

double GetSizeLot() { return(Lots); } 
double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); } 
double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); }
double GetStopLossBuy() { return(Bid-lStopLoss*Point); }
double GetStopLossSell() { return(Ask+sStopLoss*Point); }

the error is

ExistPositions - expression on global scope not allowed

and } - unbalanced parentheses.

 

just wonder why the error always change ??

after i fixed this,

then error there.

after fixed there,

error here.

 
albert_lim83:

the error is

ExistPositions - expression on global scope not allowed

and } - unbalanced parentheses.

OK, you have this function declared . . . I have adjusted the indenting to make it easier for me to read . . .

bool ExistPositions() 
   {
   for (int i=100; i<OrdersTotal(); i++) 
      {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
         {
         if (OrderSymbol()==Symbol()) 
            {
            return(True);
            }
         } 
      } 
   return(false);
   }

this code . . . this function declaration . . . must be outside of any other function, so it must be outside of start, init, deinit, etc.

 
albert_lim83:

just wonder why the error always change ??

after i fixed this,

then error there.

after fixed there,

error here.

Because one error masks another . . . fix one and another becomes visible to the compiler . . . for example, you maay haave the correct numbers of braces but the may be in the wrong places . . . or you may have missed a closing brace and an open brace . . . so the numbers match but are wrong.
 
RaptorUK:

OK, you have this function declared . . . I have adjusted the indenting to make it easier for me to read . . .

this code . . . this function declaration . . . must be outside of any other function, so it must be outside of start, init, deinit, etc.

still the same error...


ExistPositions - expression on global scope not allowed

and } - unbalanced parentheses.

where should i change ?

 
albert_lim83:


where should i change ?

I don't know . . . show you full code.
 
RaptorUK:
I don't know . . . show you full code.

Agree !. W/o full code, we can't help much, so don't expect more.

Combed with MetaEditor 5.

   if(!ExistPositions())
     {

      if((diClose0<diMA1)) && (ZigZagLow)  // <<== ???
        {
         OpenBuy();
         return(0);
        }
      else;   // <<=== ???

      if((diClose2>diMA3)) && (ZigZagHigh) // <<=== ???
        {
         OpenSell();
         return(0);
        }
     }

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ExistPositions() 
  {
   for(int i=100; i<OrdersTotal(); i++) // <<=== strange calculation 
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) 
        {
         if(OrderSymbol()==Symbol()) 
           {
            return(True);
           }
        }
     }
   return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenBuy() 
  {
   double ldLot,ldStop,ldTake;
   string lsComm;
   ldLot=GetSizeLot();
   ldStop = GetStopLossBuy();
   ldTake = GetTakeProfitBuy();
   lsComm = GetCommentForOrder();
   OrderSend(Symbol
             (),OP_BUY,ldLot,Ask,Slippage,ldStop,ldTake,lsComm,0,0,clOpenBuy);

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenSell() 
  {
   double ldLot,ldStop,ldTake;
   string lsComm;
   ldLot=GetSizeLot();
   ldStop = GetStopLossSell();
   ldTake = GetTakeProfitSell();
   lsComm = GetCommentForOrder();
   OrderSend(Symbol
             (),OP_SELL,ldLot,Bid,Slippage,ldStop,ldTake,lsComm,0,0,clOpenSell);

  }
string GetCommentForOrder() { return(Name_Expert); }

double GetSizeLot() { return(Lots); }
double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); }
double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); }
double GetStopLossBuy() { return(Bid-lStopLoss*Point); }
double GetStopLossSell() { return(Ask+sStopLoss*Point); }
 

Maybe this should be written like this ???

 if(!ExistPositions())
     {
      if(diClose0 < diMA1 && (ZigZagLow)) // <<== ???
        {
         OpenBuy();
         return(0);
        }
        else // <<=== ???
        {
        if(diClose2 > diMA3 && (ZigZagHigh)) // <<=== ???
          {
          OpenSell();
          return(0);
          }
        }
     }
Reason: