Converting to Expert Advisor. Please help

 

Dear All,


I'm converting one indicator to expert advisor. The code is almost complete for BUY order. But it is not working. I'm sure, it's just a small error in the code. Please check that.


Thanks

Files:
 
gkdoda:

Dear All,


I'm converting one indicator to expert advisor. The code is almost complete for BUY order. But it is not working. I'm sure, it's just a small error in the code. Please check that.


Thanks


What error is being thrown ?


CB

 
cloudbreaker:

What error is being thrown ?




cloudbreaker
wrote
>>

What error is being thrown ?


CB

Nothing. It is not buying anything. I'm testing this by giving the statement Print (SarBuffer[0]);

It's showing 0.

Something wrong before that.

 
gkdoda:

Nothing. It is not buying anything. I'm testing this by giving the statement Print (SarBuffer[0]);

It's showing 0.

Something wrong before that.


Try implementing plenty more Print() statements, using them to checkpoint logic flow and to expose the contents of key variables.


CB

 

I've tested them. It's showing 0 in all variables. It's my first EA. I think there is mistake in basic rule of declaration of EA. Please help me.


Thanks

 
gkdoda:

I've tested them. It's showing 0 in all variables. It's my first EA. I think there is mistake in basic rule of declaration of EA. Please help me.


Thanks


The basic problem is your use of the array. You are trying to make use of an uninitialized array. Sarbuffer[] has no size set. you'll probably want to set this to the number of Bars in the chart on init, and then increase it by 1 each time you get a new bar. you're probably better off approaching this some other way though. Maybe make an indicator which is the value you're trying to get with SarBuffer and then getting that indicator's value for the current bar.


To quickly test, you can do:

double SarBuffer[1000];

(or a number greater than the number of bars you have in your chart).


you should see your print function showing you something other than 0.


You'll then want to look at the Array functions in the dictionary (in MetaEditor). You'll be using ArrayResize. I think this may not be the best way forward, but may be the most straightforward for your current code.

Reason: