I have checked the code and was not able to find the error, could you help?
You only declared the array and didn't set the buffer.
You only declared the array and didn't set the buffer.
Until today I guess I found what you meant by set the buffer, my new code shows no error but still it fails to show, i have to try several times and it gets disable anytime, could you help me again or do you suggest me to use freelance?
//+------------------------------------------------------------------+ //| Herrcrowley_master_nc_jpy.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 //--- plot Down #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 3 //--- indicator buffers double L[]; input bool type1 = true; //=============================== MA input int MAper = 3; // период скользящего среднего input ENUM_MA_METHOD mamethod = MODE_SMA; // метод input ENUM_APPLIED_VOLUME type_volume = VOLUME_TICK; int hMA, hMA2, hMA3, hMA4, hMA5, hMA6, hMA7, hMA8, hMA9, hMA10, hMA11, hMA12, kb, ks, hrsi, hst, hAC, hMACD , hADX, hWPR, hcci, hROC, hpar, hAO, j, hVolumesAUDJPY, hVolumesCADJPY, hVolumesCHFJPY, hVolumesGBPJPY, hVolumesNZDJPY, hVolumesUSDJPY, hVolumesEURJPY; double ma[], ma2[], ma3[], ma4[], ma5[], ma6[], ma7[], ma8[], ma9[], ma10[], ma11[], ma12[], close0[], rsi[], stm[], ac[], macdm[], macds[], dip[], dim[], wpr[], cci[], roc[], par[], ao[], z1, z2, sumz, sum, mai[], hAUDJPY[], hCADJPY[], hCHFJPY[], hGBPJPY[], hNZDJPY[], hUSDJPY[], hEURJPY[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,hAUDJPY,INDICATOR_DATA); SetIndexBuffer(0,hCADJPY,INDICATOR_DATA); SetIndexBuffer(0,hCHFJPY,INDICATOR_DATA); SetIndexBuffer(0,hGBPJPY,INDICATOR_DATA); SetIndexBuffer(0,hNZDJPY,INDICATOR_DATA); SetIndexBuffer(0,hUSDJPY,INDICATOR_DATA); SetIndexBuffer(0,hEURJPY,INDICATOR_DATA); SetIndexBuffer(0,L,INDICATOR_DATA); //--- hVolumesAUDJPY=iCustom("AUDJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesCADJPY=iCustom("CADJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesCHFJPY=iCustom("CHFJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesGBPJPY=iCustom("GBPJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesNZDJPY=iCustom("NZDJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesUSDJPY=iCustom("USDJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesEURJPY=iCustom("EURJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); 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[]) { CopyBuffer(hVolumesAUDJPY,0,0,rates_total,hAUDJPY); CopyBuffer(hVolumesCADJPY,0,0,rates_total,hCADJPY); CopyBuffer(hVolumesCHFJPY,0,0,rates_total,hCHFJPY); CopyBuffer(hVolumesGBPJPY,0,0,rates_total,hGBPJPY); CopyBuffer(hVolumesNZDJPY,0,0,rates_total,hNZDJPY); CopyBuffer(hVolumesUSDJPY,0,0,rates_total,hUSDJPY); CopyBuffer(hVolumesEURJPY,0,0,rates_total,hEURJPY); int i; for(i = rates_total-1; i>=0; i--) { L[i] = -(hAUDJPY[i]+ hCADJPY[i]+ hCHFJPY[i]+hGBPJPY[i]+hNZDJPY[i]+hUSDJPY[i]+hEURJPY[i])/7; } return(rates_total); }
#property indicator_buffers 8 #property indicator_plots 1
SetIndexBuffer(0, L, INDICATOR_DATA); SetIndexBuffer(1, hAUDJPY, INDICATOR_CALCULATIONS); SetIndexBuffer(2, hCADJPY, INDICATOR_CALCULATIONS); SetIndexBuffer(3, hCHFJPY, INDICATOR_CALCULATIONS); SetIndexBuffer(4, hGBPJPY, INDICATOR_CALCULATIONS); SetIndexBuffer(5, hNZDJPY, INDICATOR_CALCULATIONS); SetIndexBuffer(6, hUSDJPY, INDICATOR_CALCULATIONS); SetIndexBuffer(7, hEURJPY, INDICATOR_CALCULATIONS);
William's point is not taken into account.
William's point is not taken into account.
L[i] = -(hAUDJPY[i]+ hCADJPY[i]+ hCHFJPY[i]+hGBPJPY[i]+hNZDJPY[i]+hUSDJPY[i]+hEURJPY[i])/7;You also assume that all charts have the same number of bars. Do not assume that indexes are the same. You must use iBarShift.
You also assume that all charts have the same number of bars. Do not assume that indexes are the same. You must use iBarShift.
I update the script to this but it's showing an error that says "EURJPY 1 invalid Bar removed" when I use Daily on weekend as now as timeframe, any advice would help, thanks.
//+------------------------------------------------------------------+ //| Herrcrowley_master_nc_jpy.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property indicator_separate_window #property indicator_buffers 8 #property indicator_plots 1 //--- plot Down #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 3 //--- indicator buffers double L[]; input bool type1 = true; //=============================== MA input int MAper = 3; // период скользящего среднего input ENUM_MA_METHOD mamethod = MODE_SMA; // метод input ENUM_APPLIED_VOLUME type_volume = VOLUME_TICK; datetime tm=TimeCurrent(); ENUM_TIMEFRAMES timeframe = PERIOD_CURRENT; bool exact = true; int hMA, hMA2, hMA3, hMA4, hMA5, hMA6, hMA7, hMA8, hMA9, hMA10, hMA11, hMA12, kb, ks, hrsi, hst, hAC, hMACD , hADX, hWPR, hcci, hROC, hpar, hAO, j; int hVolumesAUDJPY = iBarShift("AUDJPY", timeframe, tm, exact); int hVolumesCADJPY = iBarShift("CADJPY", timeframe, tm, exact); int hVolumesCHFJPY = iBarShift("CHFJPY", timeframe, tm, exact); int hVolumesGBPJPY= iBarShift("GBPJPY", timeframe, tm, exact); int hVolumesNZDJPY = iBarShift("NZDJPY", timeframe, tm, exact); int hVolumesUSDJPY = iBarShift("USDJPY", timeframe, tm, exact); int hVolumesEURJPY = iBarShift("EURJPY", timeframe, tm, exact); double ma[], ma2[], ma3[], ma4[], ma5[], ma6[], ma7[], ma8[], ma9[], ma10[], ma11[], ma12[], close0[], rsi[], stm[], ac[], macdm[], macds[], dip[], dim[], wpr[], cci[], roc[], par[], ao[], z1, z2, sumz, sum, mai[], hAUDJPY[], hCADJPY[], hCHFJPY[], hGBPJPY[], hNZDJPY[], hUSDJPY[], hEURJPY[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,L,INDICATOR_DATA); SetIndexBuffer(1,hAUDJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(2,hCADJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(3,hCHFJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(4,hGBPJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(5,hNZDJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(6,hUSDJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(7,hEURJPY,INDICATOR_CALCULATIONS); //--- hVolumesAUDJPY=iCustom("AUDJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesCADJPY=iCustom("CADJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesCHFJPY=iCustom("CHFJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesGBPJPY=iCustom("GBPJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesNZDJPY=iCustom("NZDJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesUSDJPY=iCustom("USDJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesEURJPY=iCustom("EURJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); 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[]) { CopyBuffer(hVolumesAUDJPY,0,0,rates_total,hAUDJPY); CopyBuffer(hVolumesCADJPY,0,0,rates_total,hCADJPY); CopyBuffer(hVolumesCHFJPY,0,0,rates_total,hCHFJPY); CopyBuffer(hVolumesGBPJPY,0,0,rates_total,hGBPJPY); CopyBuffer(hVolumesNZDJPY,0,0,rates_total,hNZDJPY); CopyBuffer(hVolumesUSDJPY,0,0,rates_total,hUSDJPY); CopyBuffer(hVolumesEURJPY,0,0,rates_total,hEURJPY); int i; for(i = rates_total-1; i>=0; i--) { L[i] = -(hAUDJPY[i]+ hCADJPY[i]+ hCHFJPY[i]+hGBPJPY[i]+hNZDJPY[i]+hUSDJPY[i]+hEURJPY[i]); } return(rates_total); }
int hVolumesAUDJPY = iBarShift("AUDJPY", timeframe, tm, exact); int hVolumesCADJPY = iBarShift("CADJPY", timeframe, tm, exact); int hVolumesCHFJPY = iBarShift("CHFJPY", timeframe, tm, exact); int hVolumesGBPJPY= iBarShift("GBPJPY", timeframe, tm, exact); int hVolumesNZDJPY = iBarShift("NZDJPY", timeframe, tm, exact); int hVolumesUSDJPY = iBarShift("USDJPY", timeframe, tm, exact); int hVolumesEURJPY = iBarShift("EURJPY", timeframe, tm, exact);That is not an assignment; it's initialization of a common (globally declared,) or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
- They are initialized once on program load.
- They don't update unless you assign to them.
- In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use.)
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
- Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum
You also assume that all charts have the same number of bars. Do not assume that indexes are the same. You must use iBarShift.
I proposed iBarShift to look for the last active bar and added to the count for i, that would be right?? sorry, i am pretty new into this.
//+------------------------------------------------------------------+ //| Herrcrowley_master_nc_jpy.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property indicator_separate_window #property indicator_buffers 8 #property indicator_plots 1 //--- plot Down #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 3 //--- indicator buffers double L[]; input bool type1 = true; //=============================== MA input int MAper = 3; // период скользящего среднего input ENUM_MA_METHOD mamethod = MODE_SMA; // метод input ENUM_APPLIED_VOLUME type_volume = VOLUME_TICK; datetime tm=TimeCurrent()-5; ENUM_TIMEFRAMES timeframe = PERIOD_CURRENT; bool exact = true; int hMA, hMA2, hMA3, hMA4, hMA5, hMA6, hMA7, hMA8, hMA9, hMA10, hMA11, hMA12, kb, ks, hrsi, hst, hAC, hMACD , hADX, hWPR, hcci, hROC, hpar, hAO, j, hVolumesAUDJPY, hVolumesCADJPY, hVolumesCHFJPY, hVolumesGBPJPY, hVolumesNZDJPY, hVolumesUSDJPY, hVolumesEURJPY; int iAUDJPY = iBarShift("AUDJPY", timeframe, tm, exact); int iCADJPY = iBarShift("CADJPY", timeframe, tm, exact); int iCHFJPY = iBarShift("CHFJPY", timeframe, tm, exact); int iGBPJPY= iBarShift("GBPJPY", timeframe, tm, exact); int iNZDJPY = iBarShift("NZDJPY", timeframe, tm, exact); int iUSDJPY = iBarShift("USDJPY", timeframe, tm, exact); int iEURJPY = iBarShift("EURJPY", timeframe, tm, exact); double ma[], ma2[], ma3[], ma4[], ma5[], ma6[], ma7[], ma8[], ma9[], ma10[], ma11[], ma12[], close0[], rsi[], stm[], ac[], macdm[], macds[], dip[], dim[], wpr[], cci[], roc[], par[], ao[], z1, z2, sumz, sum, mai[], hAUDJPY[], hCADJPY[], hCHFJPY[], hGBPJPY[], hNZDJPY[], hUSDJPY[], hEURJPY[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,L,INDICATOR_DATA); SetIndexBuffer(1,hAUDJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(2,hCADJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(3,hCHFJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(4,hGBPJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(5,hNZDJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(6,hUSDJPY,INDICATOR_CALCULATIONS); SetIndexBuffer(7,hEURJPY,INDICATOR_CALCULATIONS); //--- hVolumesAUDJPY=iCustom("AUDJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesCADJPY=iCustom("CADJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesCHFJPY=iCustom("CHFJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesGBPJPY=iCustom("GBPJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesNZDJPY=iCustom("NZDJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesUSDJPY=iCustom("USDJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); hVolumesEURJPY=iCustom("EURJPY", 0, "Herrcrowley_for_master_nc", type1, MAper, mamethod, type_volume); 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[]) { CopyBuffer(hVolumesAUDJPY,0,0,rates_total,hAUDJPY); CopyBuffer(hVolumesCADJPY,0,0,rates_total,hCADJPY); CopyBuffer(hVolumesCHFJPY,0,0,rates_total,hCHFJPY); CopyBuffer(hVolumesGBPJPY,0,0,rates_total,hGBPJPY); CopyBuffer(hVolumesNZDJPY,0,0,rates_total,hNZDJPY); CopyBuffer(hVolumesUSDJPY,0,0,rates_total,hUSDJPY); CopyBuffer(hVolumesEURJPY,0,0,rates_total,hEURJPY); int i; for(i = rates_total-1; i>=0; i--) { L[i] = -(hAUDJPY[i+iAUDJPY] +hCADJPY[i+iCADJPY] +hCHFJPY[i+iCHFJPY] +hGBPJPY[i+iGBPJPY] +hNZDJPY[i+iNZDJPY] +hUSDJPY[i+iUSDJPY] +hEURJPY[i+iEURJPY]); } return(rates_total); }
int iAUDJPY = iBarShift("AUDJPY", timeframe, tm, exact); int iCADJPY = iBarShift("CADJPY", timeframe, tm, exact); int iCHFJPY = iBarShift("CHFJPY", timeframe, tm, exact); int iGBPJPY= iBarShift("GBPJPY", timeframe, tm, exact); int iNZDJPY = iBarShift("NZDJPY", timeframe, tm, exact); int iUSDJPY = iBarShift("USDJPY", timeframe, tm, exact); int iEURJPY = iBarShift("EURJPY", timeframe, tm, exact);
- They are initialized once on program load.
- They don't update unless you assign to them.
- In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use.)
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
- Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have checked the code and was not able to find the error, could you help?
2020.05.03 22:54:34.762 Herrcrowley_master_nc_jpy (USDJPY,H8) array out of range in 'Herrcrowley_master_nc_jpy.mq5' (94,63), the error is highlighted, thanks.