indicator has stopped working
indicator has stopped working
19 May 2022, 09:29
Am disappointed, extremely!
i have been using ctrader for quite a long time now, the only reason i use ctrader is because of the indicators, unfortunately almost all previous ctrader indicators or rather the old indicators seem not to be working on the latest Ctrader update 4.2.2 version. below is the indicator
i have also installed .Net 6.0 and changed compiler
after recompiling the file am still getting errors,
the indicator is not showing on the chart anymore, so am wondering do i have to open a forum for each one of those indicator?
using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator("Support and Resistance At Price", IsOverlay = true, AccessRights = AccessRights.None)]
public class SRAtPrice : Indicator
{
private double extremeHigh = 0;
private double extremeLow = 0;
private double dayHi = 0;
private double dayLo = 0;
private SortedList<double, int> prices = new SortedList<double, int>();
private IList<Zone> zones = new List<Zone>();
private const string ExtremeHighName = "ExtremeHigh";
private const string ExtremeLowName = "ExtremeLow";
private const string DayHighName = "DayHigh";
private const string DayLowName = "DayLow";
[Parameter("Periods", DefaultValue = 100)]
public int Periods { get; set; }
[Parameter("Show Extreme H/L", DefaultValue = true)]
public bool ShowExtremeHL { get; set; }
[Parameter("Show Day H/L", DefaultValue = true)]
public bool ShowDayHL { get; set; }
[Parameter("Required Hits", DefaultValue = 0)]
public int RequiredHits { get; set; }
[Parameter("Zone Size", DefaultValue = 2)]
public int ZoneSize { get; set; }
[Parameter("Max Lines In Zone", DefaultValue = 1)]
public int MaxLinesInZone { get; set; }
[Output("Extreme H/L Style", Color = Colors.Red, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries ExtremeHLStyle { get; set; }
[Output("Day H/L Style", Color = Colors.Blue, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries DayHLStyle { get; set; }
[Output("S/R Style", Color = Colors.Orange, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries SRStyle { get; set; }
public override void Calculate(int index)
{
if (this.IsLastBar)
{
var currentOpenDate = this.MarketSeries.OpenTime[index].Date;
var earliest = index - this.Periods;
for (var i = index; i >= earliest; i--)
{
if (i >= 0)
{
var high = this.MarketSeries.High[i];
var nextHigh = this.MarketSeries.High[i + 1];
var low = this.MarketSeries.Low[i];
var nextLow = this.MarketSeries.Low[i + 1];
this.extremeHigh = Math.Max(high, this.extremeHigh);
this.extremeLow = this.extremeLow == 0 ? low : Math.Min(low, this.extremeLow);
if (this.TimeFrame < TimeFrame.Minute)
{
if (this.MarketSeries.OpenTime[i].Date == currentOpenDate)
{
this.dayHi = Math.Max(high, this.dayHi);
this.dayLo = this.dayLo == 0 ? low : Math.Min(low, this.dayLo);
}
}
if (nextHigh <= high)
{
this.AddOrUpdatePrice(high);
}
if (nextLow >= low)
{
this.AddOrUpdatePrice(low);
}
}
else
{
break;
}
}
this.zones.Clear();
var rangePipSize = (this.Symbol.PipSize * (double)this.ZoneSize);
for (var i = this.extremeLow + rangePipSize; i < this.extremeHigh - rangePipSize; i += rangePipSize + this.Symbol.PipSize)
{
this.zones.Add(new Zone
{
Start = i,
End = i + rangePipSize,
LinesRendered = 0
});
}
this.ChartObjects.RemoveAllObjects();
foreach (var price in this.prices.Keys)
{
this.RenderSRIfRequred(price, this.prices[price]);
}
if (this.ShowExtremeHL)
{
this.DrawExtremeHigh();
this.DrawExtremeLow();
}
if (this.TimeFrame < TimeFrame.Minute && this.ShowDayHL)
{
this.DrawDayHigh();
this.DrawDayLow();
}
}
}
private void RenderSRIfRequred(double price, int count)
{
if (count < this.RequiredHits)
{
return;
}
foreach (var range in this.zones)
{
if (price >= range.Start && price <= range.End)
{
if (range.LinesRendered != this.MaxLinesInZone)
{
range.LinesRendered++;
this.DrawSR(price);
}
return;
}
}
}
private void AddOrUpdatePrice(double priceValue)
{
if (this.prices.ContainsKey(priceValue))
{
this.prices[priceValue]++;
}
else
{
this.prices.Add(priceValue, 1);
}
}
private void DrawExtremeHigh()
{
this.DrawExtreme(ExtremeHighName, this.extremeHigh);
}
private void DrawExtremeLow()
{
this.DrawExtreme(ExtremeLowName, this.extremeLow);
}
private void DrawDayHigh()
{
this.DrawDay(DayHighName, this.dayHi);
}
private void DrawDayLow()
{
this.DrawDay(DayLowName, this.dayLo);
}
private void DrawExtreme(string name, double level)
{
var attribute = this.GetAttributeFrom<OutputAttribute>("ExtremeHLStyle");
this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle);
}
private void DrawDay(string name, double level)
{
var attribute = this.GetAttributeFrom<OutputAttribute>("DayHLStyle");
this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle);
}
private void DrawSR(double level)
{
var attribute = this.GetAttributeFrom<OutputAttribute>("SRStyle");
this.ChartObjects.DrawHorizontalLine(string.Format("SR {0}", level), level, attribute.Color, attribute.Thickness, attribute.LineStyle);
}
private T GetAttributeFrom<T>(string propertyName)
{
var attrType = typeof(T);
var property = this.GetType().GetProperty(propertyName);
return (T)property.GetCustomAttributes(attrType, false).GetValue(0);
}
private class Price
{
internal double Value { get; set; }
internal int Count { get; set; }
}
private class Zone
{
internal double Start { get; set; }
internal double End { get; set; }
internal int LinesRendered { get; set; }
}
}
}
Replies
dokinya
19 May 2022, 14:12
RE: downgrade
amusleh said:
Hi,
We were able to reproduce the issue with your indicator, we are investigating now what's causing it, please be patient and wait for our reply.
is there anyway i can downgrade the platform?
amusleh
19 May 2022, 14:45
RE: RE: downgrade
dokinya said:
amusleh said:
Hi,
We were able to reproduce the issue with your indicator, we are investigating now what's causing it, please be patient and wait for our reply.
is there anyway i can downgrade the platform?
Hi,
There is no way to downgrade, for this particular indicator you can comment the "this.ChartObjects.RemoveAllObjects();" line and it will work on version 4.2.
@amusleh
dokinya
19 May 2022, 19:10
( Updated at: 21 Dec 2023, 09:22 )
RE: RE: RE: downgrade
amusleh said:
dokinya said:
amusleh said:
Hi,
We were able to reproduce the issue with your indicator, we are investigating now what's causing it, please be patient and wait for our reply.
is there anyway i can downgrade the platform?
Hi,
There is no way to downgrade, for this particular indicator you can comment the "this.ChartObjects.RemoveAllObjects();" line and it will work on version 4.2.
isn't this the same thing already on the indicator or where am i supposed to comment that?
amusleh
20 May 2022, 08:02
Hi,
By commenting I mean remove that line of code by making it a comment, ex:
using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator("Support and Resistance At Price", IsOverlay = true, AccessRights = AccessRights.None)]
public class SRAtPrice : Indicator
{
private double extremeHigh = 0;
private double extremeLow = 0;
private double dayHi = 0;
private double dayLo = 0;
private SortedList<double, int> prices = new SortedList<double, int>();
private IList<Zone> zones = new List<Zone>();
private const string ExtremeHighName = "ExtremeHigh";
private const string ExtremeLowName = "ExtremeLow";
private const string DayHighName = "DayHigh";
private const string DayLowName = "DayLow";
[Parameter("Periods", DefaultValue = 100)]
public int Periods { get; set; }
[Parameter("Show Extreme H/L", DefaultValue = true)]
public bool ShowExtremeHL { get; set; }
[Parameter("Show Day H/L", DefaultValue = true)]
public bool ShowDayHL { get; set; }
[Parameter("Required Hits", DefaultValue = 0)]
public int RequiredHits { get; set; }
[Parameter("Zone Size", DefaultValue = 2)]
public int ZoneSize { get; set; }
[Parameter("Max Lines In Zone", DefaultValue = 1)]
public int MaxLinesInZone { get; set; }
[Output("Extreme H/L Style", Color = Colors.Red, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries ExtremeHLStyle { get; set; }
[Output("Day H/L Style", Color = Colors.Blue, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries DayHLStyle { get; set; }
[Output("S/R Style", Color = Colors.Orange, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries SRStyle { get; set; }
public override void Calculate(int index)
{
if (this.IsLastBar)
{
var currentOpenDate = this.MarketSeries.OpenTime[index].Date;
var earliest = index - this.Periods;
for (var i = index; i >= earliest; i--)
{
if (i >= 0)
{
var high = this.MarketSeries.High[i];
var nextHigh = this.MarketSeries.High[i + 1];
var low = this.MarketSeries.Low[i];
var nextLow = this.MarketSeries.Low[i + 1];
this.extremeHigh = Math.Max(high, this.extremeHigh);
this.extremeLow = this.extremeLow == 0 ? low : Math.Min(low, this.extremeLow);
if (this.TimeFrame < TimeFrame.Minute)
{
if (this.MarketSeries.OpenTime[i].Date == currentOpenDate)
{
this.dayHi = Math.Max(high, this.dayHi);
this.dayLo = this.dayLo == 0 ? low : Math.Min(low, this.dayLo);
}
}
if (nextHigh <= high)
{
this.AddOrUpdatePrice(high);
}
if (nextLow >= low)
{
this.AddOrUpdatePrice(low);
}
}
else
{
break;
}
}
this.zones.Clear();
var rangePipSize = (this.Symbol.PipSize * (double)this.ZoneSize);
for (var i = this.extremeLow + rangePipSize; i < this.extremeHigh - rangePipSize; i += rangePipSize + this.Symbol.PipSize)
{
this.zones.Add(new Zone
{
Start = i,
End = i + rangePipSize,
LinesRendered = 0
});
}
//this.ChartObjects.RemoveAllObjects();
foreach (var price in this.prices.Keys)
{
this.RenderSRIfRequred(price, this.prices[price]);
}
if (this.ShowExtremeHL)
{
this.DrawExtremeHigh();
this.DrawExtremeLow();
}
if (this.TimeFrame < TimeFrame.Minute && this.ShowDayHL)
{
this.DrawDayHigh();
this.DrawDayLow();
}
}
}
private void RenderSRIfRequred(double price, int count)
{
if (count < this.RequiredHits)
{
return;
}
foreach (var range in this.zones)
{
if (price >= range.Start && price <= range.End)
{
if (range.LinesRendered != this.MaxLinesInZone)
{
range.LinesRendered++;
this.DrawSR(price);
}
return;
}
}
}
private void AddOrUpdatePrice(double priceValue)
{
if (this.prices.ContainsKey(priceValue))
{
this.prices[priceValue]++;
}
else
{
this.prices.Add(priceValue, 1);
}
}
private void DrawExtremeHigh()
{
this.DrawExtreme(ExtremeHighName, this.extremeHigh);
}
private void DrawExtremeLow()
{
this.DrawExtreme(ExtremeLowName, this.extremeLow);
}
private void DrawDayHigh()
{
this.DrawDay(DayHighName, this.dayHi);
}
private void DrawDayLow()
{
this.DrawDay(DayLowName, this.dayLo);
}
private void DrawExtreme(string name, double level)
{
var attribute = this.GetAttributeFrom<OutputAttribute>("ExtremeHLStyle");
this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle);
}
private void DrawDay(string name, double level)
{
var attribute = this.GetAttributeFrom<OutputAttribute>("DayHLStyle");
this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle);
}
private void DrawSR(double level)
{
var attribute = this.GetAttributeFrom<OutputAttribute>("SRStyle");
this.ChartObjects.DrawHorizontalLine(string.Format("SR {0}", level), level, attribute.Color, attribute.Thickness, attribute.LineStyle);
}
private T GetAttributeFrom<T>(string propertyName)
{
var attrType = typeof(T);
var property = this.GetType().GetProperty(propertyName);
return (T)property.GetCustomAttributes(attrType, false).GetValue(0);
}
private class Price
{
internal double Value { get; set; }
internal int Count { get; set; }
}
private class Zone
{
internal double Start { get; set; }
internal double End { get; set; }
internal int LinesRendered { get; set; }
}
}
}
@amusleh
dokinya
20 May 2022, 10:00
RE:
amusleh said:
Hi,
By commenting I mean remove that line of code by making it a comment, ex:
using System; using System.Collections.Generic; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator("Support and Resistance At Price", IsOverlay = true, AccessRights = AccessRights.None)] public class SRAtPrice : Indicator { private double extremeHigh = 0; private double extremeLow = 0; private double dayHi = 0; private double dayLo = 0; private SortedList<double, int> prices = new SortedList<double, int>(); private IList<Zone> zones = new List<Zone>(); private const string ExtremeHighName = "ExtremeHigh"; private const string ExtremeLowName = "ExtremeLow"; private const string DayHighName = "DayHigh"; private const string DayLowName = "DayLow"; [Parameter("Periods", DefaultValue = 100)] public int Periods { get; set; } [Parameter("Show Extreme H/L", DefaultValue = true)] public bool ShowExtremeHL { get; set; } [Parameter("Show Day H/L", DefaultValue = true)] public bool ShowDayHL { get; set; } [Parameter("Required Hits", DefaultValue = 0)] public int RequiredHits { get; set; } [Parameter("Zone Size", DefaultValue = 2)] public int ZoneSize { get; set; } [Parameter("Max Lines In Zone", DefaultValue = 1)] public int MaxLinesInZone { get; set; } [Output("Extreme H/L Style", Color = Colors.Red, LineStyle = LineStyle.DotsVeryRare)] public IndicatorDataSeries ExtremeHLStyle { get; set; } [Output("Day H/L Style", Color = Colors.Blue, LineStyle = LineStyle.DotsVeryRare)] public IndicatorDataSeries DayHLStyle { get; set; } [Output("S/R Style", Color = Colors.Orange, LineStyle = LineStyle.DotsVeryRare)] public IndicatorDataSeries SRStyle { get; set; } public override void Calculate(int index) { if (this.IsLastBar) { var currentOpenDate = this.MarketSeries.OpenTime[index].Date; var earliest = index - this.Periods; for (var i = index; i >= earliest; i--) { if (i >= 0) { var high = this.MarketSeries.High[i]; var nextHigh = this.MarketSeries.High[i + 1]; var low = this.MarketSeries.Low[i]; var nextLow = this.MarketSeries.Low[i + 1]; this.extremeHigh = Math.Max(high, this.extremeHigh); this.extremeLow = this.extremeLow == 0 ? low : Math.Min(low, this.extremeLow); if (this.TimeFrame < TimeFrame.Minute) { if (this.MarketSeries.OpenTime[i].Date == currentOpenDate) { this.dayHi = Math.Max(high, this.dayHi); this.dayLo = this.dayLo == 0 ? low : Math.Min(low, this.dayLo); } } if (nextHigh <= high) { this.AddOrUpdatePrice(high); } if (nextLow >= low) { this.AddOrUpdatePrice(low); } } else { break; } } this.zones.Clear(); var rangePipSize = (this.Symbol.PipSize * (double)this.ZoneSize); for (var i = this.extremeLow + rangePipSize; i < this.extremeHigh - rangePipSize; i += rangePipSize + this.Symbol.PipSize) { this.zones.Add(new Zone { Start = i, End = i + rangePipSize, LinesRendered = 0 }); } //this.ChartObjects.RemoveAllObjects(); foreach (var price in this.prices.Keys) { this.RenderSRIfRequred(price, this.prices[price]); } if (this.ShowExtremeHL) { this.DrawExtremeHigh(); this.DrawExtremeLow(); } if (this.TimeFrame < TimeFrame.Minute && this.ShowDayHL) { this.DrawDayHigh(); this.DrawDayLow(); } } } private void RenderSRIfRequred(double price, int count) { if (count < this.RequiredHits) { return; } foreach (var range in this.zones) { if (price >= range.Start && price <= range.End) { if (range.LinesRendered != this.MaxLinesInZone) { range.LinesRendered++; this.DrawSR(price); } return; } } } private void AddOrUpdatePrice(double priceValue) { if (this.prices.ContainsKey(priceValue)) { this.prices[priceValue]++; } else { this.prices.Add(priceValue, 1); } } private void DrawExtremeHigh() { this.DrawExtreme(ExtremeHighName, this.extremeHigh); } private void DrawExtremeLow() { this.DrawExtreme(ExtremeLowName, this.extremeLow); } private void DrawDayHigh() { this.DrawDay(DayHighName, this.dayHi); } private void DrawDayLow() { this.DrawDay(DayLowName, this.dayLo); } private void DrawExtreme(string name, double level) { var attribute = this.GetAttributeFrom<OutputAttribute>("ExtremeHLStyle"); this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle); } private void DrawDay(string name, double level) { var attribute = this.GetAttributeFrom<OutputAttribute>("DayHLStyle"); this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle); } private void DrawSR(double level) { var attribute = this.GetAttributeFrom<OutputAttribute>("SRStyle"); this.ChartObjects.DrawHorizontalLine(string.Format("SR {0}", level), level, attribute.Color, attribute.Thickness, attribute.LineStyle); } private T GetAttributeFrom<T>(string propertyName) { var attrType = typeof(T); var property = this.GetType().GetProperty(propertyName); return (T)property.GetCustomAttributes(attrType, false).GetValue(0); } private class Price { internal double Value { get; set; } internal int Count { get; set; } } private class Zone { internal double Start { get; set; } internal double End { get; set; } internal int LinesRendered { get; set; } } } }
it's good thanks
dokinya
23 May 2022, 13:50
RE: RE:
dokinya said:
amusleh said:
Hi,
By commenting I mean remove that line of code by making it a comment, ex:
using System; using System.Collections.Generic; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator("Support and Resistance At Price", IsOverlay = true, AccessRights = AccessRights.None)] public class SRAtPrice : Indicator { private double extremeHigh = 0; private double extremeLow = 0; private double dayHi = 0; private double dayLo = 0; private SortedList<double, int> prices = new SortedList<double, int>(); private IList<Zone> zones = new List<Zone>(); private const string ExtremeHighName = "ExtremeHigh"; private const string ExtremeLowName = "ExtremeLow"; private const string DayHighName = "DayHigh"; private const string DayLowName = "DayLow"; [Parameter("Periods", DefaultValue = 100)] public int Periods { get; set; } [Parameter("Show Extreme H/L", DefaultValue = true)] public bool ShowExtremeHL { get; set; } [Parameter("Show Day H/L", DefaultValue = true)] public bool ShowDayHL { get; set; } [Parameter("Required Hits", DefaultValue = 0)] public int RequiredHits { get; set; } [Parameter("Zone Size", DefaultValue = 2)] public int ZoneSize { get; set; } [Parameter("Max Lines In Zone", DefaultValue = 1)] public int MaxLinesInZone { get; set; } [Output("Extreme H/L Style", Color = Colors.Red, LineStyle = LineStyle.DotsVeryRare)] public IndicatorDataSeries ExtremeHLStyle { get; set; } [Output("Day H/L Style", Color = Colors.Blue, LineStyle = LineStyle.DotsVeryRare)] public IndicatorDataSeries DayHLStyle { get; set; } [Output("S/R Style", Color = Colors.Orange, LineStyle = LineStyle.DotsVeryRare)] public IndicatorDataSeries SRStyle { get; set; } public override void Calculate(int index) { if (this.IsLastBar) { var currentOpenDate = this.MarketSeries.OpenTime[index].Date; var earliest = index - this.Periods; for (var i = index; i >= earliest; i--) { if (i >= 0) { var high = this.MarketSeries.High[i]; var nextHigh = this.MarketSeries.High[i + 1]; var low = this.MarketSeries.Low[i]; var nextLow = this.MarketSeries.Low[i + 1]; this.extremeHigh = Math.Max(high, this.extremeHigh); this.extremeLow = this.extremeLow == 0 ? low : Math.Min(low, this.extremeLow); if (this.TimeFrame < TimeFrame.Minute) { if (this.MarketSeries.OpenTime[i].Date == currentOpenDate) { this.dayHi = Math.Max(high, this.dayHi); this.dayLo = this.dayLo == 0 ? low : Math.Min(low, this.dayLo); } } if (nextHigh <= high) { this.AddOrUpdatePrice(high); } if (nextLow >= low) { this.AddOrUpdatePrice(low); } } else { break; } } this.zones.Clear(); var rangePipSize = (this.Symbol.PipSize * (double)this.ZoneSize); for (var i = this.extremeLow + rangePipSize; i < this.extremeHigh - rangePipSize; i += rangePipSize + this.Symbol.PipSize) { this.zones.Add(new Zone { Start = i, End = i + rangePipSize, LinesRendered = 0 }); } //this.ChartObjects.RemoveAllObjects(); foreach (var price in this.prices.Keys) { this.RenderSRIfRequred(price, this.prices[price]); } if (this.ShowExtremeHL) { this.DrawExtremeHigh(); this.DrawExtremeLow(); } if (this.TimeFrame < TimeFrame.Minute && this.ShowDayHL) { this.DrawDayHigh(); this.DrawDayLow(); } } } private void RenderSRIfRequred(double price, int count) { if (count < this.RequiredHits) { return; } foreach (var range in this.zones) { if (price >= range.Start && price <= range.End) { if (range.LinesRendered != this.MaxLinesInZone) { range.LinesRendered++; this.DrawSR(price); } return; } } } private void AddOrUpdatePrice(double priceValue) { if (this.prices.ContainsKey(priceValue)) { this.prices[priceValue]++; } else { this.prices.Add(priceValue, 1); } } private void DrawExtremeHigh() { this.DrawExtreme(ExtremeHighName, this.extremeHigh); } private void DrawExtremeLow() { this.DrawExtreme(ExtremeLowName, this.extremeLow); } private void DrawDayHigh() { this.DrawDay(DayHighName, this.dayHi); } private void DrawDayLow() { this.DrawDay(DayLowName, this.dayLo); } private void DrawExtreme(string name, double level) { var attribute = this.GetAttributeFrom<OutputAttribute>("ExtremeHLStyle"); this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle); } private void DrawDay(string name, double level) { var attribute = this.GetAttributeFrom<OutputAttribute>("DayHLStyle"); this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle); } private void DrawSR(double level) { var attribute = this.GetAttributeFrom<OutputAttribute>("SRStyle"); this.ChartObjects.DrawHorizontalLine(string.Format("SR {0}", level), level, attribute.Color, attribute.Thickness, attribute.LineStyle); } private T GetAttributeFrom<T>(string propertyName) { var attrType = typeof(T); var property = this.GetType().GetProperty(propertyName); return (T)property.GetCustomAttributes(attrType, false).GetValue(0); } private class Price { internal double Value { get; set; } internal int Count { get; set; } } private class Zone { internal double Start { get; set; } internal double End { get; set; } internal int LinesRendered { get; set; } } } }
it's good thanks
i thought this issue was sorted but i've just realized it was not... the indicator won't update it's stuck, and in some timeframe it's not showing, but when i delete it
it shows's and stay stuck.
amusleh
24 May 2022, 10:28
Hi,
This works fine on both cTrader 4.1 and 4.2:
using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Linq;
namespace cAlgo
{
[Indicator("Support and Resistance At Price", IsOverlay = true, AccessRights = AccessRights.None)]
public class SRAtPrice : Indicator
{
private double extremeHigh = 0;
private double extremeLow = 0;
private double dayHi = 0;
private double dayLo = 0;
private SortedList<double, int> prices = new SortedList<double, int>();
private IList<Zone> zones = new List<Zone>();
private const string ExtremeHighName = "ExtremeHigh";
private const string ExtremeLowName = "ExtremeLow";
private const string DayHighName = "DayHigh";
private const string DayLowName = "DayLow";
[Parameter("Periods", DefaultValue = 100)]
public int Periods { get; set; }
[Parameter("Show Extreme H/L", DefaultValue = true)]
public bool ShowExtremeHL { get; set; }
[Parameter("Show Day H/L", DefaultValue = true)]
public bool ShowDayHL { get; set; }
[Parameter("Required Hits", DefaultValue = 0)]
public int RequiredHits { get; set; }
[Parameter("Zone Size", DefaultValue = 2)]
public int ZoneSize { get; set; }
[Parameter("Max Lines In Zone", DefaultValue = 1)]
public int MaxLinesInZone { get; set; }
[Output("Extreme H/L Style", Color = Colors.Red, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries ExtremeHLStyle { get; set; }
[Output("Day H/L Style", Color = Colors.Blue, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries DayHLStyle { get; set; }
[Output("S/R Style", Color = Colors.Orange, LineStyle = LineStyle.DotsVeryRare)]
public IndicatorDataSeries SRStyle { get; set; }
public override void Calculate(int index)
{
if (this.IsLastBar)
{
var currentOpenDate = this.MarketSeries.OpenTime[index].Date;
var earliest = index - this.Periods;
for (var i = index; i >= earliest; i--)
{
if (i >= 0)
{
var high = this.MarketSeries.High[i];
var nextHigh = this.MarketSeries.High[i + 1];
var low = this.MarketSeries.Low[i];
var nextLow = this.MarketSeries.Low[i + 1];
this.extremeHigh = Math.Max(high, this.extremeHigh);
this.extremeLow = this.extremeLow == 0 ? low : Math.Min(low, this.extremeLow);
if (this.TimeFrame < TimeFrame.Minute)
{
if (this.MarketSeries.OpenTime[i].Date == currentOpenDate)
{
this.dayHi = Math.Max(high, this.dayHi);
this.dayLo = this.dayLo == 0 ? low : Math.Min(low, this.dayLo);
}
}
if (nextHigh <= high)
{
this.AddOrUpdatePrice(high);
}
if (nextLow >= low)
{
this.AddOrUpdatePrice(low);
}
}
else
{
break;
}
}
this.zones.Clear();
var rangePipSize = (this.Symbol.PipSize * (double)this.ZoneSize);
for (var i = this.extremeLow + rangePipSize; i < this.extremeHigh - rangePipSize; i += rangePipSize + this.Symbol.PipSize)
{
this.zones.Add(new Zone
{
Start = i,
End = i + rangePipSize,
LinesRendered = 0
});
}
var chartObjectCopy = Chart.Objects.ToArray();
foreach (var chartObject in chartObjectCopy)
{
Chart.RemoveObject(chartObject.Name);
}
foreach (var price in this.prices.Keys)
{
this.RenderSRIfRequred(price, this.prices[price]);
}
if (this.ShowExtremeHL)
{
this.DrawExtremeHigh();
this.DrawExtremeLow();
}
if (this.TimeFrame < TimeFrame.Minute && this.ShowDayHL)
{
this.DrawDayHigh();
this.DrawDayLow();
}
}
}
private void RenderSRIfRequred(double price, int count)
{
if (count < this.RequiredHits)
{
return;
}
foreach (var range in this.zones)
{
if (price >= range.Start && price <= range.End)
{
if (range.LinesRendered != this.MaxLinesInZone)
{
range.LinesRendered++;
this.DrawSR(price);
}
return;
}
}
}
private void AddOrUpdatePrice(double priceValue)
{
if (this.prices.ContainsKey(priceValue))
{
this.prices[priceValue]++;
}
else
{
this.prices.Add(priceValue, 1);
}
}
private void DrawExtremeHigh()
{
this.DrawExtreme(ExtremeHighName, this.extremeHigh);
}
private void DrawExtremeLow()
{
this.DrawExtreme(ExtremeLowName, this.extremeLow);
}
private void DrawDayHigh()
{
this.DrawDay(DayHighName, this.dayHi);
}
private void DrawDayLow()
{
this.DrawDay(DayLowName, this.dayLo);
}
private void DrawExtreme(string name, double level)
{
var attribute = this.GetAttributeFrom<OutputAttribute>("ExtremeHLStyle");
this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle);
}
private void DrawDay(string name, double level)
{
var attribute = this.GetAttributeFrom<OutputAttribute>("DayHLStyle");
this.ChartObjects.DrawHorizontalLine(name, level, attribute.Color, attribute.Thickness, attribute.LineStyle);
}
private void DrawSR(double level)
{
var attribute = this.GetAttributeFrom<OutputAttribute>("SRStyle");
this.ChartObjects.DrawHorizontalLine(string.Format("SR {0}", level), level, attribute.Color, attribute.Thickness, attribute.LineStyle);
}
private T GetAttributeFrom<T>(string propertyName)
{
var attrType = typeof(T);
var property = this.GetType().GetProperty(propertyName);
return (T)property.GetCustomAttributes(attrType, false).GetValue(0);
}
private class Price
{
internal double Value { get; set; }
internal int Count { get; set; }
}
private class Zone
{
internal double Start { get; set; }
internal double End { get; set; }
internal int LinesRendered { get; set; }
}
}
}
@amusleh
amusleh
19 May 2022, 09:56
Hi,
We were able to reproduce the issue with your indicator, we are investigating now what's causing it, please be patient and wait for our reply.
@amusleh