Description
Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them. There's also a Discord Server now @ https://discord.gg/5GAPMtp
This is a conversion for the Ergodic CCI indicator
UPDATE:Added RSI
For any bug report or suggestion, contact me by joining the group linked above or by commenting below
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class ErgodicCCI : Indicator
{
[Parameter("First Smoothing", Group = "Ergodic CCI", DefaultValue = 2)]
public int pq { get; set; }
[Parameter("Second Smoothing", Group = "Ergodic CCI", DefaultValue = 10)]
public int pr { get; set; }
[Parameter("Third Smoothing", Group = "Ergodic CCI", DefaultValue = 5)]
public int ps { get; set; }
[Parameter("Signal", Group = "Ergodic CCI", DefaultValue = 8)]
public int trigger { get; set; }
[Parameter("Period RSI", Group = "RSI", DefaultValue = 14)]
public int rsiPer { get; set; }
[Parameter("Show RSI", Group = "RSI", DefaultValue = true)]
public bool showRSI { get; set; }
[Output("CCI", LineColor = "RoyalBlue")]
public IndicatorDataSeries CCI { get; set; }
[Output("Trigger", LineColor = "Yellow")]
public IndicatorDataSeries signal { get; set; }
[Output("RSI", LineColor = "AcquaMarine", Thickness = 2)]
public IndicatorDataSeries RSI { get; set; }
private IndicatorDataSeries mtm, absmtm;
private ExponentialMovingAverage emaMTM, emaABS, emaEMAMTM, emaEMAEMAMTM, emaEMAABS, emaEMAEMAABS, emaSignal;
private RelativeStrengthIndex rsi;
protected override void Initialize()
{
mtm = CreateDataSeries();
absmtm = CreateDataSeries();
emaMTM = Indicators.ExponentialMovingAverage(mtm, pq);
emaEMAMTM = Indicators.ExponentialMovingAverage(emaMTM.Result, pr);
emaEMAEMAMTM = Indicators.ExponentialMovingAverage(emaEMAMTM.Result, ps);
emaABS = Indicators.ExponentialMovingAverage(absmtm, pq);
emaEMAABS = Indicators.ExponentialMovingAverage(emaABS.Result, pr);
emaEMAEMAABS = Indicators.ExponentialMovingAverage(emaEMAABS.Result, ps);
emaSignal = Indicators.ExponentialMovingAverage(CCI, trigger);
rsi = Indicators.RelativeStrengthIndex(CCI, rsiPer);
Chart.ScrollChanged += OnChartScrollChanged;
}
void OnChartScrollChanged(ChartScrollEventArgs obj)
{
if (showRSI)
if (IsLastBar)
calcRSI();
}
public override void Calculate(int index)
{
for (int i = 0; i <= index; i++)
{
mtm[i] = MarketSeries.Close[i] - MarketSeries.Close[i - 1];
absmtm[i] = Math.Abs(mtm[i]);
}
CCI[index] = 500 * emaEMAEMAMTM.Result[index] / emaEMAEMAABS.Result[index];
signal[index] = emaSignal.Result[index];
if (showRSI)
if (IsLastBar)
calcRSI();
}
public void calcRSI()
{
int startInd = Chart.FirstVisibleBarIndex;
int endIndex = Chart.LastVisibleBarIndex;
double max = 0, min = double.PositiveInfinity;
for (int k = startInd; k <= endIndex; k++)
{
max = Math.Max(max, CCI[k]);
min = Math.Min(min, CCI[k]);
}
for (int k = startInd; k <= endIndex; k++)
{
RSI[k] = (max - min) * (rsi.Result[k] - 50) / 100;
}
IndicatorArea.DrawHorizontalLine("85", (max - min) * (85 - 50) / 100, Color.DarkRed);
IndicatorArea.DrawHorizontalLine("15", (max - min) * (15 - 50) / 100, Color.Green);
}
}
}
CY
cysecsbin.01
Joined on 10.11.2018 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Ergodic CCI.algo
- Rating: 5
- Installs: 1720
- Modified: 13/10/2021 09:54
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.
Having went through your post and territorial io discovered that it is packed with information. Keep up the excellent work of publishing information that is so helpful to those who are looking for it.