ROC_multi_v1

Price Data Components
Series array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
ROC_multi_v1
//+------------------------------------------------------------------+
//|                      Rate of Change for Multi Currency Pairs.mq4 |                                     |
//|                                              Ernst van der Merwe |
//+------------------------------------------------------------------+
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4

extern int TimeFrame=0;  //1=1minute;5=5minutes;15=15minutes;30=30minutes;60=1Hour;240=4Hour;1440=Daily; 

extern double level1= 300;
extern double level2= 200;
extern double level3= 100;
extern double level4=-100;
extern double level5=-200;
extern double level6=-300;
//---- indicator buffers
double  ROC_EURUSD[];
double  ROC_GBPUSD[];
double  ROC_USDJPY[];
double  ROC_USDCHF[];

string pair1="EURUSD";
string pair2="GBPUSD";
string pair3="USDJPY";
string pair4="USDCHF";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetLevelStyle(STYLE_DOT,1,LightSlateGray);
   SetLevelValue(0,level1);
   SetLevelValue(1,level2);
   SetLevelValue(2,level3);
   SetLevelValue(3,level4);
   SetLevelValue(4,level5);
   SetLevelValue(5,level6);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,RoyalBlue);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,LimeGreen);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,Yellow);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1,Red);
   IndicatorDigits(Digits+1);
   SetIndexDrawBegin(0,0);
   SetIndexDrawBegin(1,0);
   SetIndexDrawBegin(2,0);
   SetIndexDrawBegin(3,0);
//---- 
   SetIndexBuffer(0,ROC_EURUSD);
   SetIndexBuffer(1,ROC_GBPUSD);
   SetIndexBuffer(2,ROC_USDJPY);
   SetIndexBuffer(3,ROC_USDCHF);
//---- 
   switch(TimeFrame)
     {
      case 1 : string TimeFrameStr="M1"; break;
      case 5 : TimeFrameStr="M5"; break;
      case 15 : TimeFrameStr="M15"; break;
      case 30 : TimeFrameStr="M30"; break;
      case 60 : TimeFrameStr="H1"; break;
      case 240 : TimeFrameStr="H4"; break;
      case 1440 : TimeFrameStr="D1"; break;
      case 10080 : TimeFrameStr="W1"; break;
      case 43200 : TimeFrameStr="MN1"; break;
      default : TimeFrameStr="";
     }
   IndicatorShortName("ROC "+TimeFrameStr);
   SetIndexLabel(0,pair1);
   SetIndexLabel(1,pair2);
   SetIndexLabel(2,pair3);
   SetIndexLabel(3,pair4);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   if(Bars<1000) return(-1);
   int      i,limit=1000;

   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   limit = Bars - counted_bars;
   if(counted_bars==0) limit--;
      
   double   EURUSD[];
   double   GBPUSD[];
   double   USDJPY[];
   double   USDCHF[];
   
   int size=ArraySize(ROC_EURUSD);
   ArrayResize(EURUSD,size);
   ArrayResize(GBPUSD,size);
   ArrayResize(USDJPY,size);
   ArrayResize(USDCHF,size);

   ArraySetAsSeries(GBPUSD,true);
   ArraySetAsSeries(EURUSD,true);
   ArraySetAsSeries(USDJPY,true);
   ArraySetAsSeries(USDCHF,true);
   
   for(i=0; i<limit; i++)
     {
      double vEURUSD=iClose(pair1,TimeFrame,i+1);
      double vGBPUSD=iClose(pair2,TimeFrame,i+1);
      double vUSDJPY=iClose(pair3,TimeFrame,i+1);
      double vUSDCHF=iClose(pair4,TimeFrame,i+1);
      if (vEURUSD!=0) EURUSD[i]=((iClose(pair1,TimeFrame,i)-iClose(pair1,TimeFrame,i+1))/vEURUSD)*1000;
      if (vGBPUSD!=0) GBPUSD[i]=((iClose(pair2,TimeFrame,i)-iClose(pair2,TimeFrame,i+1))/vGBPUSD)*1000;
      if (vUSDJPY!=0) USDJPY[i]=((iClose(pair3,TimeFrame,i)-iClose(pair3,TimeFrame,i+1))/vUSDJPY)*1000;
      if (vUSDCHF!=0) USDCHF[i]=((iClose(pair4,TimeFrame,i)-iClose(pair4,TimeFrame,i+1))/vUSDCHF)*1000;
     }

   ROC_EURUSD[limit]=0;
   ROC_GBPUSD[limit]=0;
   ROC_USDJPY[limit]=0;
   ROC_USDCHF[limit]=0;

   for(i=limit-1; i>=0; i--)
   {
      ROC_EURUSD[i]=ROC_EURUSD[i+1]+EURUSD[i];
      ROC_GBPUSD[i]=ROC_GBPUSD[i+1]+GBPUSD[i];
      ROC_USDJPY[i]=ROC_USDJPY[i+1]+USDJPY[i];
      ROC_USDCHF[i]=ROC_USDCHF[i+1]+USDCHF[i];
   }   
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---