Algorithms

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
How to install
renko
  0
  0
  201
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  1
  0
  81
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  0
  0
  84
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  1
  0
  90
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  0
  0
  86
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  1
  0
  71
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  0
  0
  82
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  0
  0
  81
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  0
  0
  115
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  0
  0
  66
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  0
  0
  93
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>
renko
  0
  0
  71
free  11 Dec 2022
using cAlgo.API;<font></font> using cAlgo.API.Indicators;<font></font> using cAlgo.API.Internals;<font></font> using cAlgo.Indicators;<font></font> using System;<font></font> using System.Collections.Generic;<font></font> using System.Linq;<font></font> using System.Windows.Forms;<font></font> using System.Runtime.InteropServices;<font></font> using System.Diagnostics;<font></font> using cT_MedianRenkoEngine;<font></font> <font></font> namespace cAlgo<font></font> {<font></font>     [Indicator("MedianRenko", IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]<font></font>     public class MedianRenko : Indicator<font></font>     {<font></font>         [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]<font></font>         public double BarSizePips { get; set; }<font></font> <font></font>         [Parameter("Retracement factor (0.01 - 1.00)", DefaultValue = 0.5, MinValue = 0.01, MaxValue = 1.0, Step = 0.01)]<font></font>         public double Retracement { get; set; }<font></font> <font></font>         [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]<font></font>         public int BricksToShow { get; set; }<font></font> <font></font>         [Parameter("Symmetrical Reversals", DefaultValue = true)]<font></font>         public bool SymmetricalReversals { get; set; }<font></font> <font></font>         [Parameter("Reset Open on new trading day", DefaultValue = false)]<font></font>         public bool ResetOpenOnNewTradingDay { get; set; }<font></font> <font></font>         [Parameter("Apply offset to first renko bar", DefaultValue = false)]<font></font>         public bool ApplyOffsetToFirstBar { get; set; }<font></font> <font></font>         [Parameter("Tick offset value", DefaultValue = 0, MinValue = 0)]<font></font>         public int OffsetValue { get; set; }<font></font> <font></font>         [Parameter("Bullish Bar Color", DefaultValue = "SeaGreen")]<font></font>         public string ColorBull { get; set; }<font></font> <font></font>         [Parameter("Bearish Bar Color", DefaultValue = "Tomato")]<font></font>         public string ColorBear { get; set; }<font></font> <font></font>         [Output("Open", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Open { get; set; }<font></font> <font></font>         [Output("High", Color = Colors.DimGray, Thickness = 1, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries High { get; set; }<font></font> <font></font>         [Output("Low", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Low { get; set; }<font></font> <font></font>         [Output("Close", Color = Colors.DimGray, Thickness = 0, PlotType = PlotType.Points)]<font></font>         public IndicatorDataSeries Close { get; set; }<font></font> <font></font>         private MedianRenkoCore core = null;<font></font>         private bool coreOK = true;<font></font> <font></font>         private DateTime lastTime;<font></font> <font></font>         private bool appliedOffset = false;<font></font> <font></font>         private T_OLHCV pOLHCV;<font></font>         private T_OLHCV OLHCV;<font></font>         private T_OLHCV mOLHCV;<font></font>         private T_OLHCV cOLHCV;<font></font>         private T_OLHCV memRates;<font></font>         private T_OLHCV lastBar;<font></font> <font></font>         private List<T_OLHCV> bars = new List<T_OLHCV>();<font></font>         private double barSize;<font></font>         private Colors colorBull, colorBear;<font></font> <font></font>         protected override void Initialize()<font></font>         {<font></font>             core = new MedianRenkoCore();<font></font>             coreOK = core.StatusCheck();<font></font> <font></font>             barSize = BarSizePips * Symbol.PipSize;<font></font> <font></font>             lastTime = new DateTime();<font></font>             lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];<font></font> <font></font>             lastBar = new T_OLHCV();<font></font>             pOLHCV = new T_OLHCV();<font></font>             OLHCV = new T_OLHCV();<font></font>             mOLHCV = new T_OLHCV();<font></font>             cOLHCV = new T_OLHCV();<font></font>             memRates = new T_OLHCV();<font></font> <font></font>             if (!Enum.TryParse<Colors>(ColorBull, out colorBull))<font></font>             {<font></font>                 colorBull = Colors.SeaGreen;<font></font>             }<font></font>             if (!Enum.TryParse<Colors>(ColorBear, out colorBear))<font></font>             {<font></font>                 colorBear = Colors.Tomato;<font></font>             }<font></font> <font></font>             appliedOffset = false;<font></font>         }<font></font> <font></font>         private bool NewBar(int index)<font></font>         {<font></font>             if (lastTime != MarketSeries.OpenTime[index])<font></font>             {<font></font>                 lastTime = MarketSeries.OpenTime[index];<font></font>                 return true;<font></font>             }<font></font> <font></font>             return false;<font></font>         }<font></font> <font></font>         private static int cc = 0;<font></font>         private void pushBars(T_OLHCV bar, bool display)<font></font>         {<font></font>             int count = bars.Count();<font></font> <font></font>             var newBar = new T_OLHCV();<font></font>             newBar.Copy(bar);<font></font>             newBar.Index = cc++;<font></font> <font></font>             bars.Insert(0, newBar);<font></font>             count++;<font></font> <font></font>             if (display)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font> <font></font>             if (count > BricksToShow)<font></font>             {<font></font>                 if (display)<font></font>                 {<font></font>                     for (int i = BricksToShow - 1; i < count; i++)<font></font>                     {<font></font>                         ChartObjects.RemoveObject("mr_Wick_" + bars[i].Index);<font></font>                         ChartObjects.RemoveObject("mr_Bar_" + bars[i].Index);<font></font>                     }<font></font>                 }<font></font> <font></font>                 bars.RemoveRange(BricksToShow, count - BricksToShow);<font></font> <font></font>                 Open[count - BricksToShow] = double.NaN;<font></font>                 High[count - BricksToShow] = double.NaN;<font></font>                 Low[count - BricksToShow] = double.NaN;<font></font>                 Close[count - BricksToShow] = double.NaN;<font></font>             }<font></font> <font></font>         }<font></font> <font></font>         private void shiftBars(int shift)<font></font>         {<font></font>             int count = bars.Count;<font></font>             int ix = MarketSeries.Close.Count - 2;<font></font> <font></font>             for (int i = 0; i < count && i < BricksToShow; i++)<font></font>             {<font></font>                 var candleColor = (bars[i].Close > bars[i].Open) ? colorBull : colorBear;<font></font> <font></font>                 ChartObjects.DrawLine("mr_Wick_" + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, 1, LineStyle.Solid);<font></font>                 ChartObjects.DrawLine("mr_Bar_" + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>                 Open[ix] = bars[i].Open;<font></font>                 High[ix] = bars[i].High;<font></font>                 Low[ix] = bars[i].Low;<font></font>                 Close[ix] = bars[i].Close;<font></font> <font></font>                 ix--;<font></font>             }<font></font>         }<font></font> <font></font>         private void UpdateLastBar(int ix)<font></font>         {<font></font>             var candleColor = (memRates.Close > memRates.Open) ? colorBull : colorBear;<font></font> <font></font>             ChartObjects.DrawLine("mr_Wick_Live", ix, memRates.High, ix, memRates.Low, candleColor, 1, LineStyle.Solid);<font></font>             ChartObjects.DrawLine("mr_Bar_Live", ix, memRates.Close, ix, memRates.Open, candleColor, 5, LineStyle.Solid);<font></font> <font></font>             Open[ix] = memRates.Open;<font></font>             High[ix] = memRates.High;<font></font>             Low[ix] = memRates.Low;<font></font>             Close[ix] = memRates.Close;<font></font> <font></font>         }<font></font> <font></font>         public override void Calculate(int index)<font></font>         {<font></font>             if (ResetOpenOnNewTradingDay)<font></font>             {<font></font>                 if (IsNewSession(MarketSeries.OpenTime[(index > 0) ? (index - 1) : index], MarketSeries.OpenTime[index]))<font></font>                 {<font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font>                     pOLHCV.Clear();<font></font>                     memRates.Copy(mOLHCV);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsRealTime)<font></font>             {<font></font>                 if (!coreOK)<font></font>                 {<font></font>                     ChartObjects.DrawText("TrialOverMsg", "MedianRenko Indicator - Trial period ended. Please purchase a license file at www.az-invest.eu", StaticPosition.Center, Colors.White);<font></font>                     return;<font></font>                 }<font></font> <font></font>                 if (NewBar(index))<font></font>                 {<font></font>                     shiftBars(0);<font></font> <font></font>                     Open[index - BricksToShow - 1] = double.NaN;<font></font>                     High[index - BricksToShow - 1] = double.NaN;<font></font>                     Low[index - BricksToShow - 1] = double.NaN;<font></font>                     Close[index - BricksToShow - 1] = double.NaN;<font></font>                 }<font></font> <font></font>                 OLHCV.Open = MarketSeries.Close[index];<font></font>                 OLHCV.Low = MarketSeries.Close[index];<font></font>                 OLHCV.High = MarketSeries.Close[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = 1;<font></font> <font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font>                 UpdateLastBar(index);<font></font>             }<font></font>             else<font></font>             {<font></font>                 OLHCV.Open = MarketSeries.Open[index];<font></font>                 OLHCV.Low = MarketSeries.Low[index];<font></font>                 OLHCV.High = MarketSeries.High[index];<font></font>                 OLHCV.Close = MarketSeries.Close[index];<font></font>                 OLHCV.OpenTime = MarketSeries.OpenTime[index];<font></font>                 OLHCV.TickVolume = MarketSeries.TickVolume[index];<font></font> <font></font>                 if (ApplyOffsetToFirstBar && !appliedOffset)<font></font>                 {<font></font>                     OLHCV.Open = OffsetValue * Symbol.TickSize + Math.Floor(OLHCV.Open / barSize) * barSize;<font></font>                     appliedOffset = true;<font></font>                 }<font></font> <font></font>                 ProcessMarketData(OLHCV);<font></font> <font></font>                 if (IsLastBar)<font></font>                     UpdateLastBar(index);<font></font>             }<font></font>         }<font></font> <font></font>         private void ProcessMarketData(T_OLHCV ___OLHCV)<font></font>         {<font></font>             int rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);<font></font>             while (true)<font></font>             {<font></font>                 if ((rb_return >= 1) && (rb_return <= 4))<font></font>                 {<font></font>                     pushBars(cOLHCV, IsRealTime);<font></font>                     memRates.Copy(mOLHCV);<font></font>                     OLHCV.Copy(memRates);<font></font> <font></font>                     cOLHCV.Clear();<font></font>                     mOLHCV.Clear();<font></font> <font></font>                     rb_return = core.ProcessMedianRenko(barSize, Retracement, SymmetricalReversals, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);<font></font>                     continue;<font></font> <font></font>                 }<font></font>                 else if (rb_return == 10)<font></font>                 {<font></font>                     memRates.Copy(mOLHCV);<font></font>                     break;<font></font>                 }<font></font>                 else if (rb_return == -1)<font></font>                 {<font></font>                     return;<font></font>                 }<font></font>                 else<font></font>                 {<font></font>                     throw new Exception("Unhandled return value = " + rb_return);<font></font>                 }<font></font>             }<font></font> <font></font>             if (IsLastBar && !IsRealTime)<font></font>             {<font></font>                 shiftBars(0);<font></font>             }<font></font>         }<font></font> <font></font>         private bool IsNewSession(DateTime prevTime, DateTime currTime)<font></font>         {<font></font>             if (prevTime.DayOfWeek != currTime.DayOfWeek)<font></font>                 return true;<font></font>             else<font></font>                 return false;<font></font>         }<font></font> <font></font> <font></font>     }<font></font> }<font></font> <font></font>