Indicators Used
0
Views
0
Downloads
0
Favorites
Gann_Hi_Lo_Activator_SSL
//+------------------------------------------------------------------+
//| Gann_Hi_Lo_Activator_SSL.mq5 |
//| avoitenko |
//| https://login.mql5.com/en/users/avoitenko |
//+------------------------------------------------------------------+
#property copyright ""
#property link "https://login.mql5.com/en/users/avoitenko"
#property version "1.00"
#property description "Author: Kalenzo"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 1
//--- output line
#property indicator_label1 "Gann HL"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrDodgerBlue, clrOrangeRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//--- input parameters
input ushort InpPeriod = 13; // Period
input ENUM_MA_METHOD InpMethod = MODE_SMMA; // Method
//--- buffers
double GannBuffer[];
double ColorBuffer[];
double MaHighBuffer[];
double MaLowBuffer[];
//--- global vars
int ma_high_handle;
int ma_low_handle;
int dir[2];
int period;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- check period
period=fmax(InpPeriod,2);
//--- set buffers
SetIndexBuffer(0,GannBuffer);
SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);
SetIndexBuffer(2,MaHighBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,MaLowBuffer,INDICATOR_CALCULATIONS);
//--- set direction
ArraySetAsSeries(GannBuffer,true);
ArraySetAsSeries(ColorBuffer,true);
ArraySetAsSeries(MaHighBuffer,true);
ArraySetAsSeries(MaLowBuffer,true);
//--- get handles
ma_high_handle = iMA(_Symbol, _Period, period, 0, InpMethod, PRICE_HIGH);
ma_low_handle = iMA(_Symbol, _Period, period, 0, InpMethod, PRICE_LOW);
if(ma_high_handle==INVALID_HANDLE || ma_low_handle==INVALID_HANDLE)
{
Print("Unable to create handle for iMA");
return(-1);
}
//--- set indicator properties
string short_name=StringFormat("Gann High-Low Activator SSL (%u, %s)",period,MethodToString(InpMethod));
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set label
short_name=StringFormat("GHL (%u, %s)",period,MethodToString(InpMethod));
PlotIndexSetString(0,PLOT_LABEL,short_name);
//--- done
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
ArraySetAsSeries(close,true);
int limit;
//--- first calc
if(rates_total<prev_calculated || prev_calculated<=0)
{
limit=rates_total-period;
ArrayInitialize(GannBuffer,EMPTY_VALUE);
ArrayInitialize(ColorBuffer,0);
ArrayInitialize(MaHighBuffer,0);
ArrayInitialize(MaLowBuffer,0);
}
else limit=rates_total-prev_calculated;
//--- get MA
if(CopyBuffer(ma_high_handle,0,0,limit+1,MaHighBuffer)!=limit+1)return(0);
if(CopyBuffer(ma_low_handle,0,0,limit+1,MaLowBuffer)!=limit+1)return(0);
//--- main cycle
for(int i=limit; i>=0 && !_StopFlag; i--)
{
dir[0]=dir[1];
if(close[i] > MaHighBuffer[i+1]) dir[0] = 1;
if(close[i] < MaLowBuffer[i+1]) dir[0] = -1;
if(dir[0]==-1)
{
GannBuffer[i]=MaHighBuffer[i+1];
ColorBuffer[i]=1;
}
else
{
GannBuffer[i]=MaLowBuffer[i+1];
ColorBuffer[i]=0;
}
dir[1]=dir[0];
}
//---
return(rates_total);
}
//+------------------------------------------------------------------+
//| MethodToString |
//+------------------------------------------------------------------+
string MethodToString(ENUM_MA_METHOD method)
{
string str=EnumToString(method);
if(StringLen(str)>5) return(StringSubstr(str,5));
return("");
}
//+------------------------------------------------------------------+
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
---