Indicator Class returns error 4807 in live chart but runs without any error in Strategy Tester!!!

 

Dear Fellow Members

The documentation says:

ERR_INDICATOR_WRONG_HANDLE

4807

Wrong indicator handle


I have included following check, but still in live chart I get error 4807 though none of handles return no error:

          if(mHandleFast == INVALID_HANDLE || mHandleMid == INVALID_HANDLE || mHandleSlow == INVALID_HANDLE) {
                string vMethod = "[" + mSymbol + "," + EnumToString(mTimeFrame) + "] " + __FUNCTION__;
            PrintFormat("%s Error[#%i] Creating handle CiVWMA_Tx Fast or Mid or Slow",vMethod,GetLastError());
          }

Result from EA run in live chart

2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       [XAUUSD,PERIOD_M15] CiVWMA_Tx::getFast Error[#4807] getting iVWMA_PeriodTX Fast at Index[1]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       [XAUUSD,PERIOD_M15] CiVWMA_Tx::getMid Error[#4807] getting iVWMA_PeriodTX Mid at Index[1]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       [XAUUSD,PERIOD_M15] CiVWMA_Tx::getSlow Error[#4807] getting iVWMA_PeriodTX Slow at Index[1]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       PeriodM15 Slow[0] Mid[0] Fast[0]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       [XAUUSD,PERIOD_M5] CiVWMA_Tx::getFast Error[#4807] getting iVWMA_PeriodTX Fast at Index[1]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       [XAUUSD,PERIOD_M5] CiVWMA_Tx::getMid Error[#4807] getting iVWMA_PeriodTX Mid at Index[1]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       [XAUUSD,PERIOD_M5] CiVWMA_Tx::getSlow Error[#4807] getting iVWMA_PeriodTX Slow at Index[1]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       PeriodM05 Slow[0] Mid[0] Fast[0]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       [XAUUSD,PERIOD_M1] CiVWMA_Tx::getFast Error[#4807] getting iVWMA_PeriodTX Fast at Index[1]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       [XAUUSD,PERIOD_M1] CiVWMA_Tx::getMid Error[#4807] getting iVWMA_PeriodTX Mid at Index[1]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       [XAUUSD,PERIOD_M1] CiVWMA_Tx::getSlow Error[#4807] getting iVWMA_PeriodTX Slow at Index[1]
2024.07.11 19:30:01.114 EA_CiVWMA_Tx (XAUUSD,M15)       PeriodM01 Slow[0] Mid[0] Fast[0]

Result from EA run in Strategy Tester

2024.07.11 19:29:44.023 XAUUSD,M15: testing of Experts\AuraPro\Testing\EA_CiVWMA_Tx.ex5 from 2024.07.03 00:00 to 2024.07.09 00:00 started with inputs:
2024.07.11 19:29:44.023   InpSymbol=XAUUSD
2024.07.11 19:29:44.178 XAUUSD,M5: history cache allocated for 107563 bars and contains 106328 bars from 2023.01.03 01:00 to 2024.07.02 23:55
2024.07.11 19:29:44.178 XAUUSD,M5: history begins from 2023.01.03 01:00
2024.07.11 19:29:44.317 XAUUSD,M1: history cache allocated for 537182 bars and contains 531010 bars from 2023.01.03 01:00 to 2024.07.02 23:58
2024.07.11 19:29:44.317 XAUUSD,M1: history begins from 2023.01.03 01:00
2024.07.11 19:29:44.483 2024.07.03 01:01:00   PeriodM15 Slow[2327.56] Mid[2326.5] Fast[2327.03]
2024.07.11 19:29:44.483 2024.07.03 01:01:00   PeriodM05 Slow[2326.54] Mid[2327.76] Fast[2329.87]
2024.07.11 19:29:44.483 2024.07.03 01:01:00   PeriodM01 Slow[2329.1] Mid[2329.56] Fast[2329.54]
2024.07.11 19:29:44.852 2024.07.03 01:15:00   PeriodM15 Slow[2327.57] Mid[2326.53] Fast[2327.37]
2024.07.11 19:29:44.852 2024.07.03 01:15:00   PeriodM05 Slow[2326.55] Mid[2328.14] Fast[2329.96]
2024.07.11 19:29:44.852 2024.07.03 01:15:00   PeriodM01 Slow[2329.39] Mid[2329.92] Fast[2330.29]
2024.07.11 19:29:45.266 2024.07.03 01:30:00   PeriodM15 Slow[2327.58] Mid[2326.55] Fast[2327.73]
2024.07.11 19:29:45.266 2024.07.03 01:30:00   PeriodM05 Slow[2326.57] Mid[2328.52] Fast[2330.11]
2024.07.11 19:29:45.266 2024.07.03 01:30:00   PeriodM01 Slow[2329.65] Mid[2330.39] Fast[2330.93]

Necessary indicator, class and test EA is included herewith.

Please help me to debug what is causing this error.

Thanks in advance and best regards

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
Files:
CiVWMA_Tx.mqh  7 kb
iVWMA.ex5  27 kb
LibNewBar.mqh  5 kb
 
Anil Varma: I have included following check, but still in live chart I get error 4807 though none of handles return no error:
  1.       cVWMAM15 = CiVWMA_Tx(InpSymbol,PERIOD_M15,param);
    You create an anonymous object including the internal handles.
  2. You copy the internals to cVWMAM15
  3. The anonymous object is then destroyed.
    CiVWMA_Tx::~CiVWMA_Tx() {
    
          IndicatorRelease(mHandleFast);
    Your handles, including the copies, are now invalid.
 
William Roeder #:
  1. You create an anonymous object including the internal handles.
  2. You copy the internals to cVWMAM15
  3. The anonymous object is then destroyed. Your handles, including the copies, are now invalid.

Hi @William Roeder

Thanks for you reply. However I could not get what exactly you mean to say and what solution you have suggested. Can you please elaborate.

I have just tried using my old practice of creating pointer / new key word / delete object in the EA. With this it works without error 4807.

Regards