Can anyone help with this please?

 

I hope I have posted this in the right place. I am fairly new to mql4 so this has me scratching my head


These are 3 lines of code from a much bigger program; so I show just the 3 lines that are confusing me in a simplified form 


 If I use these. The indicator does not show anything.

double Val1;

 Val1 = iMA(NULL,0,LongEMA,0,MODE_EMA,PRICE_HIGH,i);

 cross[i] = Val1;


However, if I use cross[i] = iMA(NULL,0,LongEMA,0,MODE_EMA,PRICE_HIGH,i); everything shows fine


Why does assigning the value to a variable and then assigning that to the array fail? I need to do some calculation to get the indicator I want which is why I need Val1


Cheers


TYIA


Trevor

 
TTrevor Duddle:

I hope I have posted this in the right place. I am fairly new to mql4 so this has me scratching my head


These are 3 lines of code from a much bigger program; so I show just the 3 lines that are confusing me in a simplified form 


 If I use these. The indicator does not show anything.

double Val1;

 Val1 = iMA(NULL,0,LongEMA,0,MODE_EMA,PRICE_HIGH,i);

 cross[i] = Val1;


However, if I use cross[i] = iMA(NULL,0,LongEMA,0,MODE_EMA,PRICE_HIGH,i); everything shows fine


Why does assigning the value to a variable and then assigning that to the array fail? I need to do some calculation to get the indicator I want which is why I need Val1


Cheers


TYIA


Trevor

The buffer only has one value at one bar. You have to use an array to have value for each bar.

 

Thanks for answering.


Is cross[] not an array?


cross[] is defined in the global section and I thought these 2 lines


  SetIndexBuffer(0,cross);

 SetIndexStyle(0,DRAW_LINE,STYLE_DASH,1);


set the array


Is that wrong?

 
Also, as I said if I use cross[] with the iMA function directly I get the line printed without a problem so it is clearly adding data to many points but it fails if I try to add to the array via a variable
 

It can be displayed either way without any problems as long as there are no mistakes in the program.

If it doesn't work, there must be some cause in the program, but no one can determine that from your post.
 
Trevor Duddle I Why does assigning the value to a variable and then assigning that to the array fail? 

It doesn't. Always post all relevant code (using SRC).
     How To Ask Questions The Smart Way. 2004
          Be precise and informative about your problem

We can't see your broken code.

Reason: