Is there any technique/process or function that would import all the indicators automatically, while testing an EA?

1 View
Santiago Marshall
Answered 4 months, 1 week ago
<p id="isPasted">In most cases you can create a custom function within an EA that replicates an indicator by using buffers. I have done this numerous times for clients as it makes the EA a more robust solution when not relying on external indicators.</p><p><br></p><p>Example code:</p><p>//+------------------------------------------------------------------+</p><p>double customIndicator(int IDX, int timeFrame)</p><p>//+------------------------------------------------------------------+</p><p>{</p><p>&nbsp; &nbsp;double &nbsp; Buffer[1];</p><p>&nbsp; &nbsp;int &nbsp; &nbsp; &nbsp;buffersize=iBars(Symbol(), timeFrame);</p><p>&nbsp; &nbsp;ArrayResize(Buffer, buffersize);</p><p>&nbsp; &nbsp;ArraySetAsSeries(Buffer, true);</p><p><br></p><p>&nbsp; &nbsp;int pos=buffersize-1;</p><p>&nbsp; &nbsp;while(pos&gt;=0)</p><p>&nbsp; &nbsp;{</p><p>&nbsp; &nbsp; &nbsp; // Indicator calculations</p><p>&nbsp; &nbsp; &nbsp; Buffer[pos]=...</p><p>&nbsp; &nbsp; &nbsp; pos--;</p><p>&nbsp; &nbsp;}</p><p><br></p><p>return(buffer[IDX]);</p><p>}</p>