我使用 MQL5 创建了一个指标。
分析后,我读到的程序 99% 的 CPU 被我的OnCalculate()
.
这是我的功能:
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 );
}
请告诉我,我如何OnCalculate()
在 GPU 而不是 CPU 上进行工作。