'MA200' - unexpected token

 

The system gives me 5 errors but I don't know why. Someone hepls me pleeaaseee?!?!






extern int period = 200; 

extern int applied_price = 0;
extern int barshift  = 1;
extern double   TakeProfit=120;
extern double   StopLoss=150;
extern double   Lots=1; 
double currentprice= Open[0]
double MA200=iMA(Symbol(),0,200,0,0,0,0)                                         <------

double RSI1CUSTOM=iRSI(NULL,0,period,applied_price,barshift);     <------


void OnTick()

 {

  { if ((currentprice<MA200)&&(RSI1CUSTOM==70))       <------

   

      {int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,StopLoss,TakeProfit,NULL,0,0,Red);}

 

  if ((currentprice>MA200)&&(RSI1CUSTOM==30))

      {int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Bid,0,StopLoss,TakeProfit,NULL,0,0,Green);}

   }

  }

 

Please edit your post and Use the code button when pasting code (alt+ S)

double currentprice= Open[0]
double MA200=iMA(Symbol(),0,200,0,0,0,0)                                         <------
double RSI1CUSTOM=iRSI(NULL,0,period,applied_price,barshift);     <------

These should all be inside OnTick()

 
Keith Watford:

Please edit your post and Use the code button when pasting code (alt+ S)

These should all be inside OnTick()

Thanks but I don't understand why it gives me 3 errors again

 { if ((currentprice<MA200)&&(RSI1CUSTOM==70)&&(currentprice<lastPrice))

   

      {int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,StopLoss,TakeProfit,NULL,0,0,Red);}

 

  else ((currentprice>MA200)&&(RSI1CUSTOM==30)&&(currentprice>lastPrice))

      {int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Bid,0,StopLoss,TakeProfit,NULL,0,0,Green);}}  


'}' - expressions are not allowed on a global scope dado.mq4 53 94

'else' - expressions are not allowed on a global scope dado.mq4 52 3
'{' - function definition unexpected dado.mq4 48 3

 
DAVIDE MAISANO:
Keith Watford:

Please edit your post and Use the code button when pasting code (alt+ S)

Was there something that you did not understand?

 
Keith Watford:

Was there something that you did not understand?

yes, I'm not able to do this

 
Keith Watford:

Was there something that you did not understand?

Can you help me please? There is an error but I don't know where

It gives me  " 'if' - expressions are not allowed on a global scope "


void OnTick()

 
      { double lastPrice = Open[1]; 
       double currentprice= Open[0];
       double MA200=iMA(Symbol(),0,200,0,0,0,0);
       double RSI1CUSTOM=iRSI(NULL,0,period,applied_price,barshift);}


 
  
  
       if ((currentprice<MA200)&&(RSI1CUSTOM==70)&&(currentprice<lastPrice))
       
       int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,StopLoss,TakeProfit,NULL,0,0,Red)
 
    else if ((currentprice>MA200)&&(RSI1CUSTOM==30)&&(currentprice>lastPrice))
       int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Bid,0,StopLoss,TakeProfit,NULL,0,0,Green)
       
 
    else Print("SELL");
  

 
DAVIDE MAISANO:

Can you help me please? There is an error but I don't know where

It gives me  " 'if' - expressions are not allowed on a global scope "


void OnTick()

 
      { double lastPrice = Open[1]; 
       double currentprice= Open[0];
       double MA200=iMA(Symbol(),0,200,0,0,0,0);
       double RSI1CUSTOM=iRSI(NULL,0,period,applied_price,barshift);}


 
  
  
       if ((currentprice<MA200)&&(RSI1CUSTOM==70)&&(currentprice<lastPrice))
       
       int opensell=OrderSend(Symbol(),OP_SELL,Lots,Bid,0,StopLoss,TakeProfit,NULL,0,0,Red)
 
    else if ((currentprice>MA200)&&(RSI1CUSTOM==30)&&(currentprice>lastPrice))
       int openbuy=OrderSend(Symbol(),OP_BUY,Lots,Bid,0,StopLoss,TakeProfit,NULL,0,0,Green)
       
 
    else Print("SELL");
  

i have corrected the code for you

#property copyright ""
#property link      ""
#property version   "1.00"
#property strict

extern int period = 200;

extern int applied_price = 0;
extern int barshift  = 1;
extern int   TakeProfit=120;
extern int   StopLoss=150;
extern double   Lots=1;
int ticket=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double currentprice= Open[0];
   double MA200=iMA(Symbol(),0,200,0,0,0,0);
   double RSI1CUSTOM=iRSI(NULL,0,period,applied_price,barshift);
//---
   if((currentprice<MA200)&&(RSI1CUSTOM==70))
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Bid+StopLoss*Point,Bid-TakeProfit*Point,NULL,0,0,Red);
//---
   if((currentprice>MA200)&&(RSI1CUSTOM==30))
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Ask-StopLoss*Point,Ask+TakeProfit*Point,NULL,0,0,Green);
   return;
  }
//+------------------------------------------------------------------+
 
Kenneth Parling:

i have corrected the code for you

Thank you. I have put it into MT4 tester. Why it doesent work?
 
DAVIDE MAISANO:
Thank you. I have put it into MT4 tester. Why it doesent work?

i don't know..didn't test it nor checked for more errors, just corrected your current code and nothing else 

 

check these...you should use > or >= for 70 and < or <= for 30


if((currentprice<MA200)&&(RSI1CUSTOM==70))
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Bid+StopLoss*Point,Bid-TakeProfit*Point,NULL,0,0,Red);
//---
   if((currentprice>MA200)&&(RSI1CUSTOM==30))
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Ask-StopLoss*Point,Ask+TakeProfit*Point,NULL,0,0,Green);
 

Here you go, i fixed it all for you ;)

#property copyright ""
#property link      ""
#property version   "1.00"
#property strict

int Magic=1234;
extern int period = 200;

extern int applied_price = 0;
extern int barshift  = 1;
extern int   TakeProfit=120;
extern int   StopLoss=150;
extern double   Lots=1.0;
int ticket=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double currentprice= Open[0];
   double MA200=iMA(Symbol(),0,200,0,0,0,0);
   double RSI1CUSTOM=iRSI(NULL,0,period,applied_price,barshift);
//---
   if(positions()==0)
     {
      if((currentprice<MA200)&&(RSI1CUSTOM>=70))
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Bid+StopLoss*Point,Bid-TakeProfit*Point,NULL,Magic,0,Red);
      //---
      if((currentprice>MA200)&&(RSI1CUSTOM<=30))
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Ask-StopLoss*Point,Ask+TakeProfit*Point,NULL,Magic,0,Green);
     }
   return;
  }
//+------------------------------------------------------------------+
int positions()
  {
   int pos=0;
   for(int k = OrdersTotal() - 1; k >= 0; k--)
     {
      if(!OrderSelect(k, SELECT_BY_POS))
         break;
      if(OrderSymbol()!=Symbol()&&OrderMagicNumber()!=Magic)
         continue;
      if(OrderCloseTime() == 0 && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        {
         if(OrderType() == OP_BUY)
            pos = 1; //Long position
         if(OrderType() == OP_SELL)
            pos = -1; //Short positon
        }
     }
   return(pos);
  }
//+------------------------------------------------------------------+
Reason: