iMAonArray needs Refresh

 

Hi guys,


I just have a simple question. I am trying to use a custom indicator in an EA.


What the custom indicator basically does is it adds 2 MAs from two variables that use iMA(), and sends that to a buffer. I then use iMAonArray() on that buffer to get another indicator as a crossover. This is what I mean:


for (i = limit;i>=0;i--){
      ma1=iMA(Symbol(),0,14,0,MODE_SMA,0,i);
      ma2=iMA(Symbol(),0,21,0,MODE_LWMA,0,i);
      diff=ma2-ma1;
   
      Buffer1[i]=diff;
      Buffer2[i]=iMAOnArray(Buffer1,limit,5,0,MODE_EMA,i);
}


The Buffer1 Line is drawn without any problems, but in order for the Buffer2 line to appear on the chart, I need to manually Refresh the chart and only after that, does the Buffer2 Line appear. What can I do to avoid this from happening, because when I use the Custom Indicator in the EA, it doesn't give any value to Buffer2 since it is not refreshed.


Is there any alternative to using iMAOnArray to get an EMA on this buffer? Or an alternative to having to refresh the charts so I can use it in my EA?


Thanks for any help you can provide

 
ccj:

Hi guys,


I just have a simple question. I am trying to use a custom indicator in an EA.


What the custom indicator basically does is it adds 2 MAs from two variables that use iMA(), and sends that to a buffer. I then use iMAonArray() on that buffer to get another indicator as a crossover. This is what I mean:



The Buffer1 Line is drawn without any problems, but in order for the Buffer2 line to appear on the chart, I need to manually Refresh the chart and only after that, does the Buffer2 Line appear. What can I do to avoid this from happening, because when I use the Custom Indicator in the EA, it doesn't give any value to Buffer2 since it is not refreshed.


Is there any alternative to using iMAOnArray to get an EMA on this buffer? Or an alternative to having to refresh the charts so I can use it in my EA?


Thanks for any help you can provide




If you use a custom indicator in an EA =====>> iCustom(..........)

Trie it out... Even compiled files .ex4 can be used that way in an EA

 
deVries:


If you use a custom indicator in an EA =====>> iCustom(..........)

Trie it out... Even compiled files .ex4 can be used that way in an EA


That is what I am currently using.


To explain myself better. The Custom Indicator (CI) draws 2 lines, Buffer1 and Buffer2; where Buffer2 is an EMA of Buffer1. When I add the CI to the chart, only Buffer1 Line appears, I have to refresh the chart in order to get Buffer2 Line. The strategy is basically a crossover strategy, and that is what I would like to code into the EA. I coded the EA using iCustom(), but the problem is that, (at least in the Strategy Tester) since when the EA is added, the chart is not "refreshed", the Buffer2 Line is never calculated, only Buffer1. Since the buy condition is that Buffer1 crosses Buffer2, and Buffer2 has no value, then no trades are taken.


So Im guessing I would have to either have a way that the EA "refreshes" the CI from inside the EA (which I dont think is possible), or calculate the EMA on Buffer1 in a different way, say for example coding the way an EMA is calculated and have it use the data from Buffer1 to calculate it. I've tried that as well, but I think I might be coding it wrong. The problem with EMA is that it needs the EMA of the prior bar, or at least the SMA of the bar prior to the first one where the EMA will be calculated in order to calculate the EMA

(EMA[current] = (Buffer1[current] - EMA[previous]) * weight + EMA[previous]).


Calculating that inital SMA is what I can't get to work.

 
ccj:

That is what I am currently using.

Why not move the iMAOnArray code into your EA, the EA can read the first buffer and calculate the second for itself . . . ?
 
RaptorUK:
Why not move the iMAOnArray code into your EA, the EA can read the first buffer and calculate the second for itself . . . ?

I will give it a try.
 

Buffer2[i]=iMAOnArray(Buffer1,limit,5,0,MODE_EMA,i);

change to :

Buffer2[i]=iMAOnArray(Buffer1,0,5,0,MODE_EMA,i);

since limit < 5 at most time, 0 means whole array.

 
DxdCn:

Buffer2[i]=iMAOnArray(Buffer1,limit,5,0,MODE_EMA,i);

change to :

Buffer2[i]=iMAOnArray(Buffer1,0,5,0,MODE_EMA,i);

since limit < 5 at most time, 0 means whole array.


Thanks for the suggestion, I tried it, but I still need to refresh the chart for the Buffer2 Line to show up.
 

try to add another for loop

for (i = limit;i>=0;i--)
Buffer2[i]=iMAOnArray(Buffer1,0,5,0,MODE_EMA,i);
 
qjol:

try to add another for loop

I tried this as well, and I still need to Refresh the chart in order for Buffer2 to be calculated.


Is there any way of coding the calculation of the EMA into the indicator to avoid using iMAOnArray()?

Reason: