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

 
STARIJ:

MA crossing occurs between bars - caught a clear example

The MA on the bars to the left and right of the crossing is different from the price at the crossing point. I understand that the questioner wants the value at the exact crossing point instead of the value on one of the neighbouring bars. This exact value can be obtained using linear interpolation - after all, the MA between bars is constructed as straight line segments. Or take the coordinates of each MA on adjacent bars. Construct analytically 2 straight lines and calculate their intersection point. It is possible to calculate by considering 2 similar triangles. A counter question arises - why do we need it? Are the costs commensurate with the value of the result? After all, the intersection points will move if the MA parameters are changed minimally. Most likely, it is required by the head of the course project

Thanks for the clarification, I understand that it is not easy to do
 
missha32:

I can't find the error in my calculations.
I need to find the high and low of the previous day, but for some reason the low was on the day before

Better to use CopyHigh and CopyLow with period PERIOD_D1 and corresponding bar or time instead.

CopyHigh - Доступ к таймсериям и индикаторам - Справочник MQL4
CopyHigh - Доступ к таймсериям и индикаторам - Справочник MQL4
  • docs.mql4.com
CopyHigh - Доступ к таймсериям и индикаторам - Справочник MQL4
 
missha32: I need to find the high and the low of the previous day, but for some reason the low is in the day before
  // iHigh и iLow дают макс и мин цены указанного бара. Если PERIOD_D1, то целых суток  если 1 то вчерашних последних завершенных суток

   Alert("Максимум вчерашнего дня = ", iHigh(_Symbol, PERIOD_D1, 1));
   Alert("Минимум  вчерашнего дня = ", iLow(_Symbol,  PERIOD_D1, 1));
Any bar of any Timeframe contains generalized information of the corresponding interval of bars of lower Timeframes: Maximum; Minimum; Opening time equal to the time of the first bar in the interval; Closing time equal to the time of the last bar in the interval; Volume equal to the sum of volumes of the bars in the interval. More precisely, this information is contained in the respective arrays
 
STARIJ:
Any bar of any Timeframe contains generalized information of the corresponding interval of bars of lower Timeframes: maximum, minimum, opening and closing time and volume equal to the sum of volumes of lower bars. More precisely, this information is contained in the corresponding arrays

I would do so, but I may not be able to calculate the data using further algorithm, as I may have to search for other values of yesterday and it will be a chore to rewrite the functions again.

If you could tell me where the error is in my code, I don't understand it. When I try to display the number of bars all fit together, but when I try to get the maximum or minimum, it does not show what it should.

 
missha32:

I would do so, but I may not be able to calculate the data because I may have to look for other values from yesterday and it will be a pain in the ass to rewrite the functions again.

If you could tell me where the error is in my code, I don't understand it. When I show the number of bars on the screen, everything converges, but when I try to get the maximum or minimum, it doesn't show what it should.

You've made so much mess that I can't even make sense of it. A mountain of conversions from one to the other...

And all to find the maximum and minimum of the day?

So what's not working for you?

//+------------------------------------------------------------------+
double GetPriceMaximum(const string symbol_name,const ENUM_TIMEFRAMES timeframe,int shift){
   double array[1];
   ResetLastError();
   if(CopyHigh(symbol_name,timeframe,shift,1,array)==1) return(array[0]);
   Print(__FUNCTION__," > Ошибка копирования цены High: ",GetLastError());
   return(WRONG_VALUE);
}
//+------------------------------------------------------------------+
double GetPriceMinimum(const string symbol_name,const ENUM_TIMEFRAMES timeframe,int shift){
   double array[1];
   ResetLastError();
   if(CopyLow(symbol_name,timeframe,shift,1,array)==1) return(array[0]);
   Print(__FUNCTION__," > Ошибка копирования цены Low: ",GetLastError());
   return(WRONG_VALUE);
}
//+------------------------------------------------------------------+

Need to know the maximum of the day? Please:

double max_price=GetPriceMaximum(Symbol(),PERIOD_D1,0);

Need to find out the maximum of yesterday? Easy:

double max_price=GetPriceMaximum(Symbol(),PERIOD_D1,1);

Need to know the low of the day before yesterday? No problem:

double min_price=GetPriceMinimum(Symbol(),PERIOD_D1,2);

Well, you could take the easy way out and use pure quadruple functions:

double price_max=iHigh(Symbol(),PERIOD_D1,1);

But I would not advise - using new language constructs, you'll prepare yourself and your code to that someday quadruple will not be supported, and self-discipline and all that ;)

 
Artyom Trishkin:

You've made such a mess of it that it's hard to even sort it out. A mountain of conversions from one thing to another...

All to find the highs and lows of the day?

So what's not working for you?

Need to find out the highs of the day? Please:

Need to find out the maximum of yesterday? Easy:

Need to know the low of the day before yesterday? No problem:

Well, you could take the easy way out, and use pure quadruple functions:

But I would not advise - using new language constructs, you'll prepare yourself and your codes that someday quaternion will be unsupported, and self-discipline and all that ;)

I found a mistake myself ( all inattentiveness misread the parameters iHighest, iLowest ).

So not suitable as will need other calculations from yesterday

 
missha32:

I found the error myself (all inattention misread the iHighest,iLowest parameters).

This is not suitable as other calculations from yesterday will be needed

I don't understand why you are prevented from getting the data in a simple and natural way for other calculations.
 
missha32 every red signal for buy and every blue signal for sell to allow to fill at every signal

if(Red ) OrderSend( ... Buy ...) ; if( Blue ) OrderSend( ... Sell ...) ;

Only the opposite, sell at the top, buy at the bottom...

The function OnInit (the old one asking for init) is executed at start of the indicator (when changing timeframe, recompiling, ...). All used variables must have a value assigned to them. The SetIndexDrawBegin(0,i-1) line is present in the OnInit function; the i variable must be assigned a value or a constant must be used

 
STARIJ:

if(Red ) OrderSend( ... Buy ...) ; if( Blue ) OrderSend( ... Sell ...) ;

Only the opposite, sell at the top, buy at the bottom...

The function OnInit (the old one asking for init) is executed at start of the indicator (when changing timeframe, recompiling, ...). All used variables must have a value assigned to them. In the OnInit function, there is the SetIndexDrawBegin(0,i-1) line; the i variable must be assigned a value or use a constant

To be honest, I don't understand anything, I am new to Mql4 programming, so please help me with the code.
 
missha32:
To be honest, I don't understand anything, I'm new to Mql4 programming, if you don't mind helping me with the code.

The code usually helps in freelancing.

Here - either the algorithm or to correct your mistakes. But not to rewrite again for you.

Reason: