1. mid point function? 2. C Language question

 


1. Is there a mid point function like open, high, low. close?

2. Please advise regarding the following:

I am trying to learn how to write indicators. I have never written programs in C language. I could not find a "midbar" or Midpoint" function for use in an indicator. So I copied the MetaEditor Moving Average indicator code and calculated the midpoint as follows: (High[pos]+Low[pos])/2. I then replaced Close with my calculated mid point expression (ie)(High[pos]+Low[pos])/2).

Below is the original code and then my modified code. The modified code DOES NOT COMPILE SUCCESSFULLY WHEN "Close" IS REPLACED

BY (High[pos]+Low[pos]/2) IN THE STATEMENT

"sum-=Close[pos+MA_Period-1".

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

//| Simple Moving Average orignal code |

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

void sma()

{

double sum=0;

int i,pos=Bars-ExtCountedBars-1;

//---- initial accumulation

if(pos<MA_Period) pos=MA_Period;

for(i=1;i<MA_Period;i++,pos--)

sum+=Close[pos];

//---- main calculation loop

while(pos>=0)

{

sum+=Close[pos];

ExtMapBuffer[pos]=sum/MA_Period;

sum-=Close[pos+MA_Period-1];

pos--;

}

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

//| Simple Moving Average Modified by Joe Miller |

// DOES NOT COMPILE SUCCESSFULLY WHEN "Close" IS REPLACED

// BY (High[pos]+Low[pos]/2) IN THE STATEMENT

// "sum-=Close[pos+MA_Period-1

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

void sma()

{

double sum=0;

double midpt=0; //jcm

int i,pos=Bars-ExtCountedBars-1;

//---- initial accumulation

if(pos<MA_Period) pos=MA_Period;

for(i=1;i<MA_Period;i++,pos--)

sum+=(High[pos]+Low[pos])/2;

//---- main calculation loop

while(pos>=0)

{

sum+=(High[pos]+Low[pos])/2; //jcm sum+=Close[pos];

ExtMapBuffer[pos]=sum/MA_Period;

sum-=Close[pos+MA_Period-1]; //<--PROBLEM HERE

pos--;

}

 
sum-=Close[pos+MA_Period-1]; //<--PROBLEM HERE
Probably should be something like below?
sum-=(High[pos+MA_Period-1] + Low[pos+MA_Period-1]) / 2;
Reason: