Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 432

 
WinProject:

Thank you!) , the variable Cena=FileReadString(handle); I insert into function Separator=StringReplace(Sepa,",","."); it writes error "implicit conversion from number to string" -

doesn't want to read value with separator "," (1,22426) as a string, and StringReplace doesn't work. Or i am doing it wrong?


Please copy the part of the code as you have it, from the beginning of reading the file, specifying the CENA variable type

 
Vladislav Andruschenko:

Please copy the part of the code as you have it, from the beginning of reading the file, specifying the type of the CENA variable


void MyFunc()

{

handle=FileOpen('Data.csv',FILE_CSV|FILE_READ,';');

while(FileIsEnding(handle)!=true)

{ string cena=FileReadString(handle);

string Separ=StringReplace(cena,",".");

if(FileIsEnding(handle)==true)

break;

}

FileClose(handle);

}

 
WinProject:

void MyFunc()

{

handle=FileOpen('Data.csv',FILE_CSV|FILE_READ,';');

while(FileIsEnding(handle)!=true)

{ string cena=FileReadString(handle);

string Separ=StringReplace(cena,",".");

if(FileIsEnding(handle)==true)

break;

}

FileClose(handle);

}

Please read what this function returns. You are trying to string the result. But this function just substitutes a character for a string. You can continue to use cena with changes
 
Vladislav Andruschenko:
Please read what this function returns. You are trying to string the result. But this function just replaces a character by a character. You can continue to use cena already with the changes
I figured out my mistake, (string Separ=is redundant here) and it worked.

Thank you, thank you!)

 

Help, I need to draw a rectangle from the previous candle's high to a point 200p above it and time a bar ahead.

I wrote the code, but I don't understand why the left point of the rectangle doesn't move? And the right one slides behind the hai.

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[])
  {
//---
   //ObjectDelete(0,"Name");
   ArraySetAsSeries(high,true);
   ObjectCreate(0,"Name",OBJ_RECTANGLE,0,TimeCurrent(),high[0],TimeCurrent()+PeriodSeconds(PERIOD_CURRENT)*2,high[0]+200*_Point);
   ObjectSetInteger(0,"Name",OBJPROP_FILL,true);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Roman Sharanov:

Help, I need to draw a rectangle from the previous candle's high to a point 200p above it and time a bar ahead.

I wrote the code, but I don't understand why the left point of the rectangle doesn't move? And the right one slides behind the hai.


Maybe you are trying to create an object that is already on the chart?


And the previous bar is 1 not 0.

high[0] - это ХАЙ текущего бара
 
Vladislav Andruschenko:

Maybe you are trying to create an object that is already on the chart? It might be better to check if there are already objects on the chart.


Yes and the previous bar is 1 not 0.


That's right, already fixed the indexes.

Changed the name, looked at the list, nothing has changed, still the same, one point hangs in one place, the other follows the hai

 
Roman Sharanov That's right, already fixed the indexes.

Changed the name, looked at the list, nothing has changed, it's still the same, one point hangs in one place, the other follows the hai

   ObjectDelete(0,"Name");
   ObjectCreate(0,"Name",OBJ_RECTANGLE,0,
                TimeCurrent()-_Period*60,high[1],
                TimeCurrent()+PeriodSeconds(PERIOD_CURRENT)*2,high[0]+200*_Point);
   ObjectSetInteger(0,"Name",OBJPROP_FILL,true);
   return(rates_total);

It's moving.


 
STARIJ:
It is very simple. You need to set 7 parameters for calculation of iMA. The first parameter, the name of the symbol, is obvious. As the second one, timeframe, set M1. The third parameter - the period - set as many times as you need, how many days is more than one minute. The fourth parameter - shift = 0. The next two parameters - the method of averaging and price type - you know. The last one is the bar number. Please calculate the bar number if you know the time you need. That's all! Double-check it by making calculations for M5 and M15 timeframes. Maybe even for M30.

STARIJ, Thanks for the help, checked, unfortunately the match with the original is poor, and as the TF increases (e.g. from 30 min to weekly) the match decreases significantly. This method is better than nothing, but there is not much accuracy in it. Are there other variants?

 
Boss11:

STARIJ, Thanks for the help, checked, unfortunately the match with the original is poor, and as the TF increases (e.g. from 30 min to weekly) the match decreases significantly. This method is better than nothing, but there is not much accuracy in it. Are there other variants?

Yes. We should use M1, and M5, ... - to check. Maybe we should use interpolation? MT5 has a tick history. If you let me know where the profit is, I'll take another look.
Reason: