iCustom might not be finding the indicator, look to see if there's any errors in the journal
better code:
input int Npast =300; // # of past bars in a pattern input int Nfut =50; // # of future bars in a pattern (must be < Npast) string ind_name = "Nearest_Neighbor";
int handle = iCustom(_Symbol,PERIOD_CURRENT,ind_name, Npast, Nfut);

- www.mql5.com
when i want to get value of first buffer, it always shows empty value but in Data window shows that it ( buffer 0 ) has a value!
this is the code of indicator:
i get buffer by this code:
I ran your code through the debugger - according to the debugger watch window, only the first bar of the future buffer contains a value, everything else is EMPTY_VALUE. The issue is in your indicator.
-
//| Nearest_Neighbor.mq5 | double a = iCustom(_Symbol,PERIOD_CURRENT,"nearest-neighbor");
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/OnStart (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) -
const double& Open[], ⋮ double y=Open[bars-Npast+i];
In MT5, you must set the direction.
To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] and other arrays (copyXXXX functions), call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
I ran your code through the debugger - according to the debugger watch window, only the first bar of the future buffer contains a value, everything else is EMPTY_VALUE. The issue is in your indicator.
You're basically getting the data of the last (current) bar in the EA.
If you look at the two buffers
They give the same value on that last bar.
I see it working fine.
#include <Trade/Trade.mqh> #resource "\\Indicators\\Examples\\Nearest Neighbor.ex5" input int Npast =300; // # of past bars in a pattern input int Nfut =50; // # of future bars in a pattern (must be < Npast) int handle = INVALID_HANDLE; double first_buf[]; double second_buf[]; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- handle = iCustom(_Symbol, _Period, "::Indicators\\Examples\\Nearest Neighbor", Npast, Nfut); ArraySetAsSeries(first_buf, true); ArraySetAsSeries(second_buf, true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- IndicatorRelease(handle); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(!CopyBuffer(handle, 0, 0, 1, first_buf)){ Print("Something wrong retrieving data from buffer 0"); } if(!CopyBuffer(handle, 1, 0, 1, second_buf)){ Print("Something wrong retrieving data from buffer 1"); } double b0 = first_buf[0]; double b1 = second_buf[0]; string debug = "Buffer 0 value: " + DoubleToString(b0) + "\n" + "Buffer 1 value: " + DoubleToString(b1); Comment(debug); } //+------------------------------------------------------------------+
If you want to test this when the markets are closed, you will have to use strategy tester visual mode. There are no incoming ticks on forex markets at the weekend.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
when i want to get value of first buffer, it always shows empty value but in Data window shows that it ( buffer 0 ) has a value!
this is the code of indicator:
i get buffer by this code: