EA not getting iCustom index buffer value right

 

Hey, so I have a custom indicator that does all the logic behind the strategy and it send an arrow whenever it's to buy or sell.

And on my EA I what to check if the value of the index buffer is empty or not.


Here is my arrow setup on the Indicator:

SetIndexBuffer(0, SlowDnPts);    
SetIndexBuffer(1, SlowUpPts);
SetIndexBuffer(2, FastDnPts);
SetIndexBuffer(3, FastUpPts);
SetIndexBuffer(4, ArrowUp);
SetIndexBuffer(5, ArrowDown);
if (zone_type[i] == ZONE_SUPPORT){
if(Tweezer(MODE_BUY)){ ArrowUp[0] = Close[0]-50*Point; } }else{ if(Tweezer(MODE_SELL)){ ArrowDown[0] = Close[0]+50*Point; } }


And on the EA:


void getSignal(){
    static double ArrowUp = iCustom(_Symbol, _Period, indicator_name, 4, 1);
    static double ArrowDown = iCustom(Symbol(),Period(), indicator_name, 5, 1); 

    if(ArrowUp != EMPTY_VALUE && ArrowUp != 0)
        Print("Arrow UP: " + ArrowUp);
    if(ArrowDown != EMPTY_VALUE && ArrowDown != 0)
        Print("Arrow Down: " + ArrowDown);
}

The Data Window shows a value when the candle is printed, but I'm getting Empty Value on every single candle. 

Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • www.mql5.com
Finally we've got an opportunity to try the new trade terminal - MetaTrader 5 . No doubt, it is noteworthy and has many new features as compared to its predecessor. The important advantages of this platform among others are: Essentially modified language allowing now to use the object-oriented programming, still allowing to use the rich...
 
    static double ArrowUp = iCustom(_Symbol, _Period, indicator_name, 4, 1);
    static double ArrowDown = iCustom(Symbol(),Period(), indicator_name, 5, 1); 

Why are you using static variables?

They will never be updated with your code as it is.

 
  1. Why did you post your MT4 question in the MT5 EA section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. 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++.

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