//+------------------------------------------------------------------+ //| DLabs_CurrencyPortfolio.mq4 | //| Copyright 2018, Darwinex Labs. | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, Darwinex Labs." #property strict #property script_show_inputs #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 DodgerBlue input string Portfolio_Info = "Enter Symbols & Weights (sep. by commas)"; //--- input parameters input string Portfolio_Assets = "NZDCHF,GBPJPY,AUDUSD,EURCAD"; input string Portfolio_Weights = "-1,1,1,-1"; input string Analysis_Info = "Enter Analysis Start Date Below"; input string StartDate = "2017.01.01"; //--Buffers indexes double idx[]; string symbolArray[]; string weightArray[]; string portfolioAllocations = ""; int numSymbols = 0; int numWeights = 0; datetime firstDateTime; int yOffset = 20; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { numSymbols = StringSplit(Portfolio_Assets,StringGetCharacter(",",0),symbolArray); numWeights = StringSplit(Portfolio_Weights,StringGetCharacter(",",0),weightArray); // Check Symbols match Weights if(numSymbols != numWeights) { Alert("No. of Symbols MUST MATCH No. of Weights. Exiting.."); return(INIT_FAILED); } IndicatorShortName("[Darwinex Labs] Currency Portfolio Constructor"); IndicatorBuffers(1); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,idx); SetIndexLabel(0,"PORTFOLIO"); firstDateTime=StrToTime(StartDate); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { PrintOnIndicatorWindow(Portfolio_Assets, Portfolio_Weights, yOffset); ArraySetAsSeries(idx,false); ArraySetAsSeries(time,false); int limit; if(prev_calculated==0) { idx[0]=100.0; limit=1; } else { limit=prev_calculated-1; } for(int i=limit; ifirstDateTime) { double contribution=0; for(int j=0;j