using iOpen in an indicator?

 

This indicator is supposed to show the open and close of the EURUSD in absolute value over the last hour.  When it is run it just draws a flat line, which should never be the case.  Anybody know where I went wrong?

 
//--------------------------------------------------------------------
#property indicator_separate_window    // Indicator is drawn in a seperate window
#property indicator_buffers 1       // Number of buffers
#property indicator_color1 Blue     // Color of the USD line
 
extern int LookBack=60;
double USD[];             // Declaring arrays (for indicator buffers)
//--------------------------------------------------------------------
 
 
int init()                          // Special function init()
  {
   SetIndexBuffer(0,USD);         // Assigning an array to a buffer
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1);// Line style
   return;                          // Exit the special funct. init()
  }
//--------------------------------------------------------------------
 
 
int start()                         // Special function start()
{
int i, Counted_bars;
 
Counted_bars=IndicatorCounted(); // Number of counted bars
for(i=Bars-Counted_bars-1-LookBack;i>=0;i--) // Index of the first uncounted
{
 
   //Get USD Value
   USD[i]=iClose("EURUSD",PERIOD_M1,i)-iOpen("EURUSD",PERIOD_M1,i+LookBack)
   
}
 
return;                          // Exit the special funct. start()
}
 

1. missing semicolon ";" on line:

USD[i]=iClose("EURUSD",PERIOD_M1,i)-iOpen("EURUSD",PERIOD_M1,i+LookBack)

2. BTW, start(),init() are typed functions. typed functions return typed value - return(aValue);

it then plots...

 

excuse me, I not say that I copy above code > add ";" > compile > run > it plot OK and NOT flat anywhere...

 

Counted_bars=IndicatorCounted(); // Number of counted bars

Comment("Bars to process = ", Bars-Counted_bars-1-LookBack); // add this line

if(Bars-Counted_bars-1-LookBack < 0) Alert("This isn't processing anything"); // add this line
for(i=Bars-Counted_bars-1-LookBack;i>=0;i--) // Index of the first uncounted
{

 
phy:

Counted_bars=IndicatorCounted(); // Number of counted bars

Comment("Bars to process = ", Bars-Counted_bars-1-LookBack); // add this line

if(Bars-Counted_bars-1-LookBack < 0) Alert("This isn't processing anything"); // add this line
for(i=Bars-Counted_bars-1-LookBack;i>=0;i--) // Index of the first uncounted
{

OK.
Changed it to the following:

CountedBars=IndicatorCounted();           // Number of counted bars
Print("Bars to process = ",CountedBars-1);
if(CountedBars-LookBack-1 < 0) Alert("This isn't processing anything");
for(i=CountedBars-LookBack-1;i>=0;i--)    // Index of the first uncounted

The lines move up and down now.  But they are still totally flat.  The seem to move based on the most recent calculation of:

iClose("EURUSD",PERIOD_M1,i)-iOpen("EURUSD",PERIOD_M1,i+LookBack)

in other words:

iClose("EURUSD",PERIOD_M1,0)-iOpen("EURUSD",PERIOD_M1,59)

For example, right now the value=0.0073, and the line equals 0.0073 for the whole chart, no matter how far back I scroll.

 

Well...

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow

extern int LookBack=60;
double USD[];

int init()
  {
   SetIndexBuffer(0,USD);
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1);
   return(0);
  }

int start()
    {
    for(int i = Bars-IndicatorCounted(); i >= 0; i--)
        {
       USD[i]=iClose(Symbol(),PERIOD_M1,i)-iOpen(Symbol(),PERIOD_M1,i+LookBack);   
        } 
    return(0);
}
 
phy:

Well...

thanks, Phy

Reason: