Questions from Beginners MQL5 MT5 MetaTrader 5 - page 931

 
Vitaliy Sendyaev:

Good afternoon!

Do you know how to build an indicator for Market?

I have a file with .mq5 extension and some include files with .mqh extension.

As far as I understand, you can't attach .mqh to the .mqh file via resources, should I really convert everything to one file manually?

What if there is a new version :? It's crazy +)))

Thanks.

You send the compiled (.ex5) file to the Market. This file will already contain all your include files.

 
Vladimir Karputov:

A counter question: "Why do you need to explicitly assign a symbol here?

If you use this function, you must assign a symbol to m_symbol in OnInit:

In this case, if you run EA on "EURUSD.m" symbol, "EURUSD.m" will automatically be set for m_symbol.

The thing is that Expert Advisor is hovering on a different symbol. And I need to update quotes for EURUSD.m

I found this solution but I think it is wrong

void OnTick()
  {   
// Обновляем котировки
    if(!m_symbol.Name("EURUSD.m")) //Обновляем котировки по второму символу
    RefreshRates();
    if(!m_symbol.Name("GBPUSD.m")) //Обновляем котировки по символу где висит советник
    RefreshRates();
 
EgorKim:

That's the thing, the EA is hovering on a different symbol. And I need to update quotes for EURUSD.m

I found this solution but I don't think it's right

Write EURUSD.m symbol in InInit for m_symbol. Or tell me what you do and how you do it - while I'm trying to play guessing.
 

Folks, please advise!!!

How can the TimeCurrent() function pass the values of hours and minutes to the variables so that they can work with these values?

Or for example I want to pass hours and minutes with string (12:15) and pass 12 and 15 to the variables. How to do this?
 
TaywinLannister:

Folks, please advise!!!

How can the TimeCurrent() function pass the values of hours and minutes to the variables so that you can work with these values?

Or for example I want to pass the hour and minutes with string (12:15) and pass 12 and 15 to the variables. How to do this?

TimeToStruct

 
Konstantin Nikitin:

TimeToStruct

Thank you!
 
Hello! I converted the indicator from Metatrader 4 to Metatrader 5, but now it shows the arrows in the wrong places as in Metatrader 4 on the minute timeframe. Did I make a mistake somewhere or is it because of the different quotes on the minute chart of the 4 and 5 versions of the terminal of one broker?
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_color1  clrBlue
#property indicator_color2  clrRed

#property indicator_width1  1 
#property indicator_width2  1 
//+------------------------------------------------------------------+

double     SignalBufferRed[];
double     SignalBufferBlue[];
datetime TimeAlert=0;
ENUM_TIMEFRAMES tf0,tf1,tf2,tf3,tf4,tf5; // Было инт
int S=0;
//+------------------------------------------------------------------+
int OnInit()
  {
  
    SetIndexBuffer(0,SignalBufferBlue);
    SetIndexBuffer(1,SignalBufferRed); 
//--- задать рисование линии 
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_ARROW); 
//--- задание стиля для рисования линии 
   PlotIndexSetInteger(0,PLOT_ARROW,233); 
   //--- задать рисование линии 
   PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW); 
//--- задание стиля для рисования линии 
   PlotIndexSetInteger(1,PLOT_ARROW,234); 
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,5); 
   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-5); 
   //--- установим в качестве пустого значения 0 
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0); 
   //--- установим в качестве пустого значения 0 
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0); 





   tf0=Period();
   tf1=next_period(tf0+1);
   tf2=next_period(tf1+1);
   tf3=next_period(tf2+1);
   tf4=next_period(tf3+1);
   tf5=next_period(tf4+1);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
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[])
  {
   int i,limit;

   limit=rates_total-prev_calculated-1;
   if(rates_total<1) return(0);
   double d=(high[1]-low[1]+high[2]-low[2])/2;
   for(i=limit; i>=0; i--)
     {
      if(S<1 && NormalizeDouble(open[i]-close[i],_Digits)<0 && 
         NormalizeDouble(iOpen(NULL,tf1,iBarShift(NULL,tf1,time[i],false))-iClose(NULL,tf1,iBarShift(NULL,tf1,time[i],false)),_Digits)<0 && 
         NormalizeDouble(iOpen(NULL,tf2,iBarShift(NULL,tf2,time[i],false))-iClose(NULL,tf2,iBarShift(NULL,tf2,time[i],false)),_Digits)<0 && 
         NormalizeDouble(iOpen(NULL,tf3,iBarShift(NULL,tf3,time[i],false))-iClose(NULL,tf3,iBarShift(NULL,tf3,time[i],false)),_Digits)<0 && 
         NormalizeDouble(iOpen(NULL,tf4,iBarShift(NULL,tf4,time[i],false))-iClose(NULL,tf4,iBarShift(NULL,tf4,time[i],false)),_Digits)<0 && 
         NormalizeDouble(iOpen(NULL,tf5,iBarShift(NULL,tf5,time[i],false))-iClose(NULL,tf5,iBarShift(NULL,tf5,time[i],false)),_Digits)<0)
        {
         SignalBufferBlue[i]=low[i]-d;
...
         S=1;
        }
      if(S>-1 && NormalizeDouble(open[i]>close[i],_Digits)>0 && 
         NormalizeDouble(iOpen(NULL,tf1,iBarShift(NULL,tf1,time[i],false))-iClose(NULL,tf1,iBarShift(NULL,tf1,time[i],false)),_Digits)>0 && 
         NormalizeDouble(iOpen(NULL,tf2,iBarShift(NULL,tf2,time[i],false))-iClose(NULL,tf2,iBarShift(NULL,tf2,time[i],false)),_Digits)>0 && 
         NormalizeDouble(iOpen(NULL,tf3,iBarShift(NULL,tf3,time[i],false))-iClose(NULL,tf3,iBarShift(NULL,tf3,time[i],false)),_Digits)>0 && 
         NormalizeDouble(iOpen(NULL,tf4,iBarShift(NULL,tf4,time[i],false))-iClose(NULL,tf4,iBarShift(NULL,tf4,time[i],false)),_Digits)>0 && 
         NormalizeDouble(iOpen(NULL,tf5,iBarShift(NULL,tf5,time[i],false))-iClose(NULL,tf5,iBarShift(NULL,tf5,time[i],false)),_Digits)>0)
        {
         SignalBufferRed[i]=high[i]+d;
...
         S=-1;
        }
     }

   return(rates_total);
  }
//+------------------------------------------------------------------+
ENUM_TIMEFRAMES next_period(int per) // Было инт
  {
   if(per > PERIOD_W1)  return(PERIOD_MN1);  // Былы цифры вместо период_
   if(per > PERIOD_D1)   return(PERIOD_W1);   // Былы цифры вместо период_
   if(per > PERIOD_H4)    return(PERIOD_D1);  // Былы цифры вместо период_
   if(per > PERIOD_H1)     return(PERIOD_H4);  // Былы цифры вместо период_
   if(per > PERIOD_M30)     return(PERIOD_H1);  // Былы цифры вместо период_
   if(per > PERIOD_M15)     return(PERIOD_M30);   // Былы цифры вместо период_
   if(per >  PERIOD_M5)     return(PERIOD_M15);  // Былы цифры вместо период_
   if(per >  PERIOD_M1)     return(PERIOD_M5);  // Былы цифры вместо период_
   if(per == PERIOD_M1)     return(PERIOD_M1);  // Былы цифры вместо период_
   return(Period());
  }
//+------------------------------------------------------------------+
 
Yevgen Butov:
Hi! I converted the indicator from metatrader 4 to metatrader 5, but now it shows arrows in the wrong places as in metatrader 4 on a minute period. Did I make a mistake somewhere or is it because of the different quotes on the minute chart of the 4 and 5 versions of the terminal of one broker?

Do a simple test in MQL5 and MQL4 indicator - print bar time #0:

Print("Bar #0: ",time[0]);

This will help to understand what's what...

 
Vladimir Karputov:

Do a simple test in MQL5 and MQL4 indicator - print bar time #0:

This will help to understand what's what...

Added this text to OnCalculate, bar time changes every minute now, but now there are no arrows at all. What could be the error?

ArraySetAsSeries(time,true); 

   ArraySetAsSeries(open,true); 

   ArraySetAsSeries(high,true); 

   ArraySetAsSeries(low,true); 

   ArraySetAsSeries(close,true); 
 
Yevgen Butov:

Added this text to OnCalculate, bar time changes every minute now, but now no arrows at all. What could be the error?

You didn't get it right. Compare the printed values. Compare bar time #0 and bar time #rates_total-1. Compare both there and there...