Questions from Beginners MQL5 MT5 MetaTrader 5 - page 533

 
      // AO
      if(ao) {
         CopyTime(symbol_name[st],ao_time_frame,1,1,time_buf);
         if(symbol_ao_timebar[st]!=time_buf[0]) {
            symbol_ao_timebar[st]=time_buf[0];
            double ao_buf[];
            CopyBuffer(symbol_ao_handle[st],0,enter_bar,2,ao_buf);
            if(ao_buf[1]>ao_buf[0]&&ao_buf[0]<0) symbol_ao_signal[st]=0;
            if(ao_buf[1]<ao_buf[0]&&ao_buf[0]>0) symbol_ao_signal[st]=1;
            }
         }else symbol_ao_signal[st]=2;
      
      // AC
      if(ac) {
         CopyTime(symbol_name[st],ac_time_frame,1,1,time_buf);
         if(symbol_ac_timebar[st]!=time_buf[0]) {
            symbol_ac_timebar[st]=time_buf[0];
            double ac_buf[];
            CopyBuffer(symbol_ac_handle[st],0,enter_bar,2,ac_buf);
            if(ac_buf[1]>ac_buf[0]&&ac_buf[0]<0) symbol_ac_signal[st]=0;
            if(ac_buf[1]<ac_buf[0]&&ac_buf[0]>0) symbol_ac_signal[st]=1;
            }      
         }else symbol_ac_signal[st]=2;
Hello, everybody. Here's a question. There's a piece of code It says. I mean it should say buy or sell, but only when the AO and AC are on the same plane. Buy below zero and sell above zero.
Is it so? Gurus, please help.
The question is basically this. Is this a normal code or some bullshit?
 
MASTERXAYS:
Hello, everybody. Here's a question. There's a piece of code It says. I mean it should say buy or sell, but only when the AO and AC are on the same plane. Buy below zero and sell above zero.
Is it so? Please, help the gurus.
The question is the following. Is this a normal code or some bullshit?

I'd call the whole approach "bullshit ."

Have you ever seen price follow an indicator? Also, note that these are the indicators of B. Williams, and he, as you know, did not trade in the Forex market, and the very idea is outdated.

 
-Aleks-:
And how, I'm sorry, do you perform this zeroing?
Exactly the same way as zeroing of simple types. By assigning 0 value to them. As soon as you assign 0 value to the required fields, you use reverse operation StructToTime().
 
MASTERXAYS:
Hello, everybody. Here's a question. There's a piece of code It says. I mean it should say buy or sell, but only when the AO and AC are on the same plane. Buy below zero and sell above zero.
Is it so? Please help the gurus.
The question is basically the following. Is this a normal code or some bullshit in green oil?

Read my article where the signal construction codes are described. But I personally write signal functions in this way.

ENUM_ORDER_TYPE GetSignal(int i,ENUM_TIMEFRAMES tf)
  {
   double bbup[1];
   double bbdw[1];
   double rsi[1];
   double macd[2];
   double stoh[2];
   double Close[2];

   if(IND01[i]==INVALID_HANDLE || IND01[i]==0){IND01[i]=iBands(m_symbol,tf,BB_period,0,2,PRICE_CLOSE);return(WRONG_VALUE);}
   if(IND02[i]==INVALID_HANDLE || IND02[i]==0){IND02[i]=iRSI(m_symbol,tf,RSI_period,PRICE_CLOSE);return(WRONG_VALUE);}
   if(IND03[i]==INVALID_HANDLE || IND03[i]==0){IND03[i]=iMACD(m_symbol,tf,MACD_fast_ema_period,MACD_slow_ema_period,9,PRICE_CLOSE);return(WRONG_VALUE);}
   if(IND04[i]==INVALID_HANDLE || IND04[i]==0){IND04[i]=iStochastic(m_symbol,tf,ST_Kperiod,ST_Dperiod,ST_slowing,MODE_SMA,STO_LOWHIGH);return(WRONG_VALUE);}

   if(CopyBuffer(IND01[i],1,0,1,bbup)<1) return(WRONG_VALUE);
   if(CopyBuffer(IND01[i],2,0,1,bbdw)<1) return(WRONG_VALUE);
   if(CopyBuffer(IND02[i],0,0,1,rsi)<1) return(WRONG_VALUE);
   if(CopyBuffer(IND03[i],0,0,2,macd)<2) return(WRONG_VALUE);
   if(CopyBuffer(IND04[i],0,0,2,stoh)<2) return(WRONG_VALUE);
   if(CopyClose(m_symbol,tf,0,2,Close)<2) return(WRONG_VALUE);

   if(Close[0]<bbdw[0]&& Close[1]>bbdw[0]&&  stoh[1]>stoh[0]&&  stoh[0]<20  &&  rsi[0]<30  &&  macd[1]<macd[0]) return(ORDER_TYPE_BUY);
   if(Close[0]>bbup[0]&& Close[1]<bbup[0]&&  stoh[1]<stoh[0]&&  stoh[0]>80  &&  rsi[0]>70  &&  macd[1]>macd[0]) return(ORDER_TYPE_SELL);

   return(WRONG_VALUE);
  }
 
Aleksey Lebedev:

It will be 1, both times are rounded to a whole day first, then subtracted.

What makes you think that all the numbers in the expression are rounded? It's not rounded. I agree that a variable will be rounded.

And if they were rounded, I showed an example - today's current bar and yesterday's calculated one - 1 hour TF - their difference would be equal to zero in all roundings ... Maybe if we always round upwards...

Alexey Kozitsyn:
Exactly like zeroing of simple types. By assigning them to 0. As soon as you've assigned 0 to required fields, you use reverse operation StructToTime().

Thanks - I'll try again - the examples in the Help are not good...

 
-Aleks-:

What makes you think that all the numbers in the expression are rounded? There is no rounding. But the variable is rounded - I agree.

And if rounded, I showed an example - current bar of today and calculated yesterday - 1 hour TF - their difference would be equal to zero in any rounding ... Maybe if we always round upwards...

When dividing integers(int,long,datetime etc) the result is an integer, i.e. the remainder is discarded. 00:00 today and 23:59:59 yesterday, the difference will be 1 day.

 

Can you tell me please, MQL4...
I can't figure out, indicator works on M5, how to refer to High or Low of previous bar on H1 in its code ?
Like iHigh(NULL,PERIOD_H1, i) ... The point is to determine (put an up/down arrow on the M5 chart) if the current M5 candle has broken the previous hour's High price.


 
In the MQL4 indicator code, replacing the line
for(i=pos; i<rates_total; i++) 
with
for(i=pos; i<rates_total-1; i++) 
leads to the fact that the indicator is not considered at the current (unfinished) bar - there is simply no indicator line under this bar.
In MQL5, the current bar has some strange indicator values, sometimes just 0.0000.
What can I do about it?
 
MikeZv:

Please give me a hint, MQL4...
I can not figure out, the indicator works on M5, how to refer to High or Low of the previous bar on H1 ?
Like iHigh(NULL,PERIOD_H1, i) ... The point is to determine (put an up/down arrow on the M5 chart) if the current M5 candle has broken the High price of the previous hour.


MikeZv:
In the MQL4 indicator code replace the line
with
leads to the fact that the indicator is not calculated on the current (unfinished) bar - there is simply no indicator line under this bar.
In MQL5, the current bar has some strange indicator values, sometimes just 0.0000.
What can I do about it?

It doesn't matter how you spin the indicator buffers there - only Juna can help here.

Added:

For the time of debugging check - what value is in time[i] array - so you understand from which end you start counting bars and where you have "zero" bar.

 
Karputov Vladimir

Little did you twist the indicator buffers there - only Juna can help here.
... which end you start counting bars from and where you have "zero" bar.

Vladimir, thanks for answering the first question, I missed these functions...

I put the same indicator in MT4 and in MT5 (of course the code is adapted to each platform).
Up to zero bar their values are the same, so apparently from one end ... :)
And when disabling the calculation on the current bar in MT4 nothing is drawn under the current bar, in MT5 - wrong values.

Files:
mvt_Vlt.mq4  5 kb
mvt_Vlt.mq5  5 kb
Reason: