Include a personalized indicator in an Expert Advisor

 
Hello I am new to MQL5 I want to know how to include a custom indicator in an Expert Advisor
 
diop18:
Hello I am new to MQL5 I want to know how to include a custom indicator in an Expert Advisor
You can study iCustom documentation page.
You can find sample codes in CodeBase.
Also you can search web.
 
Thank you so much
 
  1. Yashar Seyyedin #: You can study iCustom documentation page.

    That isn't what OP asked. Becareful with your answers.
        How To Ask Questions The Smart Way. (2004)
           Be precise and informative about your problem
              The XY Problem

  2. diop18: I want to know how to include a custom indicator in an Expert Advisor

    Don't try to do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)

    Just get the value(s) of the indicator(s) into EA/indicator (using iCustom) and do what you want with it.
              (MT4) Detailed explanation of iCustom - MQL4 programming forum (2017)

  3. If you really want to “include” it, so you can sell the EA, then embed the other indicator(s) inside your indicator/EA. Add the CI(s) to your code as a resource.

    #resource "\\Indicators… iCustom("::Indicators…
              Use the publicly released code - MQL5 programming forum (2017)
              Resources - MQL4 Reference

    Be aware that using resources is 40x times slower than using CIs directly.
              A custom indicator as a resource - MQL4 programming forum (2019)

    Also make use there are no spaces in the path.
              Getting error 4802 when loading custom indicator that loads another custom indicator with iCustom - Technical Indicators - MQL5 programming forum. (2020)

    Also Use of Resources in MQL5 - MQL5 Articles (2011)

 
if someone can program my strategy we'll discuss
 
diop18 #:
if someone can program my strategy we'll discuss

You are not alone, here is a dedicated place https://www.mql5.com/en/job;

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2024.03.31
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
Alexandre Medviediev # :

Vous n'êtes pas seul, voici un espace dédié  https://www.mql5.com/en/job ;

thank you very much
 
William Roeder #:
  • Don't try to do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)

    Just get the value(s) of the indicator(s) into EA/indicator (using iCustom) and do what you want with it.
              (MT4) Detailed explanation of iCustom - MQL4 programming forum (2017)

  • In MT4 this can be done quite easily.

    • prev_calculated is the current size of the indicator buffer (which you are emulating)
    • rates_total is the size of any predefined time series array (for example, Time)
    This is quite easy because you have ready-made time series arrays that are managed by the terminal. All you have to do is change the size of your indicator buffer array when it differs from the size of the timeseries array
     
    William Roeder #:
    No way to know if older bars have changed or been added (history update.)

    If the difference between "rates_total" and "prev_calculated" is not equal to 0 and not equal to 1, then recalculate all indicator values. If this happens, it is very rare (I add a message to the experts’ journal when calculating indicators “from scratch”)

     

    There is no rates_total or prev_calculated in an EA.

    If new history arrives, any remember Bars or previous Bars will be misleading.

     
    William Roeder #:
    There is no rates_total or prev_calculated in an EA.

    This is not difficult to implement in MT4. Below is the method code of one of my old advisors. Think of it as pseudocode

    This method controls the sizes of buffers and returns rates_total and prev_calculated

    void emulateBuffers(int &rates_total,int &prev_calculated)
      {
       prev_calculated = buffersGetSize();
       if(prev_calculated < 0)
          prev_calculated = 0;
       rates_total = ArraySize(Time);
       int notCalculated = rates_total - prev_calculated;
       if(notCalculated == 0)
          return;
       if(notCalculated != 1 && notCalculated != rates_total)
         {
          PrintFormat(__FUNCTION__" Looks like %i bars have been missed! rates_total %i, prev_calculated %i",notCalculated,rates_total,prev_calculated);
          prev_calculated = 0;
         }
       buffersSetAsSeries(false);
       buffersResize(rates_total);
       buffersSetAsSeries(true);
      }

    After calling this method, the rates_total and prev_calculated values are ready to be transferred to the indicator code (the buffer sizes are also ready).

    Example implementation of buffersGetSize:

    int CMacd::buffersGetSize(void) const
      {
       int sizeOfMacd = ArraySize(buffMacd);
       if(ArraySize(buffSignalSma) == sizeOfMacd && ArraySize(buffSignal2) == sizeOfMacd && ArraySize(buffHistogram) == sizeOfMacd)
          return(sizeOfMacd);
       Print(__FUNCTION__" critical error: Buffer sizes do not match!");
       return(-1);
      }

    Example implementation of buffersSetAsSeries:

    bool CMacd::buffersSetAsSeries(bool a_flag)
      {
       return(setAsSeries(buffMacd, a_flag) && setAsSeries(buffSignalSma, a_flag) && setAsSeries(buffSignal2, a_flag)
              && setAsSeries(buffHistogram, a_flag));
      }
    
    bool CIndBuffsBase::setAsSeries(const double &a_arr[],bool a_flag)
      {
       if(ArraySetAsSeries(a_arr, a_flag))
          return(true);
       Print(__FUNCTION__" error ", GetLastError());
       return(false);
      }

    Similar for buffersResize - this method calls ArrayResize for each buffer