Indicator#CRS https://www.mql5.com/en/market/product/24310
The code for your reference.
//+------------------------------------------------------------------+ //| CRS-Demo.mq4 | //| Copyright 2019,fxMeter | //| https://www.mql5.com/en/users/fxmeter | //+------------------------------------------------------------------+ #property copyright "Copyright 2019,fxMeter" #property link "https://www.mql5.com/en/users/fxmeter" #property version "1.00" #property strict input string CRS_Setting="------------------------"; input ENUM_TIMEFRAMES CRS_TimeFrame=PERIOD_D1; input int BarsToCalculate=90; input int MaPeriodsToSmoothLines=0; input string Suffix=""; string Currency[8]= {"USD","EUR","GBP","AUD","NZD","CAD","CHF","JPY"}; //basic definition: CURRENCY_BASE and CURRENCY_MARGIN from SymbolInfoString() //EURUSD: EUR is currency base, USD is currency margin //USDJPY: USD is currency base, JPY is currency margin string currencyBase,currencyMargin; //the current symbol of chart: EUR,USD double currencyBasePower[5]= {0},currencyMarginPower[5]= {0}; double powerDiff[5]= {0};// power difference = base power - margin power //-- index1: the index of currency base in array Currency[8] //-- index2: the index of currency margin in array Currency[8] int index1,index2; double overBoughtLevel = 80,overSoldLevel=20; //---struct struct StructCurrencyPower { double value; string currency; }; StructCurrencyPower AllCurPower[8]; //all 8 currency power //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- get the currency base / currency margin from the current symbol currencyBase=StringSubstr(Symbol(),0,3); currencyMargin=StringSubstr(Symbol(),3,3); //--- index1,index2 for(int i=0; i<8; i++) { if(currencyBase==Currency[i]) { index1=i; } if(currencyMargin==Currency[i]) { index2=i; } } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- GetCurrentChartPower(); //--1. buy signal -- currency base cross up currency margin bool buySignal = powerDiff[1]>0 && powerDiff[2]<0; //--2. sell signal -- currency base cross down currency margin bool sellSignal = powerDiff[1]<0 && powerDiff[2]>0; //--3. over bought -- currency base over bought bool baseOverBought = currencyBasePower[1]<overBoughtLevel && currencyBasePower[2]>=overBoughtLevel; //--4. over sold -- currency base over sold bool baseOverSold = currencyBasePower[1]>overSoldLevel && currencyBasePower[2]<=overSoldLevel; //--5. over bought -- currency margin over bought bool marginOverBought = currencyMarginPower[1]<overBoughtLevel && currencyMarginPower[2]>=overBoughtLevel; //--6. over sold -- currency margin over sold bool marginOverSold = currencyMarginPower[1]>overSoldLevel && currencyMarginPower[2]<=overSoldLevel; //--7. get all 8 currency power,and sort GetAllPower(0); //0: the current bar SortAllPower(); //--try to comment on chart string text=""; for(int i=7;i>=0;i--) { text += AllCurPower[i].currency +","+DoubleToString(AllCurPower[i].value,2)+"\n"; } Comment(text); //--- } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void GetCurrentChartPower() { double v=0; for(int i=0; i<5; i++) { v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix, index1,i); currencyBasePower[i]=NormalizeDouble(v,2); } for(int i=0; i<5; i++) { v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix, index2,i); currencyMarginPower[i]=NormalizeDouble(v,2); } for(int i=0; i<5; i++) { powerDiff[i]=currencyBasePower[i]-currencyMarginPower[i]; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetUsdPower(int shift) { double v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix,0,shift); v = NormalizeDouble(v,2); return(v); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetEurPower(int shift) { double v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix,1,shift); v = NormalizeDouble(v,2); return(v); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetGbpPower(int shift) { double v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix,2,shift); v = NormalizeDouble(v,2); return(v); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetAudPower(int shift) { double v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix,3,shift); v = NormalizeDouble(v,2); return(v); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetNzdPower(int shift) { double v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix,4,shift); v = NormalizeDouble(v,2); return(v); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetCadPower(int shift) { double v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix,5,shift); v = NormalizeDouble(v,2); return(v); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetChfPower(int shift) { double v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix,6,shift); v = NormalizeDouble(v,2); return(v); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetJpyPower(int shift) { double v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix,7,shift); v = NormalizeDouble(v,2); return(v); } //+------------------------------------------------------------------+ //---Get all 8 currency power void GetAllPower(int shift) { for(int i=0; i<8; i++) { AllCurPower[i].currency = Currency[i]; } for(int i=0; i<8; i++) { double v=iCustom(NULL,CRS_TimeFrame,"\\Market\\Currency Relative Strength", false,BarsToCalculate,MaPeriodsToSmoothLines,Suffix,i,shift); AllCurPower[i].value = NormalizeDouble(v,2); } } //--- sort AllCurPower void SortAllPower() { int total = ArraySize(AllCurPower); bool sorted=false; StructCurrencyPower tmp; while(!sorted) { sorted=true; for(int i=1; i<total; i++) { if(AllCurPower[i-1].value>AllCurPower[i].value) { tmp=AllCurPower[i-1]; AllCurPower[i-1]=AllCurPower[i]; AllCurPower[i]=tmp; sorted=false; } } total--; } } //+------------------------------------------------------------------+
Files:
CRS-Demo.mq4
10 kb