How to call this custom indicator values in mt5 expert with iCustom option. I don't understand, read many articles and posts. no answer anywhere. please help me. Thank you.

 
//+------------------------------------------------------------------+
//|                                                    multi_usd_ind |
//|                                           Copyright 2014 Winston |
//+------------------------------------------------------------------+
#property copyright "Winston"
#property version "1.10"
#property description "Multi Currency Indicator with USD reference"
#property indicator_separate_window
#property indicator_level1 0.001; // 0.1% lines
#property indicator_level2 -0.001;
#property indicator_level3 0.01;  //  1% lines
#property indicator_level4 -0.01;
#property indicator_level5 0.1;   // 10% lines
#property indicator_level6 -0.1; 
#property indicator_label1 "USD"
#property indicator_buffers 7
#property indicator_plots   7
#property indicator_type1   DRAW_LINE
#property indicator_color1  Orange     // AUDUSD
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_type2   DRAW_LINE
#property indicator_color2  White      // EURUSD
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
#property indicator_type3   DRAW_SECTION
#property indicator_color3  Red        // GBPUSD
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
#property indicator_type4   DRAW_LINE
#property indicator_color4  Yellow     // NZDUSD
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
#property indicator_type5   DRAW_LINE
#property indicator_color5  Aqua       // USDCAD inverted
#property indicator_style5  STYLE_DOT
#property indicator_width5  1
#property indicator_type6   DRAW_SECTION
#property indicator_color6  SpringGreen // USDCHF inverted
#property indicator_style6  STYLE_DOT
#property indicator_width6  1
#property indicator_type7   DRAW_SECTION
#property indicator_color7  Violet     // USDJPY inverted
#property indicator_style7  STYLE_DOT
#property indicator_width7  1
//---
input double k=1.0; // Smoothing factor
input int p=60;     // Period
//---
int T,n=p;
double aug[],eug[],gug[],nug[],cug[],hug[],jug[]; // Display indicators
//---
MqlRates AU[],EU[],GU[],NU[],UC[],UH[],UJ[];
MqlDateTime tim;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
   ArraySetAsSeries(aug,true);
   ArraySetAsSeries(eug,true);
   ArraySetAsSeries(gug,true);
   ArraySetAsSeries(nug,true);
   ArraySetAsSeries(cug,true);
   ArraySetAsSeries(hug,true);
   ArraySetAsSeries(jug,true);
//---
   SetIndexBuffer(0,aug,INDICATOR_DATA);
   SetIndexBuffer(1,eug,INDICATOR_DATA);
   SetIndexBuffer(2,gug,INDICATOR_DATA);
   SetIndexBuffer(3,nug,INDICATOR_DATA);
   SetIndexBuffer(4,cug,INDICATOR_DATA);
   SetIndexBuffer(5,hug,INDICATOR_DATA);
   SetIndexBuffer(6,jug,INDICATOR_DATA);
//---
   ArraySetAsSeries(AU,true);
   ArraySetAsSeries(EU,true);
   ArraySetAsSeries(GU,true);
   ArraySetAsSeries(NU,true);
   ArraySetAsSeries(UC,true);
   ArraySetAsSeries(UH,true);
   ArraySetAsSeries(UJ,true);
//---
   IndicatorSetString(INDICATOR_SHORTNAME,"AUD-org EUR-wht GBP-red NZD-yel CAD-blu CHF-green JPY-vio");
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
   TimeCurrent(tim);
   if(T!=tim.min)
     {
      T=tim.min;
      n++;
     }
//---
   ArrayInitialize(aug,0);
   ArrayInitialize(eug,0);
   ArrayInitialize(gug,0);
   ArrayInitialize(nug,0);
   ArrayInitialize(cug,0);
   ArrayInitialize(hug,0);
   ArrayInitialize(jug,0);
//---
   CopyRates("AUDUSD",0,0,n+1,AU);
   CopyRates("EURUSD",0,0,n+1,EU);
   CopyRates("GBPUSD",0,0,n+1,GU);
   CopyRates("NZDUSD",0,0,n+1,NU);
   CopyRates("USDCAD",0,0,n+1,UC);
   CopyRates("USDCHF",0,0,n+1,UH);
   CopyRates("USDJPY",0,0,n+1,UJ);
//---
   double au=0,eu=0,gu=0,nu=0,uc=0,uh=0,uj=0;
//---
   for(int i=n;i>=0;i--)
     {
      if(AU[i].close*AU[n].close>0){au+=k*(1-AU[n].close/AU[i].close-au); aug[i]=au;}
      if(EU[i].close*EU[n].close>0){eu+=k*(1-EU[n].close/EU[i].close-eu); eug[i]=eu;}
      if(GU[i].close*GU[n].close>0){gu+=k*(1-GU[n].close/GU[i].close-gu); gug[i]=gu;}
      if(NU[i].close*NU[n].close>0){nu+=k*(1-NU[n].close/NU[i].close-nu); nug[i]=nu;}
      if(UC[i].close*UC[n].close>0){uc+=k*(1-UC[i].close/UC[n].close-uc); cug[i]=uc;}
      if(UH[i].close*UH[n].close>0){uh+=k*(1-UH[i].close/UH[n].close-uh); hug[i]=uh;}
      if(UJ[i].close*UJ[n].close>0){uj+=k*(1-UJ[i].close/UJ[n].close-uj); jug[i]=uj;}
        
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
iCustom - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
vedaveer vengala: I don't understand, read many articles and posts. no answer anywhere.

Perhaps you should read the manual. You don't call indicators. You read the buffers with iCustom.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2018)

We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
          No free help (2017)

 

Thanks brother. I already tried with that code. But the calue is coming 1 only.. not real value. can you please give me sample.

 

Brother this is what i tried. as shown in that link but the value is coming only 1 always.. 

//+------------------------------------------------------------------+
//|                                              Moving Averages.mq5 |
//|                   Copyright 2009-2017, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009-2017, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#include <Trade\Trade.mqh>

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
 

 double aug[] ;
int MA_handle;
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+ 
//+------------------------------------------------------------------+
//| Position select depending on netting or hedging                  |
//+------------------------------------------------------------------+ 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(void)
  { 
  
        SetIndexBuffer(0,aug,INDICATOR_DATA);
   ResetLastError();
   MA_handle=iCustom(NULL,0,"Markets\\multi_usd_ind",  0, 0 ); 
   Print("MA_handle = ",MA_handle,"  error = ",GetLastError());
        
         
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(void)
  {
        
  
 
  }
 
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+

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[])

 {
 
//--- Copy the values of the indicator Custom Moving Average to our indicator buffer
   int copy=CopyBuffer(MA_handle,0,0,rates_total,aug);
   Print("copy = ",copy,"    rates_total = ",rates_total);
   
   Comment(  "\n   copy:  "+DoubleToString(copy,4)   );
   
//--- If our attempt has failed - Report this
   if(copy<=0)
      Print("An attempt to get the values if Custom Moving Average has failed");
//--- return value of prev_calculated for next call
 

   return(rates_total);
  }
 
 

Hi!

1) You create handle of indicator by iCustom(). It is better to do in in OnInit().

2) You use CopyBuffer() for getting values from created handle.

 
vedaveer vengala #:

Brother this is what i tried. as shown in that link but the value is coming only 1 always.. 

You must NOT mix OnTick() and OnCalculate(), one is only for EAs one only for indicators!

You should study(!):

Quickstart for newbies: https://www.mql5.com/en/articles/496
and: https://www.mql5.com/en/articles/100
cookbook: https://www.mql5.com/en/search#!keyword=cookbook

Bear in mind there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you - so searching gives better results than AI or ChatGPT!

Quick Start: Short Guide for Beginners
Quick Start: Short Guide for Beginners
  • www.mql5.com
Hello dear reader! In this article, I will try to explain and show you how you can easily and quickly get the hang of the principles of creating Expert Advisors, working with indicators, etc. It is beginner-oriented and will not feature any difficult or abstruse examples.
Reason: