wrong buffer value retrieved from mql5 indicator using iCustom

wrong buffer value retrieved from mql5 indicator using iCustom

Manage alerts

Loading saved threads...

Umer · External communityPost link
External question — Stack Overflow Stack Exchange Author: Umer Original post: https://stackoverflow.com/questions/67105867 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I just moved from mql4 to mql5 and now i am trying to read buffers values from an indicator , but it only shows me 0 instead of the actual buffer values Here is my code : #property version "1.00" int handle1 = 0; double valu1,valu2,valu3,valu4; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create timer EventSetTimer(60); handle1 = iCustom(NULL, NULL, "LTD by KDMfx"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- destroy timer EventKillTimer(); IndicatorRelease(handle1); } //+------------------------------------------------------------------+ //| Get indicator value | //+------------------------------------------------------------------+ double GetIndicator(int handle, int buffer_num, int index) { double arr[]; if(CopyBuffer(handle, buffer_num, 0, index+1, arr) <= 0) { Sleep(200); for(int i=0; i<100; i++) { if(BarsCalculated(handle) > 0) break; Sleep(50); } int copied = CopyBuffer(handle, buffer_num, 0, index+1, arr); if(copied <= 0) { Print("CopyBuffer failed. Maybe history has not download yet? Error = ", GetLastError()); return -1; } else return (arr[index]); } return 0; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { //--- valu1 = GetIndicator(handle1,0,4); valu2 = GetIndicator(handle1,1,4); valu3 = GetIndicator(handle1,2,4); valu4 = GetIndicator(handle1,3,4); Comment("b1: ", valu1, "\nb2: ", valu2, "\nb3: ", valu3, "\nb4: ", valu4 ); } what am i doing wrong here ? the indicator does not appear on the current or the last closed candle , it appears on the current+4 candle , meaning on the 5th candle in past . so i am using "4" as the candle id but still no use , no matter what i try i can get it to work
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange Author: PaulB Original post: https://stackoverflow.com/a/67106742 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Try simplifying things a bit. I don't have a copy of the indicator you are trying to read, but the following code should work #property version "1.10" #property strict int handle; //+------------------------------------------------------------------+ //| Initialization function of the expert | //+------------------------------------------------------------------+ int OnInit() { handle=iCustom(_Symbol, 0, "LTD by KDMfx"); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Deinitialization function of the expert | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { IndicatorRelease(handle); } //+------------------------------------------------------------------+ //| "Tick" event handler function | //+------------------------------------------------------------------+ void OnTick() { double LTDindicator[]; ArraySetAsSeries(LTDindicator, true); CopyBuffer(handle, 0, 0, 25, LTDindicator); Comment(LTDindicator[0]); return; }
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Umer Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/67105867 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I just moved from mql4 to mql5 and now i am trying to read buffers values from an indicator , but it only shows me 0 instead of the actual buffer values Here is my code : #property version "1.00" int handle1 = 0; double valu1,valu2,valu3,valu4; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create timer EventSetTimer(60); handle1 = iCustom(NULL, NULL, "LTD by KDMfx"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- destroy timer EventKillTimer(); IndicatorRelease(handle1); } //+------------------------------------------------------------------+ //| Get indicator value | //+------------------------------------------------------------------+ double GetIndicator(int handle, int buffer_num, int index) { double arr[]; if(CopyBuffer(handle, buffer_num, 0, index+1, arr) <= 0) { Sleep(200); for(int i=0; i<100; i++) { if(BarsCalculated(handle) > 0) break; Sleep(50); } int copied = CopyBuffer(handle, buffer_num, 0, index+1, arr); if(copied <= 0) { Print("CopyBuffer failed. Maybe history has not download yet? Error = ", GetLastError()); return -1; } else return (arr[index]); } return 0; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { //--- valu1 = GetIndicator(handle1,0,4); valu2 = GetIndicator(handle1,1,4); valu3 = GetIndicator(handle1,2,4); valu4 = GetIndicator(handle1,3,4); Comment("b1: ", valu1, "\nb2: ", valu2, "\nb3: ", valu3, "\nb4: ", valu4 ); } what am i doing wrong here ? the indicator does not appear on the current or the last closed candle , it appears on the current+4 candle , meaning on the 5th candle in past . so i am using "4" as the candle id but still no use , no matter what i try i can get it to work

Cancel quote

Checking account access…