question about close[] and iclose() and, declaration of value

 

Dear all

Below shown is an extract of my code. There are two questions I can't solve:

1. when I compile the program, an error message occured: ' Y ' - variable not defined (i.e. the sentense under Close Order Block). However, what I want to do is, assign 0 value to Y after close of order.

2. Close[1] always return 0 when I run the program. In fact, I really confuse with Close[] and iclose(). Sometimes one of them returns the value of close but sometimes it just returns 0. From the manual, only Close[0] and iclose(null,0,0) will return 0, but MT4 doesn't show me the same thing. Would anybody like to share with me their experience?

Thanks a lot!

+----------------------+

| entry condition |

+----------------------+

int start()

{

double Y:

double A:

if (A = 1)

{

Y = Close[1];

}

if (A =2)

{

Y = 0;

}

return;

}

+---------------+

| close order |

+---------------+

Y = 0 ;

wing

 
//+----------------------+
//| entry condition |
//+----------------------+ 
int start()
  {
//----
   double Y;
   double A;
   
   if (A == 1)
      {
      Y = Close[1];
      }
   if (A == 2)
      {
      Y = 0;
      }

//+---------------+
//| close order |
//+---------------+
   Y = 0 ;

//----
   return(0);
  }
final bracket needs to be after the final expression.
 

1005phillip

I've updated but still can't get the value of close[1]......

wing

 

Using the attached EA on a live chart:

2010.12.18 00:11:44 Close[] and iClose() USDJPY,H1: In init(): Close[0] = 83.86, Close[1] = 83.89 and Close[2] = 83.91
2010.12.18 00:12:49 Close[] and iClose() USDJPY,H1: In deinit(): Close[0] = 83.86, Close[1] = 83.89 and Close[2] = 83.91

Using the attached EA on a backtest chart:

00:13:52 Close[] and iClose(): loaded successfully
00:13:52 Close[] and iClose() started for testing
00:13:52 2010.12.17 00:00 Close[] and iClose() USDJPY,M1: In init(): Close[0] = 83.9, Close[1] = 83.89 and Close[2] = 83.94
00:13:52 2010.12.17 00:00 Close[] and iClose() USDJPY,M1: In start(): Close[0] = 83.9, Close[1] = 83.89 and Close[2] = 83.94
00:13:52 2010.12.17 00:00 Close[] and iClose() USDJPY,M1: In start(): Close[0] = 83.979, Close[1] = 83.89 and Close[2] = 83.94
00:13:52 2010.12.17 00:00 Close[] and iClose() USDJPY,M1: In start(): Close[0] = 83.968, Close[1] = 83.89 and Close[2] = 83.94
00:13:52 2010.12.17 00:00 Close[] and iClose() USDJPY,M1: In start(): Close[0] = 83.99, Close[1] = 83.89 and Close[2] = 83.94
...
00:13:52 2010.12.17 22:59 Close[] and iClose() USDJPY,M1: In start(): Close[0] = 83.87, Close[1] = 83.92 and Close[2] = 83.92
00:13:52 2010.12.17 22:59 Close[] and iClose() USDJPY,M1: In start(): Close[0] = 83.86, Close[1] = 83.92 and Close[2] = 83.92
00:13:52 2010.12.17 22:59 Close[] and iClose() USDJPY,M1: In deinit(): Close[0] = 83.86, Close[1] = 83.92 and Close[2] = 83.92

So...not sure what you are doing wrong but you can see the code in the EA, doesn't get much simpler than that.

Files:
 

  1. double Y:
    double A: 
    type Variable Semicolon
  2. double A;
    //if (A = 1){  Y = Close[1]; }
    //if (A =2){ Y = 0; }
    if (A == 1){ Y = Close[1]; }
    if (A == 2){ Y = 0; }
    Since A is never set, it is zero. Therefor Y is never set, it is zero
Reason: