Expressions are not allowed on the global scale

To add comments, please log in or register
Rio12
58
Rio12  

Hello there 

i am a total newbie in coding and i dont know anything 


so the thing is that i needed an indicator that can draw two horizontal lines at candle high and low , and the candle that lines are drawn at is 01:00 candle 

so i did this :

//+------------------------------------------------------------------+
//|                                                  HLine Alert.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
extern int   HOUR                = 4; //Hour to draw the lines
extern int   MINUTE              = 0; //Minute to draw the lines
extern string LineName="MyLineL";
extern string LineName1="MyLineH";
extern color LineColor=Pink; 
extern color LineColor1=DodgerBlue; 
extern int LineStyle=STYLE_SOLID;
extern int LineStyle1=STYLE_SOLID;
extern int pipDistance = 5;
extern string AlertWav="alert.wav";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start();
  
   int Counted_bars=IndicatorCounted();
   int i=Bars-Counted_bars-1;
   
    while(i>=0)                       
   {  
      if(TimeHour(Time[i]) == HOUR && TimeMinute(Time[i]) == MINUTE)
      {
         if (ObjectFind(name+DoubleToStr(Time[i])) != 0)
         {
            ObjectCreate(name+DoubleToStr(Time[i]), OBJ_HLINE, 0, Low[i], 0);
            
             ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
      ObjectSet(LineName, OBJPROP_COLOR, LineColor);
            ObjectSetInteger(0,name+DoubleToStr(Time[i]),OBJPROP_STYLE,Line_Style);
            ObjectSet(name+DoubleToStr(Time[i]), OBJPROP_COLOR, Line_Color);
            
                ObjectCreate(LineName1, OBJ_HLINE, 0, High[i], 0);
      ObjectSet(LineName1, OBJPROP_STYLE, LineStyle1);
      ObjectSet(LineName1, OBJPROP_COLOR, LineColor1);
        
      double val =  ObjectGet( LineName, OBJPROP_PRICE1);
      if (Bid <= val ) PlaySound(AlertWav);
      
      double val1 =  ObjectGet( LineName1, OBJPROP_PRICE1);
      if (Bid >= val1 ) PlaySound(AlertWav);
      
         }
      }
     
   return(0);
  }
//+------------------------------------------------------------------+

well as expected there were a lot of errors but most of them were syntax error , that i got rid of , only one is remaining , can anybody take a look and tell me if the indicator will do what i intend , and also could you help me with the error 

thanks 

and sorry for the poor English language , it not my native language so i might have a lot of mistakes

lippmaje
185
lippmaje  
These are deprecated function names. Change to OnInit/OnDeinit/OnCalculate() and indent your code with Tools - Styler. Add the compiler errors you got including line number.
Marco vd Heijden
Moderator
8831
Marco vd Heijden  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start();
  
   int Counted_bars=IndicatorCounted();
   int i=Bars-Counted_bars-1;
   
    while(i>=0)                       
   {  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start() 
 { 
   int Counted_bars=IndicatorCounted();
   int i=Bars-Counted_bars-1;
   
    while(i>=0)                       
   {  
You are missing something...
Rio12
58
Rio12  
Marco vd Heijden:
You are missing something...
I think so too, but what am I missing 
Rio12
58
Rio12  
lippmaje:
These are deprecated function names. Change to OnInit/OnDeinit/OnCalculate() and indent your code with Tools - Styler. Add the compiler errors you got including line number.
Sorry but everything you said, went over my head 😞
Marco vd Heijden
Moderator
8831
Marco vd Heijden  
Rio12:
I think so too, but what am I missing 

You are missing a curly bracket as i pointed out above.

Rio12
58
Rio12  
Marco vd Heijden:

You are missing a curly bracket as i pointed out above.

are you sure its because of the braces ? because here is what I got after i put the braces:

Files:
SS.png 83 kb
Marco vd Heijden
Moderator
8831
Marco vd Heijden  

I guess you are a beginning coder.

A function usually opens and closes with a curly bracket.

Please study some codebase examples.

void Somefunction()
  {
   // Code goes here...
  }

Or

void Somefunction(){
  
   // Code goes here...
  }

And you didn't modify it like i proposed.

Look closer.

Keith Watford
Moderator
15758
Keith Watford  
Rio12:

are you sure its because of the braces ? because here is what I got after i put the braces:

Did you also remove the semicolon?

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start();
  
   int Counted_bars=IndicatorCounted();
   int i=Bars-Counted_bars-1;
   
    while(i>=0)                       
   {  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start() 
 { 
   int Counted_bars=IndicatorCounted();
   int i=Bars-Counted_bars-1;
   
    while(i>=0)                       
   {  
You will also need to check that you have the braces matched
Rio12
58
Rio12  
Marco vd Heijden:

I guess you are a beginning coder.

A function usually opens and closes with a curly bracket.

Please study some codebase examples.

Or

And you didn't modify it like i proposed.

Look closer.

yes i am a total beginner :'(

Rio12
58
Rio12  
Keith Watford:

Did you also remove the semicolon?

You will also need to check that you have the braces matched

although there is no error in the code but the indicator is not drawing any horizontal lines

//+------------------------------------------------------------------+
//|                                                  HLine Alert.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
extern int   HOUR                = 4; //Hour to draw the lines
extern int   MINUTE              = 0; //Minute to draw the lines
extern string LineName="MyLineL";
extern string LineName1="MyLineH";
extern color LineColor=Pink; 
extern color LineColor1=DodgerBlue; 
extern int LineStyle=STYLE_SOLID;
extern int LineStyle1=STYLE_SOLID;
extern int pipDistance = 5;
extern string AlertWav="alert.wav";

extern color Line_Color          = clrBlack; //Color of the lines
input ENUM_LINE_STYLE Line_Style = STYLE_DASH; //Style of the lines

string name = "TimeLine";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start()
  {
      int Counted_bars=IndicatorCounted();
      int i=Bars-Counted_bars-1;
   
      while(i>=0)                       
   {  
      if(TimeHour(Time[i]) == HOUR && TimeMinute(Time[i]) == MINUTE)
      {
         if (ObjectFind(name+DoubleToStr(Time[i])) != 0)
         {
            ObjectCreate(name+DoubleToStr(Time[i]), OBJ_HLINE, 0, Low[i], 0);
            
             ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
      ObjectSet(LineName, OBJPROP_COLOR, LineColor);
            ObjectSetInteger(0,name+DoubleToStr(Time[i]),OBJPROP_STYLE,Line_Style);
            ObjectSet(name+DoubleToStr(Time[i]), OBJPROP_COLOR, Line_Color);
            
                ObjectCreate(LineName1, OBJ_HLINE, 0, High[i], 0);
      ObjectSet(LineName1, OBJPROP_STYLE, LineStyle1);
      ObjectSet(LineName1, OBJPROP_COLOR, LineColor1);
        
      double val =  ObjectGet( LineName, OBJPROP_PRICE1);
      if (Bid <= val ) PlaySound(AlertWav);
      
      double val1 =  ObjectGet( LineName1, OBJPROP_PRICE1);
      if (Bid >= val1 ) PlaySound(AlertWav);
      
         }
      }
     
   return(0);
  }
  }
//+------------------------------------------------------------------+


123
To add comments, please log in or register