Skip to content

Instantly share code, notes, and snippets.

@sin32775
Created December 21, 2020 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sin32775/833cb2c70fe791ced6b6a39bbf78a933 to your computer and use it in GitHub Desktop.
Save sin32775/833cb2c70fe791ced6b6a39bbf78a933 to your computer and use it in GitHub Desktop.
//+------------------------------------------------------------------+
//| RSI1st.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_separate_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDodgerBlue
#property indicator_width1 2
#property indicator_style1 STYLE_SOLID
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrGreen
#property indicator_width2 2
#property indicator_style2 STYLE_SOLID
input int RSI_Period=14; //RSI期間
input int MA_Period=9; //移動平均線の期間
input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // 平滑化の方法
input ENUM_APPLIED_PRICE InpMAApply=PRICE_CLOSE;//適用価格
double RSI_Buffer[];
double MA_Buffer[];
int hRSI;
int hRSIMA;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,RSI_Buffer,INDICATOR_DATA);
SetIndexBuffer(1,MA_Buffer,INDICATOR_DATA);
IndicatorSetString(INDICATOR_SHORTNAME,"RSI1st("+(string)RSI_Period+","+(string)MA_Period+")");
PlotIndexSetString(0,PLOT_LABEL,"RSI("+string(RSI_Period)+")");
PlotIndexSetString(1,PLOT_LABEL,"RSI 移動平均線("+string(RSI_Period)+","+string(MA_Period)+")");
IndicatorSetInteger(INDICATOR_DIGITS,2);
hRSI=iRSI(NULL,0,RSI_Period,InpMAApply);
hRSIMA=iMA(NULL,0,MA_Period,0,InpMAMethod,hRSI);
//---
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(hRSI)<rates_total && BarsCalculated(hRSIMA)<rates_total)
return(0);
int to_copy;
to_copy=rates_total-prev_calculated;
if(to_copy==0)
to_copy++;
if(CopyBuffer(hRSI,0,0,to_copy,RSI_Buffer)<=0)
return(0);
if(CopyBuffer(hRSIMA,0,0,to_copy,MA_Buffer)<=0)
return (0);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//|ハンドルの開放 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
IndicatorRelease(hRSI);
IndicatorRelease(hRSIMA);
}
//+------------------------------------------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment