Can my EA use levels from a different chart?

 

For my trading strategy I use levels from high timeframes like the Daily and H4, but my trigger to enter is found on much smaller timeframes like m1 and m5. My levels are drawn on the daily with a custom indicator. I'm trying to figure out whether I can create an EA to leave running on my trigger chart. However, to be effective I need to use daily levels that were drawn days or even weeks ago. Since there are 1440 m1 candles in a day I would need to use a lot of data to compute those levels. So, is it possible that I can have the daily indicator running on the daily chart and the EA running on my m1 chart and the EA will use the data from the indicator on the other chart? 

I tried searching this answer, but I've been struggling to articulate what I'm asking in a short sentence. Thanks in advance!

 
dasilvja:

For my trading strategy I use levels from high timeframes like the Daily and H4, but my trigger to enter is found on much smaller timeframes like m1 and m5. My levels are drawn on the daily with a custom indicator. I'm trying to figure out whether I can create an EA to leave running on my trigger chart. However, to be effective I need to use daily levels that were drawn days or even weeks ago. Since there are 1440 m1 candles in a day I would need to use a lot of data to compute those levels. So, is it possible that I can have the daily indicator running on the daily chart and the EA running on my m1 chart and the EA will use the data from the indicator on the other chart? 

I tried searching this answer, but I've been struggling to articulate what I'm asking in a short sentence. Thanks in advance!

Yes. You just need to code your technical analysis logic to call the higher timeframe, e.g., PERIOD_D1, in the EA that runs on the PERIOD_M1 timeframe.

Depending on how your indicator is coded, iCustom() is generally the best way to call an indicator in an EA.

iCustom - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
The function returns the handle of a specified custom indicator. Parameters symbol [in] The symbol name of the security, the data of which should...
 
dasilvja:

For my trading strategy I use levels from high timeframes like the Daily and H4, but my trigger to enter is found on much smaller timeframes like m1 and m5. My levels are drawn on the daily with a custom indicator. I'm trying to figure out whether I can create an EA to leave running on my trigger chart. However, to be effective I need to use daily levels that were drawn days or even weeks ago. Since there are 1440 m1 candles in a day I would need to use a lot of data to compute those levels. So, is it possible that I can have the daily indicator running on the daily chart and the EA running on my m1 chart and the EA will use the data from the indicator on the other chart? 

I tried searching this answer, but I've been struggling to articulate what I'm asking in a short sentence. Thanks in advance!

Yes you can , here is an example

#property version   "1.00"
input ENUM_TIMEFRAMES MA_TIMEFRAME=PERIOD_D1;//Moving average timeframe
input ENUM_MA_METHOD MA_Method=MODE_SMA;//Moving average method
input ENUM_APPLIED_PRICE MA_Price=PRICE_CLOSE;//Moving average price
input int MA_Period=100;//Moving average period
/* you will need to be VERY careful accessing higher timeframes , maintain symmetry ,meaning
   you must be able to repeat what you did live in the past.
   tracking change of bar for other tf V
*/
datetime OtherTFbarStamp=0,currentBarStamp=0;
int handle=INVALID_HANDLE;
bool systemLoaded=false;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   OtherTFbarStamp=0;
   currentBarStamp=0;
   systemLoaded=false;
   handle=INVALID_HANDLE;
   EventSetMillisecondTimer(600);
   return(INIT_SUCCEEDED);
  }
void OnTimer()
  {
  if(SymbolIsSynchronized(_Symbol)){
    EventKillTimer();
    ResetLastError();
    int errors=0;
    handle=iMA(_Symbol,MA_TIMEFRAME,MA_Period,0,MA_Method,MA_Price);errors+=GetLastError();ResetLastError();
    OtherTFbarStamp=iTime(_Symbol,MA_TIMEFRAME,0);errors+=GetLastError();ResetLastError();
    currentBarStamp=iTime(_Symbol,_Period,0);errors+=GetLastError();ResetLastError();
    if(errors!=0){
      Print("Cannot initialize ");
      ExpertRemove();
      return;
      }else{
      systemLoaded=true;
      //zero out timers for showcase
        OtherTFbarStamp=0;
        currentBarStamp=0;
      }
    }
  }
void OnTick()
  {
  //if loaded
    if(systemLoaded){
      //if higher tf new bar 
        if(iTime(_Symbol,MA_TIMEFRAME,0)>OtherTFbarStamp){
          OtherTFbarStamp=iTime(_Symbol,MA_TIMEFRAME,0);
          double ma[];
          CopyBuffer(handle,0,0,1,ma);
          Print("MA "+DoubleToString(ma[0],_Digits));
          }
      }
  }
void OnDeinit(const int reason)
  {
//--- destroy timer
   if(handle!=INVALID_HANDLE){
     IndicatorRelease(handle);
     }
   EventKillTimer();
  }