Beginner - Error open parenthesis expected

Divania111  

Hello,

By reading through this website i am trying to make a (hopefully) very simple indicator. This is for learning purposes as I am a total beginner.


My first step is that I want to store the closing price in a variable at a specific time. Later on I want to compare this closing price to a closing price an x amount later and generate a buy or sell signal.


But I get an error at the first step. There is an openparenthesis expected at the "If" statement. But when I read me MQL5 reference for the "if" statement it seems to match my format.

Can someone help me out?



#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

input int timex = 180;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   

   return(INIT_SUCCEEDED);


  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

datetime tm=TimeCurrent();
double Close;

   string str1="Date and time with minutes: "+TimeToString(tm);
   string str2="Date only: "+TimeToString(tm,TIME_DATE);
   string str3="Time with minutes only: "+TimeToString(tm,TIME_MINUTES);
   string str4="Time with seconds only: "+TimeToString(tm,TIME_SECONDS);
   string str5="Date and time with seconds: "+TimeToString(tm,TIME_DATE|TIME_SECONDS);
//--- output results
   Alert(str1);
   Alert(str2);
   Alert(str3);
   Alert(str4);
   Alert(str5);

   datetime timezero = StringToTime(str2) +timex*60;

   if(timezero == TimeCurrent)
   {
   Close = iClose(_Symbol,PERIOD_CURRENT,1);
   Print(Close);
   }

  }

//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
//---

  }
//+------------------------------------------------------------------+
Paul Anscombe  
Divania111:

Hello,

But I get an error at the first step. There is an openparenthesis expected at the "If" statement. But when I read me MQL5 reference for the "if" statement it seems to match my format.

Can someone help me out?

You have not used the  TimeCurrent function correctly

   if(timezero == TimeCurrent())
Divania111  
Paul Anscombe #:

You have not used the  TimeCurrent function correctly

Thanks! Been trying to figure it out for hours and it so obvious.

again, thanks!

Divania111  

Hi Everyone,


So I have been trying to make my own indicator based on the above.

-If the close price at a specified time is higher than the close price x-amount of minutes back, then I want to plot a up-arrow on the chart.

- If the close price at a specified time is lower than the close price x-amount of minutes back, then I want to plot a down-arrow on the chart.

The idea is that the arrow has a similar style to that of the fractals indicator.


The code seems not to have any errors. Yet, no arrows are generated on the chart. Can someone point me in the right direction as to what I am missing? (ps. when I attached the indicator the input parameter timex is filled in minutes: for example 1320mins in order to set the time to 22:00hrs of the current day). 

Also any tips on how to get the close price from an array back at a specified time? Currently, I simply use close[24] to get the closing price of "array entry 24". 

#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_ARROW
#property indicator_type2   DRAW_ARROW
#property indicator_color1  Gray
#property indicator_color2  Gray
#property indicator_label1  "Arrow Up"
#property indicator_label2  "Arrow Down"
//--- input parameters
input int      TimeX;
//--- indicator buffers
double ArrowUpBuffer[];
double ArrowDownBuffer[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
Plot
   SetIndexBuffer(0,ArrowUpBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ArrowDownBuffer,INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_ARROW,217);
   PlotIndexSetInteger(1,PLOT_ARROW,218);
//--- arrow shifts when drawing
//--- sets drawing line empty value--
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- Array Setting as series
ArraySetAsSeries(ArrowDownBuffer,true);
ArraySetAsSeries(ArrowUpBuffer,true);
ArraySetAsSeries(close,true);
ArraySetAsSeries (time,true);

int bars = rates_total - 1;
if(prev_calculated > 0) bars = rates_total - prev_calculated;

//Main Loop

   for(int i=bars;i>rates_total;i--)
     {
      datetime tm =TimeCurrent(); 
      string str2;
      str2=TimeToString(tm,TIME_DATE);
      datetime timenow = StringToTime(str2) + TimeX;      
      if(TimeCurrent() == timenow && close[i] >= close[24])
        {
       ArrowUpBuffer [i] = close[i];
        }
          else
            {
             ArrowDownBuffer [i] = close[i];
            }
         }
 return(rates_total);    
     }