//+------------------------------------------------------------------+ //| SQI_v1.02.mq5 | //| SQI v1.02 Copyright 2015, fxborg | //| http://blog.livedoor.jp/fxborg/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, fxborg" #property link "http://blog.livedoor.jp/fxborg/" #property version "1.02" #include #property indicator_separate_window #property indicator_buffers 9 #property indicator_plots 1 #property indicator_type1 DRAW_COLOR_HISTOGRAM #property indicator_color1 clrRed,clrOrange,clrLime, clrGreen #property indicator_maximum 1.0 #property indicator_width1 3 //--- input int VolatPeriod=14; // Volatility Period input int VolatSmooth=2; // Volatility Smooth Period input int VolatSlowPeriod=70; // Volatility Slow Period input double VolatLv1=0.3; // Volatility Level 1 input double VolatLv2=0.5; // Volatility Level 2 int MomSmooth=3; //--- //--- double SQSigBuffer[]; double SQRawBuffer[]; double SQBuffer[]; double SQMaBuffer[]; double SQSlowBuffer[]; double SQColorBuffer[]; double MaBuffer[]; double MomMaRawBuffer[]; double MomMaBuffer[]; double DmyBuffer[]; double UpDnBuffer[]; double PriceBuffer[]; //--- //---- declaration of global variables int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- Initialization of variables of data calculation starting point min_rates_total=VolatPeriod+1+VolatSmooth+1; //--- indicator buffers mapping SetIndexBuffer(0,SQSigBuffer,INDICATOR_DATA); SetIndexBuffer(1,SQColorBuffer,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,SQBuffer,INDICATOR_DATA); SetIndexBuffer(3,UpDnBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(4,SQRawBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(5,MaBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(6,MomMaRawBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(7,MomMaBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(8,PriceBuffer,INDICATOR_CALCULATIONS); //--- set drawing line empty value PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(7,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(8,PLOT_EMPTY_VALUE,0); //--- PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total); //--- IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); string shortname="SQI v1.02"; IndicatorSetString(INDICATOR_SHORTNAME,shortname); //--- 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 i,first,begin_pos; begin_pos=min_rates_total; //--- check for bars count if(rates_total<=min_rates_total) return(0); //--- first=begin_pos; if(first+1low[i-j])dmin=low[i-j]; } double volat=0; for(int j=0;j= -under && SQBuffer[i] < -mid)SQColorBuffer[i]=1.0; else if(SQBuffer[i]>= -mid && SQBuffer[i]<=mid)SQColorBuffer[i]=2.0; else SQColorBuffer[i]=3.0; SQSigBuffer[i]=1; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double CalcUpDn(const double &o[],const double &h[],const double &l[],const double &c[],const int i) { double up= MathMax(0,(c[i]-o[i])) + (c[i]-l[i]); double dn= MathMax(0,(o[i]-c[i])) + (h[i]-c[i]); double dir=(up/MathMax(0.0000001,(up+dn))); return dir-0.5; } //+------------------------------------------------------------------+