Translate indicator parameters to EA. PVT setup.

 

Hello guys, this is my first post here, what motivated me was to spend the fourth overnight in a row trying to translate a PVT  (price volume trend) indicator to an EA strategy. When the pvt crosses a moving average up or down.

The indicator I downloaded to be able to get the calculation base was from Metaquotes: https://www.mql5.com/en/code/45 and it goes like this:

int OnCalculate(const int rates_total,const int prev_calculated,
                const datetime &Time[],
                const double &Open[],
                const double &High[],
                const double &Low[],
                const double &Close[],
                const long &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
//--- variables
   int pos;
//--- check for bars count
   if(rates_total<2)
      return(0);
//--- start calculation
   pos=prev_calculated-1;
//--- correct position, when it's first iteration
   if(pos<0)
     {
      pos=1;
      ExtPVTBuffer[0]=0.0;
     }
//--- main cycle
   if(InpVolumeType==VOLUME_TICK)
      CalculatePVT(pos,rates_total,Close,TickVolume);
   else
      CalculatePVT(pos,rates_total,Close,Volume);
//---- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Calculate PVT by volume argument                                 |
//+------------------------------------------------------------------+
void CalculatePVT(int nPosition,
                  int nRatesCount,
                  const double &ClBuffer[],
                  const long &VolBuffer[])
  {
   if(nPosition<=0) nPosition=1;
//---
   for(int i=nPosition;i<nRatesCount && !IsStopped();i++)
     {
      //--- get some data
      double PrevClose=ClBuffer[i-1];
      //--- calculate PVT value
      if(PrevClose!=0)
         ExtPVTBuffer[i]=((ClBuffer[i]-PrevClose)/PrevClose)*VolBuffer[i]+ExtPVTBuffer[i-1];
      else ExtPVTBuffer[i]=ExtPVTBuffer[i-1];
     }

And I'm having trouble translating the call from Oncalculate, which has the rates_total and prev_calculated parameters. Because in the EA we cannot call this function.

int OnCalculate(const int rates_total,const int prev_calculated,
                const datetime &Time[],
                const double &Open[],
                const double &High[],
                const double &Low[],
                const double &Close[],
                const long &TickVolume[],
                const long &Volume[],
                const int &Spread[])

Hence the idea is to look for a way to translate this code so that the EA runs, and I saw that there is a workaround using iBars for rates_total, which then pulls the number of bars for the period you stipulate. but it was the most I managed to develop =(



I've been programming EAs for 4 months and the learning here is being almost literally based on trial and error, and this is the first time I ask for help here, because I believe that I lack a simple detail that is not yet part of my knowledge.
Cheers!

Price and Volume Trend (PVT)
Price and Volume Trend (PVT)
  • www.mql5.com
Price and Volume Trend (PVT) indicator, like On Balance Volume (OBV), represents the cumulative sum of trade volumes calculated considering close price changes. The calculation algorithm is close to that of the indicator OBV. But in OBV we add the whole daily volume to the current indicator value when close prices are higher, and detract the...