Using Multi Time Frames

 

Hi,


If using an EA running on H1, what is needed to use values from other timeframes? 

I am currently calling the data using code such as this to call it:


iClose(NULL,PERIOD_M1,1)


Still, I am only getting the H1 closing price. Even when running it on Tick data. What am I missing here? Any help is appriciated.

Thanks

 
martinRedg:

Hi,


If using an EA running on H1, what is needed to use values from other timeframes? 

I am currently calling the data using code such as this to call it:



Still, I am only getting the H1 closing price. Even when running it on Tick data. What am I missing here? Any help is appriciated.

Thanks

https://docs.mql4.com/series/ibarshift

iBarShift - Timeseries and Indicators Access - MQL4 Reference
iBarShift - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iBarShift - Timeseries and Indicators Access - MQL4 Reference
 
Mehmet Bastem:

https://docs.mql4.com/series/ibarshift

Thank you Mehmet. I have tried this and successfully used it to close trades. However, timestamps on those closes are still on the open charts timeframe. So even if I am trying to close on M5 while using EA on H1 it still closes only on H1.

To further explain, pls see screenshot where the function is only executed on exact hours:

60362466: Alpari-ECN-Demo - Demo-konto - [GBPUSD,H1] (gyazo.com)

Here is my attempt at doing this, please let me know if you see any obvious flaws that I can correct:


void barShiftClose(double RG2, string symb, int Magic, double Slippage)
{
     if(RG2 != 0)
     {
       for (int iii = OrdersTotal() - 1; iii >= 0; iii --) 
         {
         if (OrderSelect(iii, SELECT_BY_POS, MODE_TRADES))
            {
            if (OrderSymbol() == symb && OrderMagicNumber() == Magic) 
               {

      datetime  then    =       TimeCurrent()-300;
      int               bar     =       iBarShift(NULL, PERIOD_M5, then, true);
         
         switch(OrderType())
         {
         case OP_BUY:
         
            if(Close[bar] > OrderTakeProfit()-0.0005)
            {OrderClose(OrderTicket(),OrderLots(), Bid,Slippage, Green);
            Print("barClose");}

         case OP_SELL:
         
            if(Close[bar] < OrderTakeProfit()+0.0005)
            {OrderClose(OrderTicket(),OrderLots(), Ask,Slippage, Green);
            Print("barClose");}   
                  
               }
           }
   }
}
} 
}
Reason: