BBR_Indicator

#property copyright "Copyright 2017, WIZSYS Networks Corp."
#property link "https://www.wizsys.net/"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrBlue
#property indicator_color2 clrRed
#property indicator_width1 1
#property indicator_width2 1
//--- input parameters
extern int bb_period = 34; //ボリンジャーバンドの周期
extern double bb_deviation = 2.0; //ボリンジャーバンドの偏差
extern int mo_period = 14; //モメンタムの周期
extern double mo_tyousei = 8.0; //モメンタム閾値調整
double up[];
double down[];
//  Custom indicator initialization function
int OnInit()
{
mo_tyousei*=0.01;
//--- indicator buffers mapping
SetIndexBuffer(0,up);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexLabel(0,"Up Arrow");
SetIndexBuffer(1,down);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,234);
SetIndexLabel(1,"Down Arrow");
//---
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[])
{
//---
int limit = rates_total - prev_calculated;
if(prev_calculated==0)limit--;
for(int i=0;i<limit;i++)
{
double bbH_value = iBands(_Symbol,0,bb_period,bb_deviation,0,PRICE_HIGH,MODE_UPPER,i);
double bbL_value = iBands(_Symbol,0,bb_period,bb_deviation,0,PRICE_LOW,MODE_LOWER,i);
double moH_value = iMomentum(_Symbol,0,mo_period,PRICE_HIGH,i);
double moL_value = iMomentum(_Symbol,0,mo_period,PRICE_LOW,i);
if(bbH_value < High[i] && moH_value >= 100+mo_tyousei)
down[i]=High[i];
else if(bbL_value > Low[i] && moL_value <= 100-mo_tyousei)
up[i]=Low[i];
}
//--- return value of prev_calculated for next call
return(rates_total-1);
}