//+------------------------------------------------------------------+ //| si_q_asi.mq4 | //| Copyright 2016, Evbut | //+------------------------------------------------------------------+ #property copyright "Copyright © 2016, Evbut" #property description "Краткосрочный и Аккумулятивный Индексы колебания цены. \nCurrent and Accumulative Swing Index" #property strict //---- #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 DarkBlue //Сolor Line SwingIndex #property indicator_color2 Green //Color Line AccumelativeIndex #property indicator_color3 Blue //Color Positive data #property indicator_color4 Red //Color Nagative data #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 2 #property indicator_width4 2 #property indicator_level1 0.0 #property indicator_levelcolor Black //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_CHOIS { SwingIndex, //Краткросрочный индекс / Current Index AccumulativeIndex //Накопительный индекс / Accumulative Index }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ enum ENUM_CHOIS1 { Histogramm, // Гистограмма / Histogramm Line // Линия / Line }; //---- input parameters input ENUM_CHOIS IndexType = SwingIndex; //Тип индекса / Index Type input ENUM_CHOIS1 Display_mode = Line; //Вид отображения / Display Mode extern int indBarsCount = 500; //Количество баров отображения / The number of bars to display //---- buffers double SIBuffer[]; //SwingIndex Buffer double ASIBuff[]; //Accumulative Buffer double Positive[], Negative[]; //Histogramm Buffers string short_name; //---- Global variables double T=5000.0; double R,K,TR,ER,SH,Tpoints; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(4); SetIndexBuffer(0,SIBuffer); SetIndexLabel(0,"Current Swing Index"); SetIndexBuffer(1,ASIBuff); SetIndexLabel(1,"Accumulative Swing Index"); SetIndexBuffer(2,Positive); SetIndexBuffer(3,Negative); if(IndexType==SwingIndex) { SetIndexLabel(2,"Current Swing Index"); SetIndexLabel(3,"Current Swing Index"); } else { SetIndexLabel(2,"Accumulative Swing Index"); SetIndexLabel(3,"Accumulative Swing Index"); } switch(Display_mode) { case Line: if(IndexType==AccumulativeIndex) { SetIndexStyle(0,DRAW_NONE); SetIndexStyle(1,DRAW_LINE); SetIndexStyle(2,DRAW_NONE); SetIndexStyle(3,DRAW_NONE); SetIndexEmptyValue(1,0.0); } else { SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_NONE); SetIndexStyle(2,DRAW_NONE); SetIndexStyle(3,DRAW_NONE); } break; case Histogramm: if(IndexType==AccumulativeIndex) { SetIndexStyle(0,DRAW_NONE); SetIndexStyle(1,DRAW_LINE); SetIndexStyle(2,DRAW_NONE); SetIndexStyle(3,DRAW_NONE); SetIndexEmptyValue(1,0.0); } else { SetIndexStyle(0,DRAW_NONE); SetIndexStyle(1,DRAW_NONE); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexStyle(3,DRAW_HISTOGRAM); } break; } if(IndexType== SwingIndex) short_name="CSI ("+IntegerToString(Period(),0)+")"; else short_name="ASI ("+IntegerToString(Period(),0)+")"; IndicatorShortName(short_name); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- return(0); } //+-------------------------------------------------------------------+ //| Determination of bar index which needed to recalculate | //+-------------------------------------------------------------------+ int GetRecalcIndex(int &total) { int counted_bars=IndicatorCounted(); total=Bars-1; if(indBarsCount>0 || indBarsCount=Low[index] && Close[index+1]<=High[index]) ER=0; else { if(Close[index+1]>High[index]) ER=MathAbs(High[index]-Close[index+1]); if(Close[index+1]=0; i--) { SIBuffer[i]=CurrentSI(i); if(IndexType==AccumulativeIndex) ASIBuff[i]=ASIBuff[i+1]+SIBuffer[i]; //----- For Histogramm mode ----- double current=SIBuffer[i]; if(current>0) { Positive[i]=current; Negative[i]=0.0; } else { Positive[i]=0.0; Negative[i]=current; } } //---- return(0); } //+------------------------------------------------------------------+