Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
si_q_asi
//+------------------------------------------------------------------+
//| 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<total)
total=indBarsCount;
if(counted_bars==0)
return(total);
return(Bars - counted_bars - 1);
}
//+------------------------------------------------------------------+
//| Current Swing Index Calculation |
//+------------------------------------------------------------------+
double CurrentSI(int index)
{
Tpoints=T*MarketInfo(Symbol(),MODE_POINT);
TR=iATR(Symbol(),0,1,index);
if(Close[index+1]>=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]<Low[index])
ER=MathAbs(Low[index]-Close[index+1]);
}
K=MathMax(MathAbs(High[index]-Close[index+1]),
MathAbs(Low[index]-Close[index+1]));
SH= MathAbs(Close[index+1]-Open[index+1]);
R = TR-0.5*ER+0.25*SH;
if(R==0)
return(0);
return(50*(Close[index] - Close[index+1] + 0.5*(Close[index] - Open[index]) +
0.25*(Close[index+1]-Open[index+1]))*(K/Tpoints)/R);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int total;
int limit=GetRecalcIndex(total); // Îïðåäåëèì ïåðâûé ðàñ÷åòíûé áàð
for(int i=limit; i>=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);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---