Indicator Feedback (VAMA)

Moderator: admin

Indicator Feedback (VAMA)

Postby gershgorin » Sun Feb 27, 2022 5:33 pm

I am currently trying to code the volume adjusted moving average as described in this article:
https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/vama.

I am getting a bit stuck trying to make sense of the numbers it's coming up with on the data window. The indicator is not complete. Right now I am trying to make sure the numbers generated make sense. I believe the issue is in how I am calculating the volume increment. However, I'm not sure.

Any help would be appreciated, and I hope I am posting this in the correct section.

Code: Select all
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Yellow

extern int Length=200;
                       
double Vol[];
double VolumeRatio[];
double PriceVolumeRatio[];
double VAMA[];


int init()
   {
      IndicatorShortName("VAMA Modfied Fidelity Formula ");
      SetIndexStyle(0,DRAW_NONE);
      SetIndexBuffer(0,Vol);
      SetIndexStyle(1,DRAW_NONE);
      SetIndexBuffer(1,VolumeRatio);
      SetIndexStyle(2,DRAW_NONE);
      SetIndexBuffer(2,PriceVolumeRatio);
      SetIndexStyle(3,DRAW_LINE);
      SetIndexBuffer(3,VAMA);
      return(0);
   }

int deinit()
  {
      return(0);
  }
 

int start()
   {
     
      int limit = Bars-1;
      int pos = limit;
      //Create Volume Array
      while(limit>=0)
      {
       Vol[limit]=iVolume(NULL,NULL,limit);
      limit--;
      }
      //Average Volume of all bars in the chart.
      double VolArraySum;
      int limitarray = ArraySize(Vol);
      while(limitarray>=0)
      {
      VolArraySum +=Vol[limitarray];
      limitarray--;
      }
      //Take average of Volume Array
      double VolumeIncrement = (VolArraySum/ArraySize(Vol))*.67;
      //Alert(VolumeIncrement);//Use to test AverageVolume

      while(pos>=0)
      {
      VolumeRatio[pos]=Vol[pos]/VolumeIncrement;
      PriceVolumeRatio[pos]=VolumeRatio[pos]*iClose(NULL,NULL,pos);
      VAMA[pos]=iMAOnArray(PriceVolumeRatio,0,Length,0,MODE_SMA,pos);
      pos--;
      }
  return(0);
   }

gershgorin
 
Posts: 3
Joined: Mon Jul 19, 2021 7:51 pm

Re: Indicator Feedback (VAMA)

Postby Apprentice » Mon Feb 28, 2022 9:56 am

Your request is added to the development list.
Development reference 126.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36476
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Indicator Feedback (VAMA)

Postby gershgorin » Mon Feb 28, 2022 11:46 pm

I would like to mention that I modified the code a bit, and I am providing this as I am learning as well. Hence it is not elegant, but written in a way so I can easily follow.

Code: Select all
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Yellow

extern int Length=200;
                       
double Vol[];
double VolumeRatio[];
double PriceVolumeRatio[];
double CumulativePriceVolumeRatio[];
double CumulativeVolumeRatio[];
double VAMA[];

int init()
   {
      IndicatorShortName("VAMA following Fidelity Formula ");
      IndicatorDigits(Digits);
      SetIndexStyle(0,DRAW_NONE);
      SetIndexBuffer(0,Vol);
      SetIndexStyle(1,DRAW_NONE);
      SetIndexBuffer(1,VolumeRatio);
      SetIndexStyle(2,DRAW_NONE);
      SetIndexBuffer(2,PriceVolumeRatio);
      SetIndexStyle(3,DRAW_NONE);
      SetIndexBuffer(3,CumulativePriceVolumeRatio);
      SetIndexStyle(4,DRAW_NONE);
      SetIndexBuffer(4,CumulativeVolumeRatio);
      SetIndexStyle(5,DRAW_NONE);
      SetIndexBuffer(5,VAMA);
      return(0);
   }

int deinit()
  {
      return(0);
  }
 

int start()
   {
      int limit=Bars-1;
      int pos = limit;
      int pos2 = pos;
     
      //Create a Volume Array across all bars.
      while(limit>=0)
      {
 
         Vol[limit]=iVolume(NULL,NULL,limit);
         limit--;
      }
     
      //Take average of Volume Array.
      double VolArraySum;
      int limitarray = ArraySize(Vol)-1;
      for(limitarray;limitarray>=0;limitarray--)
        {
        VolArraySum +=Vol[limitarray];
        }
       
      //Calculate the Volume Increment.
      double VolumeIncrement = VolArraySum/ArraySize(Vol)*.67;

      //Alert(VolumeIncrement);
      //Use to test VolumeIncrement
     
      //Calculate the VolumeRatio and Price Volume Ratio across all bars.
      while(pos>=0)
      {
      VolumeRatio[pos]=Vol[pos]/VolumeIncrement;
      PriceVolumeRatio[pos]=VolumeRatio[pos]*iClose(NULL,NULL,pos);
      pos--;
      }
      //Calculate the cumulative price volume ratio.  Calculate the Length average.
      int i;
      int j;
      for(i=0;i<=Bars-Length-1;i++)
         {
         for(j=i;j<=i+Length-1;j++)
            {
            CumulativePriceVolumeRatio[i]+=PriceVolumeRatio[j];
            }
         }
  return(0);
   }
gershgorin
 
Posts: 3
Joined: Mon Jul 19, 2021 7:51 pm


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 14 guests