"access to non-static member or function" Error

 

Hello, I'm currently confused as to why I keep getting this error when I compile: 'RSILength' - access to non-static member or function line 32

Maybe I haven't looked enough but I can't understand why it won't let me enter this variable into my RSI Handle. Thanks.


//+------------------------------------------------------------------+

//|                                                       RSI-#1.mq5 |

//|                                                   Zachary Waring |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Zachary Waring"

#property link      "https://www.mql5.com"

#property version   "1.00"



#include <Trade\Trade.mqh>

#include <Trade\PositionInfo.mqh>



input int lotsize = 1.0;

input int RSI1 = 25;

input int RSI2 = 20;

input int RSI3 = 70;

input int RSILength = 14;



bool canibuy = true;

bool canisell = true;



double RSI[];

int RSI_Handle = iRSI(NULL,0,RSILength,PRICE_CLOSE);





void OnTick()

  {

}


 
ZacharyWaring:

Hello, I'm currently confused as to why I keep getting this error when I compile: 'RSILength' - access to non-static member or function line 32

Maybe I haven't looked enough but I can't understand why it won't let me enter this variable into my RSI Handle. Thanks.



I just got the last update, and everyone, without exception of any code. They stopped working all with this same error.

I believe it is something with the latest update released a few minutes ago.

 
Jonathan Pereira:

I just got the last update, and everyone, without exception of any code. They stopped working all with this same error.

I believe it is something with the latest update released a few minutes ago.

Thank you! Hopefully it gets fixed soon.
 
ZacharyWaring:
Thank you! Hopefully it gets fixed soon.

I managed to solve the problem, I declared all variables as static. Although I think this is wrong.

 
Jonathan Pereira:

I managed to solve the problem, I declared all variables as static. Although I think this is wrong.

I just got another update (2410) and the bug was fixed.

Version 2408 was in trouble.

In it I noticed that if the variables were declared as statistical it would solve the problem, however it would generate optimization problems in the algorithms

 
int RSI_Handle = iRSI(NULL,0,RSILength,PRICE_CLOSE);
  1. Global and static variables work exactly the same way in MT4/MT5/C/C++.

    1. They are initialized once on program load.

    2. They don't update unless you assign to them.

    3. 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:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

    4. Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
                external static variable - MQL4 programming forum

  2. Perhaps you should read the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick 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.03.08
              How to call indicators in MQL5 - MQL5 Articles 12 March 2010

 
William Roeder:
  1. Global and static variables work exactly the same way in MT4/MT5/C/C++.

    1. They are initialized once on program load.

    2. They don't update unless you assign to them.

    3. 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:

      1. Terminal starts.
      2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
      3. OnInit is called.
      4. For indicators OnCalculate is called with any existing history.
      5. Human may have to enter password, connection to server begins.
      6. New history is received, OnCalculate called again.
      7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

    4. Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
                external static variable - MQL4 programming forum

  2. Perhaps you should read the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick 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.03.08
              How to call indicators in MQL5 - MQL5 Articles 12 March 2010

Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.


I think you were wrong, every change in graphics generates a call in OnDenit (reason) and supports that OnInit is called.

 
Hi, i got the same problem but when i update to (2410) the bug was fixed. So don't use version 2408 it is in trouble (may 2020).
 
Jonathan Pereira:

Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.


I think you were wrong, every change in graphics generates a call in OnDenit (reason) and supports that OnInit is called.

You have misunderstood.

With an EA, static and global variables are not reinitialized when the EA is reinitialized. If the coder requires that they are reinitialized, it must be coded to do do.

 
Jonathan Pereira:

Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.


I think you were wrong, every change in graphics generates a call in OnDenit (reason) and supports that OnInit is called.

A deinit/init are two function calls; that isn't reloading. Prove it to yourself:

int OnInit(){
  static int loaded=0;
  Print(loaded);
  ++loaded;
}

Attach to chart, see zero. Change TF, see one. Etc.

 
William Roeder:

I consider it a bad practice to create a variable within OnInit

Reason: