Open position using indicator

 

Hi, 

I have an indicator that creates a 'dot' on the chart prompting me to either buy if the dot is blue or sell if the dot is orange. Please excuse my lack of correct jargon as I only started working with MQL this morning. I am trying to have an EA open the positions for me instead of having to open positions manually when a 'dot' is added to the chart. If anyone could point me in the right direction to capture this info from the indicator. I have looked at using iCustom but I fail to understand how to make the relevant info available from the indicator e.g. "Open long now" to the EA. Once again, I know that I am not using the correct jargon but I am very new to MQL.

 
Heinrich Kruger:

Hi, 

I have an indicator that creates a 'dot' on the chart prompting me to either buy if the dot is blue or sell if the dot is orange. Please excuse my lack of correct jargon as I only started working with MQL this morning. I am trying to have an EA open the positions for me instead of having to open positions manually when a 'dot' is added to the chart. If anyone could point me in the right direction to capture this info from the indicator. I have looked at using iCustom but I fail to understand how to make the relevant info available from the indicator e.g. "Open long now" to the EA. Once again, I know that I am not using the correct jargon but I am very new to MQL.

Welcome to MQL . 

First thing you have to do (i assume you dont have the source code for the indicator) is check the indicator buffers bar to bar and see which buffer 
controls which dot ,with iCustom .

So you will build a test EA and after initialization you will make a pass of say 10 bars and check each indicator buffer .

This is the point of differentiation between MT4 + MT5 so i'll wait for you to tell me which one you are learning

 
Lorentzos Roussos:

Welcome to MQL . 

First thing you have to do (i assume you dont have the source code for the indicator) is check the indicator buffers bar to bar and see which buffer 
controls which dot ,with iCustom .

So you will build a test EA and after initialization you will make a pass of say 10 bars and check each indicator buffer .

This is the point of differentiation between MT4 + MT5 so i'll wait for you to tell me which one you are learning

Hi Lorentzo,

Thank you for your swift reply. I am using MQL5. For curiosity sake, what do you call the dot that's added to the chart?


Please find the onCalculate function below, hopefully it provides you with so clarification as to what info the indicator should make available.

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
{
   ArraySetAsSeries(time, true);
   ArraySetAsSeries(high, true);
   ArraySetAsSeries(low, true);
   int limit;
   if (prev_calculated <= 0 || prev_calculated > rates_total)
   {
      limit = rates_total - 2;
      ArrayInitialize(trend, 0);
      ArrayInitialize(trendh, 0);
      ArrayInitialize(up, EMPTY_VALUE);
      ArrayInitialize(dn, EMPTY_VALUE);
      ArrayInitialize(uph, EMPTY_VALUE);
      ArrayInitialize(dnh, EMPTY_VALUE);
   }
   else
      limit = rates_total - prev_calculated + 1;

   double blue[1], orange[1], qqe1[1], qqe2[1];   
   for(int i=limit; i > 0; i--)
   {
      up[i] = EMPTY_VALUE;
      dn[i] = EMPTY_VALUE;
      uph[i] = EMPTY_VALUE;
      dnh[i] = EMPTY_VALUE;
      trend[i] = trend[i + 1];
      trendh[i] = trendh[i + 1];
      if (CopyBuffer(MACD_Handle, 0, i, 1, blue) <= 0
         || CopyBuffer(MACD_Handle, 1, i, 1, orange) <= 0
         || CopyBuffer(QQE_Handle, 0, i, 1, qqe1) <= 0
         || CopyBuffer(QQE_Handle, 1, i, 1, qqe2) <= 0)
      {
         return(0);
      }
      if (trend[i] != UP_TREND && blue[0] >= orange[0] && qqe1[0] >= qqe2[0])    
      {
         trend[i] = UP_TREND;
         up[i] = low[i] - 2 * pnt;
         if (i == 1 && dt[0] < time[0])
            alert_sig("Trend change to Up!", 0, time[0]);
      }
      else if (trend[i] != DOWN_TREND && blue[0] < orange[0] && qqe1[0] < qqe2[0]) 
      {
         trend[i] = DOWN_TREND;
         dn[i] = high[i] + 2 * pnt;
         if (i==1 && dt[0] < time[0])
            alert_sig("Trend change to Dn!", 0, time[0]);
      }
      if (HigherTimeFrame > 0 && HigherTimeFrame > Period())
      {
         int shift = iBarShift(HigherTimeFrame, time[i]);
         int nextshift = iBarShift(HigherTimeFrame, time[i - 1]);
         if (shift != -1) // last current chart bar for the higher time frame bar
         {
            double blueh[1], orangeh[1], qqe1h[1], qqe2h[1];
            if (CopyBuffer(MACDH_Handle, 0, shift, 1, blueh) <= 0
               || CopyBuffer(MACDH_Handle, 1, shift, 1, orangeh) <= 0
               || CopyBuffer(QQEH_Handle, 0, shift, 1, qqe1h) <= 0
               || CopyBuffer(QQEH_Handle, 1, shift, 1, qqe2h) <= 0)
            {
               return(0);
            }
            if (trendh[i] != UP_TREND && blueh[0] >= orangeh[0] && qqe1h[0] >= qqe2h[0])    
            {
               trendh[i] = UP_TREND;
               uph[i] = low[i] - 4 * pnt;
               if (i == 1 && dt[1] < time[0] && shift != nextshift)
                  alert_sig("Higher TimeFrame Trend change to Up!", 1, time[0]);
            }
            else if (trendh[i] != DOWN_TREND && blueh[0] < orangeh[0] && qqe1h[0] < qqe2h[0])
            {
               trendh[i] = DOWN_TREND;
               dnh[i] = high[i] + 4 * pnt;
               if (i == 1 && dt[1] < time[0] && shift != nextshift)
                  alert_sig("Higher TimeFrame Trend change to Dn!", 1, time[0]);
            }
         }
      }
   }
//----
   return (rates_total);
}
 
From what i understand it monitors the native and one higher timeframe .
And the buffers " up , uph , dn ,dnh " might have the dots you seek . Also , there should be 2 kinds of dots , one more pronounced (i assume) 
to signify the higher timeframe .

So now , in the "OnInit" function , you will find the declaration of buffers "SetIndexBuffer" etc ...
Thats how you may find which buffer to call with iCustom . 
for example , lets say you want to read the uph buffer .
You go in Oninit  , find the "SetIndexBuffer" declaration with "uph" array declared , the number after the first parenthesis is the 
index buffer you will enter in iCustom to read from uph.
 
Lorentzos Roussos:
From what i understand it monitors the native and one higher timeframe .
And the buffers " up , uph , dn ,dnh " might have the dots you seek . Also , there should be 2 kinds of dots , one more pronounced (i assume) 
to signify the higher timeframe .

So now , in the "OnInit" function , you will find the declaration of buffers "SetIndexBuffer" etc ...
Thats how you may find which buffer to call with iCustom . 
for example , lets say you want to read the uph buffer .
You go in Oninit  , find the "SetIndexBuffer" declaration with "uph" array declared , the number after the first parenthesis is the 
index buffer you will enter in iCustom to read from uph.

This is what I have done based on your response:

#resource "\\Indicators\\QMP Filter.ex5"

double up[], dn[], uph[], dnh[];

up[]=iCustom(NULL,0,"\\Indicators\\QMP Filter.ex5",0);
dn[]=iCustom(NULL,0,"\\Indicators\\QMP Filter.ex5",1);
uph[]=iCustom(NULL,0,"\\Indicators\\QMP Filter.ex5",2);
dnh[]=iCustom(NULL,0,"\\Indicators\\QMP Filter.ex5",3);

Does this look right? 

Another question, how do I bundle the indicator and the indicators on which it depends so that they are compiled along with the EA so that it will work as a self-contained unit?

 
  1. Heinrich Kruger: Does this look right? 
    up[]=iCustom(NULL,0,"\\Indicators\\QMP Filter.ex5",0);

    No. Perhaps you should read the manual. In MT5, iCustom returns an int, a handle. You need to use the handle in CopyBuffer as the documentation says.
              Technical Indicators / iCustom - Reference on algorithmic/automated trading language for MetaTrader 5

  2. Heinrich Kruger: how do I bundle the indicator and the indicators on which it depends so that they are compiled along with the EA so that it will work as a self-contained unit?
    Just embed the other indicator(s) inside your indicator/EA. Add the CI(s) to your code as a resource.
              Use the publicly released code - Expert Advisors and Automated Trading - MQL5 programming forum
              Resources - MQL4 programs - MQL4 Reference
    #resource "\\Indicators\\indicator.ex5" //include the indicator in your file
    int IndicHandle=iCustom(NULL,PERIOD_CURRENT,"::Indicators\\indicator.ex5", …
Reason: