function definition unexpected

 

Hi There, 


I would like to know were I have gone wrong. Attached below is the code. It is giving the error message FUNCTION DEFINITION UNEXPECTED. 


void Ontick()

  {

      

      double K_Line= iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);

      double D_Line= iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,1);

      double Previous_K_Line= iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,2);

      double Previous_D_Line= iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,2);

      

      if(Previous_K_Line>80)

      if(Previous_K_Line>Previous_D_Line&&K_Line<D_Line)

      if(OrdersTotal()==0)

      OrderSend(Symbol(),OP_BUY,LotSize,Ask-(Stoploss*Pips),Ask+(TakeProfit*Pips),NULL,MagicNumber,0,Green);

      

      if(Previous_K_Line<20)

      if(Previous_K_Line<Previous_D_Line&&K_Line>D_Line)

      if(OrdersTotal()==1)

       OrderSend(Symbol(),OP_SELL,LotSize,Bid+(Stoploss*Pips),Bid-(TakeProfit*Pips),NULL,MagicNumber,0,Red);

      

      return(0) ; 
 
  1. Your posted code is without context, so we can only guess. That code is likely inside another function.

  2. OrderSend(Symbol(),OP_BUY,LotSize,Ask-(Stoploss*Pips),Ask+(TakeProfit*Pips),NULL,MagicNumber,0,Green);
    
          if(OrdersTotal()==1)
    
    OrderSend(Symbol(),OP_SELL,LotSize,Bid+(Stoploss*Pips),Bid-(TakeProfit*P
  3. You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP would be longer. Don't you want the same/specified amount for either direction?
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at 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.)

  4. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              PositionClose is not working - MQL5 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

  5. Your code
     Documentation
         OrderSend(
    Symbol(),
    OP_BUY,
    LotSize,
                            
                            
    Ask-(Stoploss*Pips),
    Ask+(TakeProfit*Pips),
    NULL,
    MagicNumber,
    0,
    Green
    );
    
    int  OrderSend(
       string   symbol,              // symbol
       int      cmd,                 // operation
       double   volume,              // volume
       double   price,               // price   
       int      slippage,            // slippage
       double   stoploss,            // stop loss
       double   takeprofit,          // take profit
       string   comment=NULL,        // comment
       int      magic=0,             // magic number
       datetime expiration=0,        // pending order expiration
       color    arrow_color=clrNONE  // color
       );
    Missing arguments. Don't post code that won't compile.
  6. Check your return codes for errors, and report them including GLE/LE and your variable values. Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
 

Hello, I just started coding and I cannot solve my errors, could you please help me ?

the errors are :     '{' - function definition unexpected 68 3

                             '}' - expressions are not allowed on a global scope 86 3



Files:
EA_ROH.mq5  9 kb
 
rapha9a:

Hello, I just started coding and I cannot solve my errors, could you please help me ?

the errors are :     '{' - function definition unexpected 68 3

                             '}' - expressions are not allowed on a global scope 86 3



Why have you posted your mql5 question in the mql4 section?

Do not make multiple posts with the same issue.

I have deleted your other posts.

 
it is showing function error could someone please guide me 
 
Sneha N #: it is showing function error could someone please guide me 
  1. This is what you wrote. See the problem?

      //this is support and resistance to show the charts trend 
    
    study("Support and Resistance", overlay= true) left  = input(10) right = input(10) hih = pivothigh(high, left, right) lol = pivotlow (low , left, right) top = valuewhen(hih, high[right], 0) bot = valuewhen(lol, low [right], 0) res = plot(top, color=top != top[1] ? na : red, offset=-left) sup = plot(bot, color=bot != bot[1] ? na : green, offset=-left)
    
      }
    

  2. Next time post your MT5 question in the MT4 section.

Reason: