Question about aquiring EMA on higher time frame?

 

Hello everyone:


I was able to write part of the indicator that I want, thanks to all the help on this forum. What it does so far is just display a histogram signal (RED or GREEN) bar only if a EMA fan of 4 moving averages line up on the 4 Hour time frame.Now I am trying to check two higher time frames to see if the price is above or below he 200 EMA (Weekly & daily) and I want to only show my bar on the histogram when all three conditions are in sync. 


My problem:   As I cycle through every bar ion the 4 Hour time frame, How can I figure out what he corresponding bar is on say the Daily time frame? For instance, there are six 4 Hour bars on one Daily bar so I would be checking only bar 0 on the daily for the first 6 bars on the 4 hour. I know how to manually figure out which bar it is, but as I cycle through my main loop to check every 4 hour candle, is there a formula that can give me the correct candle shift to use on any higher time frame to make sure I am looking at the correct candle that lines up with the lower time frame.


I may be saying it wrong, but here is how I am setting up my higher Time Frames:

---------------------------------------

 TF2_handle = iMA(NULL,TF2,EMA200,0,MODE_EMA,PRICE_CLOSE);

 ArraySetAsSeries(TF2_Buffer,true);

----------------------------------------


And here is how I am trying to figure out if the price on any 4 Hour candle is above or below the 200 EMA on any higher timeframe. the shift is the same shift as the 4 hour main OnCalculate loop so do I need to modify it to reflect the correct candle on the higher (daily) TF in this case?

Thanks and let me know if I am making no sense or explaining this wrong..

--------------------------------------

  int Trend(int shift, const double &price[])

  {

  int TF2_Trend = 0;

  

  if(TF2_Buffer[shift] < price[shift]) 

     {

      TF2_Trend = 1;    // price on the current 4 hour candle is above 200EMA on Daily TF.

     }

  if(TF2_Buffer[shift] > price[shift]) 

     {

      TF2_Trend = -1;    // price on the current 4 hour candle is below 200EMA on Daily TF.

     }

  return(TF2_Trend);

 
Topgun_68: so do I need to modify it to reflect the correct candle on the higher (daily) TF in this case?
Yes, the MT5 equivalent of iBarShift See Migrating from MQL4 to MQL5 - MQL5 Articles
 
whroeder1:
Yes, the MT5 equivalent of iBarShift See Migrating from MQL4 to MQL5 - MQL5 Articles


Wow, I was trying to do it manually.

Thanks  :<)

 
https://www.mql5.com/en/code/1864
iBarShift
iBarShift
  • votes: 41
  • 2013.10.25
  • Alain Verleyen
  • www.mql5.com
There are a lot of users who searched for iBarShift function like in MQL4. But this function is no more include in MQL5, mainly because MQL5 provides all necessary basic, low-level, functions to process such thing in a library.
Reason: