Multi Currency Indicator with USD Indicator- Please some one help me to calling indicator values in Expert mql5

 

Hello Guys. 

    I know Little bit MQL4 Language only But i don't know at all MQL5.

    it it very simple to get this indicator values in Mql4 Expert. But I don't understand how to get the indicator values in Mql5. 

    I am attaching the indicator below please some one help me how can i get the values in Expert.  give an example to calling the values in default     NORMAL MOVING AVERAGE Expert. 

    in MQL4 i can get the values with iCustom. like this..    

    

   double   audusd= iCustom("AUDUSD",0,"multi_usd_ind",0,0) ;
   double   eurusd= iCustom("EURUSD",0,"multi_usd_ind",1,0) ;
   double   gbpusd= iCustom("GBPUSD",0,"multi_usd_ind",2,0) ;

          I can get what ever the position values i want, its easy but i don't understand how to get them in Mql5.

          I searched many articles but still i don't understand how to solve this problem.

         Please tell me how can i get this MULTI CURRENCY INDICATOR values in default NORMAL MOVING AVERAGE Expert.

         If i know how to get the values in Expert i can do lot of research on this.  daily i am spending more than 8 hours to create a good Expert.

         Mql4 does not support MULTI currency strategy tester. So i need to use MT5 for testing. 


        Thank you in advance . Please help me. I will remember your help will help you back when you need me. 


  

       



  

 //+------------------------------------------------------------------+

//|                                                    multi_usd_ind |

//|                                           Copyright 2014 Winston |

//+------------------------------------------------------------------+

#property copyright "Winston"

#property version "1.10"

#property description "Multi-usd"

#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);

  }

//+------------------------------------------------------------------+














//+------------------------------------------------------------------+
//|                                              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>

input double MaximumRisk        = 0.02;    // Maximum Risk in percentage
input double DecreaseFactor     = 3;       // Descrease factor
input int    MovingPeriod       = 12;      // Moving Average period
input int    MovingShift        = 6;       // Moving Average shift
//---
int    ExtHandle=0;
bool   ExtHedging=false;
CTrade ExtTrade;
 
#define MA_MAGIC 1234501
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double TradeSizeOptimized(void)
  {
   double price=0.0;
   double margin=0.0;
//--- select lot size
   if(!SymbolInfoDouble(_Symbol,SYMBOL_ASK,price))
      return(0.0);
   if(!OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1.0,price,margin))
      return(0.0);
   if(margin<=0.0)
      return(0.0);

   double lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_MARGIN_FREE)*MaximumRisk/margin,2);
//--- calculate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      //--- select history for access
      HistorySelect(0,TimeCurrent());
      //---
      int    orders=HistoryDealsTotal();  // total history deals
      int    losses=0;                    // number of losses orders without a break

      for(int i=orders-1;i>=0;i--)
        {
         ulong ticket=HistoryDealGetTicket(i);
         if(ticket==0)
           {
            Print("HistoryDealGetTicket failed, no trade history");
            break;
           }
         //--- check symbol
         if(HistoryDealGetString(ticket,DEAL_SYMBOL)!=_Symbol)
            continue;
         //--- check Expert Magic number
         if(HistoryDealGetInteger(ticket,DEAL_MAGIC)!=MA_MAGIC)
            continue;
         //--- check profit
         double profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
         if(profit>0.0)
            break;
         if(profit<0.0)
            losses++;
        }
      //---
      if(losses>1)
         lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
     }
//--- normalize and check limits
   double stepvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
   lot=stepvol*NormalizeDouble(lot/stepvol,0);

   double minvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
   if(lot<minvol)
      lot=minvol;

   double maxvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
   if(lot>maxvol)
      lot=maxvol;
//--- return trading volume
   return(lot);
  }
//+------------------------------------------------------------------+
//| Check for open position conditions                               |
//+------------------------------------------------------------------+
void CheckForOpen(void)
  {
  
   
   
   MqlRates rt[2];
//--- go trading only for first ticks of new bar
   if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
     {
      Print("CopyRates of ",_Symbol," failed, no history");
      return;
     }
   if(rt[1].tick_volume>1)
      return;
//--- get current Moving Average 
   double   ma[1];
   if(CopyBuffer(ExtHandle,0,0,1,ma)!=1)
     {
      Print("CopyBuffer from iMA failed, no data");
      return;
     }
     
     
     
//--- check signals
   ENUM_ORDER_TYPE signal=WRONG_VALUE;

   if(rt[0].open>ma[0] && rt[0].close<ma[0])
      signal=ORDER_TYPE_SELL;    // sell conditions
   else
     {
      if(rt[0].open<ma[0] && rt[0].close>ma[0])
         signal=ORDER_TYPE_BUY;  // buy conditions
     }
//--- additional checking
   if(signal!=WRONG_VALUE)
     {
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && Bars(_Symbol,_Period)>100)
         ExtTrade.PositionOpen(_Symbol,signal,TradeSizeOptimized(),
                               SymbolInfoDouble(_Symbol,signal==ORDER_TYPE_SELL ? SYMBOL_BID:SYMBOL_ASK),
                               0,0);
     }
//---
  }
//+------------------------------------------------------------------+
//| Check for close position conditions                              |
//+------------------------------------------------------------------+
void CheckForClose(void)
  {
   MqlRates rt[2];
//--- go trading only for first ticks of new bar
   if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
     {
      Print("CopyRates of ",_Symbol," failed, no history");
      return;
     }
   if(rt[1].tick_volume>1)
      return;
//--- get current Moving Average 
   double   ma[1];
   if(CopyBuffer(ExtHandle,0,0,1,ma)!=1)
     {
      Print("CopyBuffer from iMA failed, no data");
      return;
     }
//--- positions already selected before
   bool signal=false;
   long type=PositionGetInteger(POSITION_TYPE);

   if(type==(long)POSITION_TYPE_BUY && rt[0].open>ma[0] && rt[0].close<ma[0])
      signal=true;
   if(type==(long)POSITION_TYPE_SELL && rt[0].open<ma[0] && rt[0].close>ma[0])
      signal=true;
//--- additional checking
   if(signal)
     {
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && Bars(_Symbol,_Period)>100)
         ExtTrade.PositionClose(_Symbol,3);
     }
//---
  }
//+------------------------------------------------------------------+
//| Position select depending on netting or hedging                  |
//+------------------------------------------------------------------+
bool SelectPosition()
  {
   bool res=false;
//--- check position in Hedging mode
   if(ExtHedging)
     {
      uint total=PositionsTotal();
      for(uint i=0; i<total; i++)
        {
         string position_symbol=PositionGetSymbol(i);
         if(_Symbol==position_symbol && MA_MAGIC==PositionGetInteger(POSITION_MAGIC))
           {
            res=true;
            break;
           }
        }
     }
//--- check position in Netting mode
   else
     {
      if(!PositionSelect(_Symbol))
         return(false);
      else
         return(PositionGetInteger(POSITION_MAGIC)==MA_MAGIC); //---check Magic number
     }
//--- result for Hedging mode
   return(res);
  }
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- prepare trade class to control positions if hedging mode is active
   ExtHedging=((ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE)==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);
   ExtTrade.SetExpertMagicNumber(MA_MAGIC);
   ExtTrade.SetMarginMode();
   ExtTrade.SetTypeFillingBySymbol(Symbol());
//--- Moving Average indicator
   ExtHandle=iMA(_Symbol,_Period,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE);
   if(ExtHandle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(INIT_FAILED);
     }
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(void)
  {
//---
   if(SelectPosition())
      CheckForClose();
   else
      CheckForOpen();
//---
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Program Properties (#property) - Preprocessor - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

  3.  if(AU[i].close*AU[n].close>0){au+=k*(1-AU[n].close/AU[i].close-au); aug[i]=au;}

    When will a price times a price ever be non-positive?

 

Please edit your post to use the CODE button (Alt-S)!

Use the CODE button


 
Sergey Golubev #:

Please edit your post to use the CODE button (Alt-S)!


Thank you brother.. It is first time i am asking question. so i don't know many option. I have edited and updated my post.

 
William Roeder #:
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

  3. When will a price times a price ever be non-positive?

Thank you brother.. It is first time i am asking question. so i don't know many options. I have edited and updated my post.
Reason: