Created
December 21, 2020 08:33
-
-
Save sin32775/dd47764322f2d3ae9c00632d44c9a630 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+------------------------------------------------------------------+ | |
//| MA1st.mq5 | | |
//| Copyright 2020, Beleif Co., Ltd. | | |
//| https://belief-hf.com/ | | |
//+------------------------------------------------------------------+ | |
#property copyright "Copyright 2020, Beleif Co., Ltd." | |
#property link "https://belief-hf.com/" | |
#property version "1.00" | |
#property indicator_chart_window | |
#property indicator_buffers 1 | |
#property indicator_plots 1 | |
#property indicator_type1 DRAW_LINE | |
#property indicator_color1 clrDeepPink | |
#property indicator_width1 2 | |
#property indicator_style1 STYLE_DOT | |
input ENUM_MA_METHOD InpMAMethod=MODE_SMA;//移動平均線の種類 | |
input ENUM_APPLIED_PRICE InpMAApply=PRICE_CLOSE;//適用価格 | |
input int InpMaPeriod=20;//期間 | |
double MABuffer[]; | |
int hMA; | |
//+------------------------------------------------------------------+ | |
//| Custom indicator initialization function | | |
//+------------------------------------------------------------------+ | |
int OnInit() | |
{ | |
if(InpMaPeriod<1) | |
{ | |
Print("Error Invalid InpMaPeriod value"); | |
return(INIT_FAILED); | |
} | |
//--- indicator buffers mapping | |
SetIndexBuffer(0,MABuffer,INDICATOR_DATA); | |
IndicatorSetString(INDICATOR_SHORTNAME,"はじめての移動平均"); | |
PlotIndexSetString(0,PLOT_LABEL,"MA1st("+string(InpMaPeriod)+")"); | |
hMA=iMA(NULL,0,InpMaPeriod,0,InpMAMethod,InpMAApply); | |
if(hMA==INVALID_HANDLE) | |
{ | |
Print("Error INVALID_HANDLE"); | |
return(INIT_FAILED); | |
} | |
//--- | |
return(INIT_SUCCEEDED); | |
} | |
//+------------------------------------------------------------------+ | |
//| Custom indicator iteration function | | |
//+------------------------------------------------------------------+ | |
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[]) | |
{ | |
//--- | |
if(BarsCalculated(hMA)<rates_total) | |
return(0); | |
int to_copy; | |
to_copy=rates_total-prev_calculated; | |
if(to_copy==0) | |
to_copy++; | |
if(CopyBuffer(hMA,0,0,to_copy,MABuffer)<=0) | |
return(0); | |
// Print(rates_total,",",prev_calculated); | |
//--- return value of prev_calculated for next call | |
return(rates_total); | |
} | |
//+------------------------------------------------------------------+ | |
//|ハンドルの開放 | | |
//+------------------------------------------------------------------+ | |
void OnDeinit(const int reason) | |
{ | |
IndicatorRelease(hMA); | |
} | |
//+------------------------------------------------------------------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment