I have created an Indicator using MQL5.
After Profiling, the program I read that 99% of my CPU is used by my OnCalculate()
.
Here is my function:
int OnCalculate( const int rates_total,
const int prev_calculated,
const int begin,
const double &price[]
)
{
//--- check for bars count
float tempprice[];
ArrayResize( tempprice, ArraySize( price ) );
if ( rates_total < InpMAPeriod - 1 + begin ) return( 0 ); // not enough bars for calculation
//--- first calculation or number of bars was changed
if ( prev_calculated == 0 ) ArrayInitialize( ExtLineBuffer, 0 );
ArrayCopy( tempprice, price );
//--- sets first bar from what index will be draw
PlotIndexSetInteger( 0, PLOT_DRAW_BEGIN, InpMAPeriod - 1 + begin );
switch( InpMAMethod )
{
case MODE_EMA: Execute_Me( price,
"CalculateEMA",
rates_total,
prev_calculated,
begin
);
break;
case MODE_LWMA: Execute_Me( price,
"CalculateLWMA",
rates_total,
prev_calculated,
begin
);
break;
case MODE_SMMA: Execute_Me( price,
"CalculateSmoothedMA",
rates_total,
prev_calculated,
begin
);
break;
case MODE_SMA: Execute_Me( price,
"CalculateSimpleMA",
rates_total,
prev_calculated,
begin
);
break;
}
return( rates_total );
}
Here is the result of profiling:
Kindly, let me know, how I can make the OnCalculate()
work on GPU instead of CPU.