Buff Dormeier's VPCI Indicator Based on Technical Analysis of Stocks & Commodities Vol 25 July Traders' Tips Tradestation Easylanguage code

 

Please forgive me if I'm in the wrong place or doing this wrong, I'm new to this, i need help with the attached code.

It compiles but the indicator does not display in the MT4 chart.

when debugging it hangs up, i don't know and can't find where the error is.

here is the Tradestation Easylanguage code this indicator is based on

Indicator: VPCI

inputs: Price( Close ), Length1( 5 ), Length2( 20 ), VPCIAvgLen( 20 ) ;

variables: VolValue( 0 ), VolumeSum1( 0 ), VolumeSum2( 0 ), VWMA1( 0 ), VWMA2( 0 ), VP( 0 ), VPR( 0 ), VM( 0 ), VPCI( 0 ), AvgVPCI( 0 ) ;

if BarType >= 2 then { not tick/minute data } VolValue = Volume else VolValue = Ticks ;

VolumeSum1 = Summation( VolValue, Length1 ) ; if VolumeSum1 > 0 then VWMA1 = Summation( Price * VolValue , Length1 ) / VolumeSum1 ;

VolumeSum2 = Summation( VolValue, Length2 ) ; if VolumeSum2 > 0 then VWMA2 = Summation( Price * VolValue , Length2 ) / VolumeSum2 ;

VP = VWMA2 - Average( Price, Length2 ) ;

VPR = VWMA1 / Average( Low, Length1 ) ;

VM = Average( VolValue, Length1 ) / Average( VolValue, Length2 ) ;

VPCI = VP * VPR * VM ;

AvgVPCI = Average( VPCI, VPCIAvgLen ) ;

Plot1( VPCI, “VPCI” ) ; Plot2( AvgVPCI, “VPCISmooth” ) ; Plot3( 0, “Zero” ) ;

my mql4 code is attached.

Please tell me why it doesn't work, Thanks

Files:
VPCI.mq4  6 kb
 
  1. Marc Antzis: It compiles but the indicator does not display in the MT4 chart.

    Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have moved this thread.

  2. datetime NewCandleTime = TimeCurrent();
    

    That is not an assignment; it's initialization of a common (globally declared), or static variable(s) 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 indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), 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. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  3.    ArrayCopy(VolValue,Volume,0,0,WHOLE_ARRAY); 
       return(INIT_SUCCEEDED);
    

    What is the purpose of VolValue? Just use the predefined array Volume?

  4. bool IsNewCandle()

    There is no need for new candle code in indicators.
              How to do your lookbacks correctly #9#14 & #19 (2016)

  5.    ArrayCopy(VPCIx,VPCI,0,0,WHOLE_ARRAY);  
       AvgVPCI[i+1] = SumAvg(VPCIAvgLen,i+1,VPCIx,0);
    

    What is the purpose of VPCIx? just use VPCI.

  6.       Counted_bars=IndicatorCounted(); // Number of counted bars
          i=Bars-Counted_bars-21;   
    
    After the first run your loops do nothing.
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

    You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference


  7.       while(i==0)                      // Loop for uncounted bars
    

    This is an infinite loop.
              How to do your lookbacks correctly #9#14 & #19 (2016)