定番になってきたMTFシリーズ、今回はCCIです。
これまでと同様にコードの説明はRSIのほうを参照してください。
ソースコード
#property copyright "© shanch, 2020"
#property link "shanch2@gmail.com"
#property description "MTFCCI"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrLightSeaGreen
#property indicator_width1 1
#property indicator_style1 STYLE_SOLID
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1;
int hCCI;
double BufCCI[];
double BufTemp[];
int OnInit()
{
SetIndexBuffer(0, BufCCI, INDICATOR_DATA);
ArraySetAsSeries(BufCCI, true);
ArraySetAsSeries(BufTemp, true);
IndicatorSetInteger(INDICATOR_LEVELS,3);
IndicatorSetDouble(INDICATOR_LEVELVALUE,0,100);
IndicatorSetDouble(INDICATOR_LEVELVALUE,1,-100);
IndicatorSetDouble(INDICATOR_LEVELVALUE,2,200);
IndicatorSetDouble(INDICATOR_LEVELVALUE,3,-200);
IndicatorSetDouble(INDICATOR_MINIMUM,-300);
IndicatorSetDouble(INDICATOR_MAXIMUM,300);
hCCI = iCCI(NULL, TimeFrame, 14, PRICE_TYPICAL);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) { IndicatorRelease(hCCI);}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
ArraySetAsSeries(time,true);
int limit = rates_total - prev_calculated;
if(limit == 0) limit= 1;
int shift = 0;
for(int i=0; i<limit; i++)
{
shift=iBarShift(_Symbol,TimeFrame,time[i]);
if(CopyBuffer(hCCI, 0, shift, 1, BufTemp) <= 0)
{
Print("Getting CCI failed! Error",GetLastError());
return(0);
}
else
{
BufCCI[i]=BufTemp[0];
}
}
for(int i=1; i<rates_total; i++)
{
if(iBarShift(NULL, TimeFrame, time[i]) > 0)
{
break;
}
BufCCI[i]=BufCCI[0];
}
return(rates_total);
}