Questions from Beginners MQL5 MT5 MetaTrader 5 - page 85

 

A couple of other questions came up along the way:

1. there is a string:

datetime ProvTimeX1=ObjectGetInteger(0, "Y="+IntegerToString(y,0,''),OBJPROP_TIME);

The compiler frowns upon it, writing"possible loss of data due to type conversion". What is wrong here?

2. How does mql5 put data into arrays and distribute them, in which direction?

 
WindSW:

A couple of other questions came up along the way:

1. there is a string:

datetime ProvTimeX1=ObjectGetInteger(0, "Y="+IntegerToString(y,0,''),OBJPROP_TIME);

The compiler frowns upon it, writing"possible loss of data due to type conversion". What is wrong here?

Well, it is right, you are trying to write into the datetime variable a value long returned by ObjectGetInteger. Do type conversion.

datetime ProvTimeX1=(datetime)ObjectGetInteger(0,"Y="+IntegerToString(y,0,' '),OBJPROP_TIME);
2. How are the data in mql5 put into arrays and allocated, in which direction?

The direction is always the same - from the beginning (the index is zero) to the end, BUT if you do not specify indexing with ArraySetAsSeries function. If the question is about indexing.

 

Good afternoon, I cannot divide the numbers, the result is 0.0

Why?

   double res =  8000/16000 * 100;
   Print(res);
 
ryzhak.vladimir:

Good afternoon, I cannot divide the numbers, the result is 0.0

Why?



   double res=((double)8000/16000)*100;
   Print(res);
Documentation >>> Type conversion
 

It's stupid of course, that you have to add something to change something, some calculator without dots is fine and it does not need to specify what type of data, but okay, the second way is to add ".0" to the end of the integer

so the correct expression would be like this.

double res =8000.0/16000.0*100;
Print(res);
By the way, in some programming language saw a variable so that the terminal selects its type, perhaps it was only for numeric data, but still comfortable, is it not implemented here, I tried to find in the documentation - could not find?
 
thank you all)
 

In version 4: datetime TimeX2=Time[0]+18000; - increased time value by 5 candles forward

Now in 5 when writing:

datetime Topen[];
ArraySetAsSeries(Topen,true);
CopyTime(_Symbol,_Period,0,3,Topen);
datetime TimeX2=Topen[0]+18000;

When debugging it gives array overflow error and points todatetime line TimeX2=Topen[0]+18000;

Please advise how to get the same result in 5 as it was in 4?

Addendum: It's written correctly, I just made a mistake - in OnInit the array was empty.

 
WindSW:

In version 4: datetime TimeX2=Time[0]+18000; - increased time value by 5 candles forward

Now in 5 when writing:

When debugging it gives array overflow error and points todatetime line TimeX2=Topen[0]+18000;

Please advise how to get the same result in 5 as it was in 4?

datetime b=TimeTradeServer()+60*min; //min - кол-во минут от текущего времени
 

I've encountered a problem with the drawing of levels.

void OnInit()
  {
   ObjectCreate(0,oPP,OBJ_TREND,0,0,0,0,0);
   ObjectSetInteger(0,oPP,OBJPROP_COLOR,clrDeepSkyBlue);
   ObjectSetInteger(0,oPP,OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,oPP,OBJPROP_WIDTH,2);
   ObjectSetInteger(0,oPP,OBJPROP_RAY,false);
   ObjectCreate(0,oRes1,OBJ_TREND,0,0,0,0,0);
   ObjectSetInteger(0,oRes1,OBJPROP_COLOR,clrDeepSkyBlue);
   ObjectSetInteger(0,oRes1,OBJPROP_STYLE,STYLE_DASH);
   ObjectSetInteger(0,oRes1,OBJPROP_WIDTH,1);
   ObjectSetInteger(0,oRes1,OBJPROP_RAY,false);
   ObjectCreate(0,oSup1,OBJ_TREND,0,0,0,0,0);
   ObjectSetInteger(0,oSup1,OBJPROP_COLOR,clrDeepSkyBlue);
   ObjectSetInteger(0,oSup1,OBJPROP_STYLE,STYLE_DASH);
   ObjectSetInteger(0,oSup1,OBJPROP_WIDTH,1);
   ObjectSetInteger(0,oSup1,OBJPROP_RAY,false);
   PPlevel();
  }
//+------------------------------------------------+
//| Пивот поинт                                    |
//+------------------------------------------------+
void PPlevel()
   {
    double iH=iHigh(Symbol(),PERIOD_D1,1);
    double iL=iLow(Symbol(),PERIOD_D1,1);
    double iC=iClose(Symbol(),PERIOD_D1,1);
    double iO=iOpen(Symbol(),PERIOD_D1,1);
    int New_candle=0;
    New_candle=NBar(); // функция появления новой свечи
    if(New_candle==1)
      {
       double range=NormalizeDouble(iH-iL,_Digits);
       double PP=NormalizeDouble((iH+iL+iC)/3,_Digits);
       double R1=NormalizeDouble((2*PP)-iL,_Digits);
       double S1=NormalizeDouble((2*PP)-iH,_Digits);
       TimeStart=iTime(Symbol(),PERIOD_D1,0)-7200;
       TimeFinish=Topen[0]+64000;
       ObjectSetInteger(0,oPP,OBJPROP_TIME,TimeStart);                 // отрисовка PP
       ObjectSetDouble(0,oPP,OBJPROP_PRICE,PP);
       ObjectSetInteger(0,oPP,OBJPROP_TIME,1,TimeFinish);
       ObjectSetDouble(0,oPP,OBJPROP_PRICE,1,PP);
       ObjectSetInteger(0,oRes1,OBJPROP_TIME,TimeStart);               // отрисовка сопротивления
       ObjectSetDouble(0,oRes1,OBJPROP_PRICE,R1);
       ObjectSetInteger(0,oRes1,OBJPROP_TIME,1,TimeFinish);
       ObjectSetDouble(0,oRes1,OBJPROP_PRICE,1,R1);
       ObjectSetInteger(0,oSup1,OBJPROP_TIME,TimeStart);               // отрисовка поддержки
       ObjectSetDouble(0,oSup1,OBJPROP_PRICE,S1);
       ObjectSetInteger(0,oSup1,OBJPROP_TIME,1,TimeFinish);
       ObjectSetDouble(0,oSup1,OBJPROP_PRICE,1,S1);
      }
   }
I checked with Print() and got normal calculation results "Example: (GBPUSD,H1) 0.0152 i 1.5911 i 1.59682 i 2013.01.20 22:00:00 i 2013.01.22 09:46:40" but it does not draw these levels. Checking in the terminal via"Object List", they are not there. Please advise what is the problem? Where am I wrong?
 
WindSW:

I'm having trouble drawing the levels.

I checked with Print() and got normal calculation results "Example: (GBPUSD,H1) 0.0152 i 1.5911 i 1.59682 i 2013.01.20 22:00:00 i 2013.01.22 09:46:40" but it does not draw these levels. Checking in the terminal via"Object List", they are not there. Please advise what is the problem? Where am I wrong?
Print the results of ObjectCreate, maybe there is an error there.
Reason: