Description
For those of us who use GannHilos on the chart.
This indicator simplifies your life by providing the ability to add up to 4 GannHilos of ANY timeframe onto the current chart.
Very very usefull - Enjoy !!!
using cAlgo.API;
using cAlgo.API.Indicators;
using System;
namespace cAlgo
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.FileSystem)]
public class KF_Mtf_Ghls_v4 : Indicator
{
[Parameter("G1_Enabled", DefaultValue = true, Group = "Ghl 1")]
public bool G1_Enabled { get; set; }
[Parameter("G1_Period", DefaultValue = 9, Group = "Ghl 1")]
public int G1_Period { get; set; }
[Parameter("G1_MaType", DefaultValue = MovingAverageType.TimeSeries, Group = "Ghl 1")]
public MovingAverageType G1_MaType { get; set; }
[Parameter("G1_TimeFrame", DefaultValue = "Hour4", Group = "Ghl 1")]
public TimeFrame G1_TimeFrame { get; set; }
[Parameter("G2_Enabled", DefaultValue = false, Group = "Ghl 2")]
public bool G2_Enabled { get; set; }
[Parameter("G2_Period", DefaultValue = 11, Group = "Ghl 2")]
public int G2_Period { get; set; }
[Parameter("G2_MaType", DefaultValue = MovingAverageType.Hull, Group = "Ghl 2")]
public MovingAverageType G2_MaType { get; set; }
[Parameter("G2_TimeFrame", DefaultValue = "Hour4", Group = "Ghl 2")]
public TimeFrame G2_TimeFrame { get; set; }
[Parameter("G3_Enabled", DefaultValue = true, Group = "Ghl 3")]
public bool G3_Enabled { get; set; }
[Parameter("G3_Period", DefaultValue = 9, Group = "Ghl 3")]
public int G3_Period { get; set; }
[Parameter("G3_MaType", DefaultValue = MovingAverageType.WilderSmoothing, Group = "Ghl 3")]
public MovingAverageType G3_MaType { get; set; }
[Parameter("G3_TimeFrame", DefaultValue = "Hour4", Group = "Ghl 3")]
public TimeFrame G3_TimeFrame { get; set; }
[Parameter("G4_Enabled", DefaultValue = true, Group = "Ghl 4")]
public bool G4_Enabled { get; set; }
[Parameter("G4_Period", DefaultValue = 9, Group = "Ghl 4")]
public int G4_Period { get; set; }
[Parameter("G4_MaType", DefaultValue = MovingAverageType.Weighted, Group = "Ghl 4")]
public MovingAverageType G4_MaType { get; set; }
[Parameter("G4_TimeFrame", DefaultValue = "Hour4", Group = "Ghl 4")]
public TimeFrame G4_TimeFrame { get; set; }
[Output("G1", LineColor = "Orange", Thickness = 3)]
public IndicatorDataSeries G1 { get; set; }
[Output("G2", LineColor = "Snow", Thickness = 3)]
public IndicatorDataSeries G2 { get; set; }
[Output("G3", LineColor = "Tomato", Thickness = 3)]
public IndicatorDataSeries G3 { get; set; }
[Output("G4", LineColor = "Aqua", Thickness = 3)]
public IndicatorDataSeries G4 { get; set; }
private MovingAverage _g1T, _g1B, _g2T, _g2B, _g3T, _g3B, _g4T, _g4B;
private Bars _g1, _g2, _g3, _g4;
private bool _histLoaded1, _histLoaded2, _histLoaded3, _histLoaded4;
private void SmoothOutGhl(int _idx, int idxX, Bars _gBars, IndicatorDataSeries _g)
{
int indexXX = _gBars.TimeFrame == this.Chart.TimeFrame ? _idx - 1 : _gBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[_idx - 1]);
int lastDataIndex1 = Bars.OpenTimes.GetIndexByTime(_gBars.OpenTimes[idxX]);
int lastDataIndex2 = Bars.OpenTimes.GetIndexByTime(_gBars.OpenTimes[indexXX]);
if (lastDataIndex1 == lastDataIndex2 && _gBars.TimeFrame != this.Chart.TimeFrame)
{
_g[_idx - 1] = double.NaN;
}
}
private bool LoadHistory(ref Bars g, ref MovingAverage gT, ref MovingAverage gB, int gP, MovingAverageType gM)
{
g = g.TimeFrame != this.Chart.TimeFrame ? MarketData.GetBars(g.TimeFrame) : Bars;
while (g.OpenTimes[0] > Bars.OpenTimes[0])
g.LoadMoreHistory();
gT = Indicators.MovingAverage(g.HighPrices, gP, gM);
gB = Indicators.MovingAverage(g.LowPrices, gP, gM);
return true;
}
protected override void Initialize()
{
try
{
if (this.G1_Enabled)
{
_g1 = G1_TimeFrame == Chart.TimeFrame ? Bars : MarketData.GetBars(G1_TimeFrame);
_g1T = Indicators.MovingAverage(_g1.HighPrices, G1_Period, G1_MaType);
_g1B = Indicators.MovingAverage(_g1.LowPrices, G1_Period, G1_MaType);
}
if (this.G2_Enabled)
{
_g2 = G2_TimeFrame == Chart.TimeFrame ? Bars : MarketData.GetBars(G2_TimeFrame);
_g2T = Indicators.MovingAverage(_g2.HighPrices, G2_Period, G2_MaType);
_g2B = Indicators.MovingAverage(_g2.LowPrices, G2_Period, G2_MaType);
}
if (this.G3_Enabled)
{
_g3 = G3_TimeFrame == Chart.TimeFrame ? Bars : MarketData.GetBars(G3_TimeFrame);
_g3T = Indicators.MovingAverage(_g3.HighPrices, G3_Period, G3_MaType);
_g3B = Indicators.MovingAverage(_g3.LowPrices, G3_Period, G3_MaType);
}
if (this.G4_Enabled)
{
_g4 = G4_TimeFrame == Chart.TimeFrame ? Bars : MarketData.GetBars(G4_TimeFrame);
_g4T = Indicators.MovingAverage(_g4.HighPrices, G4_Period, G4_MaType);
_g4B = Indicators.MovingAverage(_g4.LowPrices, G4_Period, G4_MaType);
}
} catch (Exception ex)
{
Print(ex);
System.IO.File.AppendAllText(ToString() + ".txt", ex.ToString());
}
}
public override void Calculate(int index)
{
try
{
if (G1_Enabled)
{
if (!_histLoaded1)
{
_histLoaded1 = this.LoadHistory(ref _g1, ref _g1T, ref _g1B, G1_Period, G1_MaType);
}
var index1 = _g1.TimeFrame == Chart.TimeFrame ? index : _g1.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
if (index1 < 1)
return;
double close = _g1.ClosePrices[index1];
double smaHigh = _g1T.Result[index1 - 1];
double smaLow = _g1B.Result[index1 - 1];
int Hld, Hlv = 0;
if (close > smaHigh)
Hld = 1;
else
{
if (close < smaLow)
Hld = -1;
else
Hld = 0;
}
if (Hld != 0)
Hlv = Hld;
if (Hlv == -1)
G1[index] = smaHigh;
else
G1[index] = smaLow;
SmoothOutGhl(index, index1, _g1, G1);
}
} catch (Exception ex)
{
Print("G1 " + ex);
System.IO.File.AppendAllText(ToString() + ".txt", "G1 " + ex.ToString());
}
try
{
if (G2_Enabled)
{
if (!_histLoaded2)
{
_histLoaded2 = this.LoadHistory(ref _g2, ref _g2T, ref _g2B, G2_Period, G2_MaType);
}
var index2 = _g2.TimeFrame == Chart.TimeFrame ? index : _g2.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
if (index2 < 1)
return;
double close = _g2.ClosePrices[index2];
double smaHigh = _g2T.Result[index2 - 1];
double smaLow = _g2B.Result[index2 - 1];
int Hld, Hlv = 0;
if (close > smaHigh)
Hld = 1;
else
{
if (close < smaLow)
Hld = -1;
else
Hld = 0;
}
if (Hld != 0)
Hlv = Hld;
if (Hlv == -1)
G2[index] = smaHigh;
else
G2[index] = smaLow;
SmoothOutGhl(index, index2, _g2, G2);
}
} catch (Exception ex)
{
Print("G2 " + ex);
System.IO.File.AppendAllText(ToString() + ".txt", "G2 " + ex.ToString());
}
try
{
if (G3_Enabled)
{
if (!_histLoaded3)
{
_histLoaded3 = this.LoadHistory(ref _g3, ref _g3T, ref _g3B, G3_Period, G3_MaType);
}
var index3 = _g3.TimeFrame == Chart.TimeFrame ? index : _g3.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
if (index3 < 1)
return;
double close = _g3.ClosePrices[index3];
double smaHigh = _g3T.Result[index3 - 1];
double smaLow = _g3B.Result[index3 - 1];
int Hld, Hlv = 0;
if (close > smaHigh)
Hld = 1;
else
{
if (close < smaLow)
Hld = -1;
else
Hld = 0;
}
if (Hld != 0)
Hlv = Hld;
if (Hlv == -1)
G3[index] = smaHigh;
else
G3[index] = smaLow;
SmoothOutGhl(index, index3, _g3, G3);
}
} catch (Exception ex)
{
Print("G3 " + ex);
System.IO.File.AppendAllText(ToString() + ".txt", "G3 " + ex.ToString());
}
try
{
if (G4_Enabled)
{
if (!_histLoaded4)
{
_histLoaded4 = this.LoadHistory(ref _g4, ref _g4T, ref _g4B, G4_Period, G4_MaType);
}
var index4 = _g4.TimeFrame == Chart.TimeFrame ? index : _g4.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
if (index4 < 1)
return;
double close = _g4.ClosePrices[index4];
double smaHigh = _g4T.Result[index4 - 1];
double smaLow = _g4B.Result[index4 - 1];
int Hld, Hlv = 0;
if (close > smaHigh)
Hld = 1;
else
{
if (close < smaLow)
Hld = -1;
else
Hld = 0;
}
if (Hld != 0)
Hlv = Hld;
if (Hlv == -1)
G4[index] = smaHigh;
else
G4[index] = smaLow;
SmoothOutGhl(index, index4, _g4, G4);
}
} catch (Exception ex)
{
Print("G4 " + ex);
System.IO.File.AppendAllText(ToString() + ".txt", "G4 " + ex.ToString());
}
}
}
}
GM
gmkenneyy
Joined on 20.03.2020 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: KF_Mtf_Ghls_v4.algo
- Rating: 0
- Installs: 570
- Modified: 08/11/2022 23:48
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
No comments found.