Undeclared identifier. Anyone? - page 2

 

I have got same message with if function and && 'some operator required '

***
 
Khalid Amin:

I have got same message with if function and && 'some operator required '

***
Please insert the code correctly: when editing a message, press the button   Codeand paste your code into the pop-up window. (The first time I corrected your message)
 

   // import Trade Library
   #include <Trade\Trade.mqh>;
   // Create an include of Ctrade called trade
   CTrade trade;
   
 

void OnTick()
  
{
   //Get th Ask price
   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);

   // Get the Bid price
   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   
   // if no order or postion exists
   If ((OrdersTotal()==0) && (PositionsTotal()==0));
   
   {
  
   trade.BuyLimit(0.10,(Bid-(200*_Point)),_Symbol,0,(Ask+(200*_Point)),ORDER_TIME_GTC,0,0);
   
   }
  
}
 
Khalid Amin :

Correct your mistake: instead of 'If' you need to use 'if':

// import Trade Library
#include <Trade\Trade.mqh>;
// Create an include of Ctrade called trade
CTrade trade;
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//Get th Ask price
   double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
// Get the Bid price
   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
// if no order or postion exists
   if((OrdersTotal()==0) && (PositionsTotal()==0));
     {
      trade.BuyLimit(0.10,(Bid-(200*_Point)),_Symbol,0,(Ask+(200*_Point)),ORDER_TIME_GTC,0,0);
     }
  }
 
Vladimir Karputov:

Correct your mistake: instead of 'If' you need to use 'if':

thanks done now it is ok 
 
  1. Vladimir Karputov: Correct your mistake: instead of 'If' you need to use 'if':
      if((OrdersTotal()==0) && (PositionsTotal()==0));

    Remove the semicolon so the if applies to the trade.

  2.       trade.BuyLimit(0.10,(Bid-(200*_Point)),_Symbol,0,(Ask+(200*_Point)),ORDER_TIME_GTC,0,0);
    

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).