khoshroomahdi's avatar
Mahdi
Mahdi 's avatar

Info

Username:khoshroomahdi
Name:Mahdi
Member since: 17 Jun 2021

About

None

Signature

None

Last Algorithm Comments

@AW Moving Cloud:  12 Dec 2021, 22:44


@opit78 how could we have sepeate color for cloud and moving average? for example: different color for fast ema and up cloud.

@AW Moving Cloud:  12 Dec 2021, 22:43


@opit78 May i Use your code to update this indicator?

@Pattern Drawing:  22 Jun 2021, 20:12


why you didin't add this code to internal ctrader tools.? ex: Draw Traingle and fork is better than default tools

@Draw Spread:  18 Jun 2021, 16:54


Please add color parameter. enable $disable label, position on chart parameter

Last Forum Posts

@Fractal Calculate problem:  05 Jan 2023, 12:48


it shows wrong fractal based fractal fomula

Blue line is correct fractal

but my code show red line.

i think DrawUpFractal() and DrawDownFractal() have problems.

PanagiotisChar said:

Hi there,

I cannot understand the problem. Can you explain the issue better?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

@Fractal Calculate problem:  03 Jan 2023, 21:16


i make code to draw line between fractal and show distance , pip and percenge 

but it has problem to calculate fracral.

using cAlgo.API;
using System;
using System.Collections.Generic;
using System.Text;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AwFractal : Indicator
    {
        private class SwingPoint
        {
            public int Index { get; set; }
            public double Price { get; set; }

            public SwingPoint()
            {
                Index = 0;
                Price = double.MaxValue;
            }

            public SwingPoint(int index, double price)
            {
                Index = index;
                Price = price;
            }
        }

        #region Fields

        // Bar Index
        private int _index;

        // Direction of the Fractal
        private Direction direction = Direction.Down;

        // Price of recent High
        private double high;

        // Price of recent Low
        private double low;

        private bool isBullish;

        private SwingPoint swingPoint;
        private List<SwingPoint> swingPointList;

        private enum Direction
        {
            Up,
            Down
        }

        #endregion Fields

        #region Parameters

        [Parameter("Period", DefaultValue = 5, MinValue = 5, Group = "Fractal")]
        public int Period { get; set; }

        [Parameter("Show Distance?", DefaultValue = false, Group = "Fractal")]
        public bool ShowDistance { get; set; }

        [Parameter("Show Pip?", DefaultValue = false, Group = "Fractal")]
        public bool ShowPip { get; set; }

        [Parameter("Show Percentage?", DefaultValue = true, Group = "Fractal")]
        public bool ShowPercentChange { get; set; }

        #endregion Parameters

        #region Output

        [Output("Fractal", LineColor = "Red", Thickness = 2, PlotType = PlotType.Line)]
        public IndicatorDataSeries Result { get; set; }

        #endregion Output

        public override void Calculate(int index)
        {
            _index = index;

            low = Bars.LowPrices.LastValue;
            high = Bars.HighPrices.LastValue;

            if (Bars.ClosePrices.Count < 2)
                return;

            switch (direction)
            {
                case Direction.Up:
                    DrawUpFractal();
                    break;

                case Direction.Down:
                default:
                    DrawDownFractal();
                    break;
            }
        }

        protected override void Initialize()
        {
            swingPoint = new SwingPoint();
            swingPointList = new List<SwingPoint>();
        }

        #region Append Text

        public string GetFractalText(double currentValue, double previousValue, double thirdValue)
        {
            StringBuilder sb = new StringBuilder();

            if (ShowDistance)
                AppendDistance(sb);

            if (ShowPip)
                AppendPip(sb);

            if (ShowPercentChange)
                AppendPercentageChange(currentValue, previousValue, thirdValue, sb);



            return sb.ToString();
        }

        private void AppendPercentageChange(double currentValue, double previousValue, double thirdValue, StringBuilder sb)
        {
            if (ShowDistance || ShowPip)
                sb.AppendLine();

            string sign = isBullish ? "+" : "-";
            string percentage = (isBullish ? CalculatePercentageChange(thirdValue, previousValue, currentValue) : CalculatePercentageChange(thirdValue, previousValue, currentValue)).ToString("N0");

            sb.Append(string.Format("{0}{1}%", sign, percentage));
        }

        private void AppendDistance(StringBuilder sb)
        {
            sb.Append((swingPointList[swingPointList.Count - 1].Index - swingPointList[swingPointList.Count - 2].Index).ToString(""));
        }

        private void AppendPip(StringBuilder sb)
        {
            if (ShowDistance)
                sb.AppendLine();

            sb.Append(((swingPointList[swingPointList.Count - 1].Price - swingPointList[swingPointList.Count - 2].Price) / Symbol.PipSize).ToString("N1"));
        }

        private double CalculatePercentageChange(double third, double previous, double current)
        {
            double lastChange = Math.Abs(third - previous);
            double change = Math.Abs(current - previous);
            return 100 * (double)change / lastChange;
        }

        #endregion Append Text

        #region Create Fractal

        public void ShowFractalLabel()
        {
            // Get last value
            double currentValue = swingPointList[swingPointList.Count - 1].Price;
            // Get second last value
            double previousValue = swingPointList[swingPointList.Count - 2].Price;
            //get thirdValue
            double thirdValue = swingPointList[swingPointList.Count - 3].Price;


            isBullish = currentValue > previousValue;
            string objName = "FractalLabel" + swingPoint.Index;
            Color textColour = isBullish ? "Green" : "Red";
            string labelText = GetFractalText(currentValue, previousValue, thirdValue);

            ChartText text = Chart.DrawText(name: objName, text: labelText, barIndex: swingPoint.Index, y: swingPoint.Price, color: textColour);

            text.VerticalAlignment = isBullish ? VerticalAlignment.Top : VerticalAlignment.Bottom;
            text.HorizontalAlignment = HorizontalAlignment.Center;
        }

        private void DrawDownFractal()
        {

            int period = Period % 2 == 0 ? Period - 1 : Period;
            int middleIndex = _index - period / 2;
            double middleValue = Bars.LowPrices[middleIndex];
            bool down = true;

            for (int i = 0; i < period; i++)
            {
                if (middleValue > Bars.LowPrices[_index - i])
                {
                    down = false;
                    break;
                }
            }
            if (down)
            {
                bool moveExtremum = low <= swingPoint.Price;
                bool changeDirection = high >= swingPoint.Price;

                if (moveExtremum)
                    MoveExtremum(low);
                else if (changeDirection)
                {
                    SetExtremum(high);
                    direction = Direction.Up;
                }
            }

        }

        private void DrawUpFractal()
        {
        
            int period = Period % 2 == 0 ? Period - 1 : Period;
            int middleIndex = -_index - period / 2;
            double middleValue = Bars.HighPrices[middleIndex];

            bool up = true;

            for (int i = 0; i < period; i++)
            {
                if (middleValue < Bars.HighPrices[-_index - i])
                {
                    up = false;
                    break;
                }
            }
            if (up)
            {

                bool moveExtremum = high >= swingPoint.Price;
                bool changeDirection = low <= swingPoint.Price;

                if (moveExtremum)
                    MoveExtremum(high);
                else if (changeDirection)
                {
                    SetExtremum(low);
                    direction = Direction.Down;
                }
            }


        }

        private void MoveExtremum(double price)
        {
            Result[swingPoint.Index] = double.NaN;

            if (swingPointList.Count > 0)
                swingPointList.Remove(swingPointList[swingPointList.Count - 1]);

            Chart.RemoveObject("FractalLabel" + swingPoint.Index);

            SetExtremum(price);
        }

        private void SetExtremum(double price)
        {
            swingPoint = new SwingPoint(_index, price);
            swingPointList.Add(swingPoint);
            Result[swingPoint.Index] = swingPoint.Price;

            if (swingPointList.Count < 2)
                return;

            ShowFractalLabel();
        }

        #endregion Create Fractal




    }
}

@ctrader 4.4.19 doesn't save line style,thickness:  20 Nov 2022, 14:26


4.4.19 is aweful

for a trader that use line, fibo, rectangle in chart is terrible that set every line color, thickness, fibo level and etc

pleeeeease fix that soooooon

@show icon in Max high candle:  02 Sep 2022, 01:23


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;
using System.Linq;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWBoxLiveTime : Indicator
    {

        [Parameter("Period", DefaultValue = 10, MinValue = 1, Group = "Rectangle")]
        public int Period { get; set; }
        [Parameter("Color", DefaultValue = "Red", Group = "Rectangle")]
        public string Color { get; set; }
        [Parameter("LineStyle", DefaultValue = LineStyle.Solid, Group = "Rectangle")]
        public LineStyle ls { get; set; }
        [Parameter("Thickness", DefaultValue = 2, Group = "Rectangle")]
        public int Thickness { get; set; }

        [Parameter("Mid Line", DefaultValue = true, Group = "Mid Line")]
        public bool Midline { get; set; }
        [Parameter("Mid Line Color", DefaultValue = "Red", Group = "Mid Line")]
        public string Color2 { get; set; }
        [Parameter("Mid Line Style", DefaultValue = LineStyle.Lines, Group = "Mid Line")]
        public LineStyle ls2 { get; set; }
        [Parameter("Mid Line Thickness", DefaultValue = 1, Group = "Mid Line")]
        public int Thickness2 { get; set; }
        [Parameter("Mid Time Line", DefaultValue = true, Group = "Mid Line")]
        public bool MidTimeline { get; set; }
        
       

        protected override void Initialize()
        {


        }

        public override void Calculate(int index)
        {

            var rectangle = Chart.DrawRectangle("rectangle_sample", Bars.Count, Bars.LowPrices.Minimum(Period), Chart.LastVisibleBarIndex - Period, Bars.HighPrices.Maximum(Period), Color);
            rectangle.IsInteractive = false;
            rectangle.IsFilled = false;
            rectangle.LineStyle = ls;
            rectangle.Thickness = Thickness;
            Chart.DrawIcon("iconName", ChartIconType.DownTriangle,GetHighLowInSelection().Point2.BarIndex, Bars.HighPrices.Maximum(Period), Color2);
            Chart.DrawIcon("iconName2", ChartIconType.UpTriangle,GetHighLowInSelection().Point1.BarIndex, Bars.LowPrices.Minimum(Period), Color2);

            if (Midline)
            {
                var trendLine = Chart.DrawTrendLine("trendLine", Chart.LastVisibleBarIndex + 1, (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2, Chart.LastVisibleBarIndex - Period, (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2, Color2, Thickness2, ls2);
            }
            if (MidTimeline)
            {
                var trendLine1 = Chart.DrawTrendLine("TimeLine",(Chart.LastVisibleBarIndex+Chart.LastVisibleBarIndex - Period)/2,Bars.HighPrices.Maximum(Period),(Chart.LastVisibleBarIndex+Chart.LastVisibleBarIndex - Period)/2,Bars.LowPrices.Minimum(Period), Color2, Thickness2, ls2);
            }


        }
         private ChartPoints GetHighLowInSelection()
        {
            var priceMax = double.MinValue;
            var priceMin = double.MaxValue;
            int barIndexMin = -1;
            int barIndexMax = -1;
            for (int i = Chart.LastVisibleBarIndex-Period; i <= Chart.LastVisibleBarIndex;i++)
            {
                var high = Bars.HighPrices[i];
                var low = Bars.LowPrices[i];
                if (high > priceMax)
                {
                    priceMax = high;
                    barIndexMax = i;
                }
                if (low < priceMin)
                {
                    priceMin = low;
                    barIndexMin = i;
                }
            }

            var maximum = new ChartPoint(barIndexMax, priceMax);
            var minimum = new ChartPoint(barIndexMin, priceMin);
            return new ChartPoints(minimum, maximum);
        }
        class ChartPoint
    {
        public ChartPoint(int barIndex, double price)
        {
            BarIndex = barIndex;
            Price = price;
        }

        public int BarIndex { get; private set; }
        public double Price { get; private set; }
    }

    class ChartPoints
    {
        public ChartPoints(ChartPoint point1, ChartPoint point2)
        {
            Point1 = point1;
            Point2 = point2;
        }

        public ChartPoint Point1 { get; private set; }
        public ChartPoint Point2 { get; private set; }
    }
      





    }
}

i fix this but i have a mini problem with distance betwwen arrow and candle. how can i fix it...

 i want to add normal space between arrow and line.

@show icon in Max high candle:  01 Sep 2022, 17:56


i want to show an arrow in max candle but i dont know how to get this candle time in a period

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;
using System.Linq;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWBoxLiveTime : Indicator
    {

        [Parameter("Period", DefaultValue = 10, MinValue = 1, Group = "Rectangle")]
        public int Period { get; set; }
        [Parameter("Color", DefaultValue = "Red", Group = "Rectangle")]
        public string Color { get; set; }
        [Parameter("LineStyle", DefaultValue = LineStyle.Solid, Group = "Rectangle")]
        public LineStyle ls { get; set; }
        [Parameter("Thickness", DefaultValue = 2, Group = "Rectangle")]
        public int Thickness { get; set; }

        [Parameter("Mid Line", DefaultValue = true, Group = "Mid Line")]
        public bool Midline { get; set; }
        [Parameter("Mid Line Color", DefaultValue = "Red", Group = "Mid Line")]
        public string Color2 { get; set; }
        [Parameter("Mid Line Style", DefaultValue = LineStyle.Lines, Group = "Mid Line")]
        public LineStyle ls2 { get; set; }
        [Parameter("Mid Line Thickness", DefaultValue = 1, Group = "Mid Line")]
        public int Thickness2 { get; set; }
        [Parameter("Mid Time Line", DefaultValue = true, Group = "Mid Line")]
        public bool MidTimeline { get; set; }
        
       

        protected override void Initialize()
        {


        }

        public override void Calculate(int index)
        {

            var rectangle = Chart.DrawRectangle("rectangle_sample", Bars.Count, Bars.LowPrices.Minimum(Period), Chart.LastVisibleBarIndex - Period, Bars.HighPrices.Maximum(Period), Color);
            rectangle.IsInteractive = false;
            rectangle.IsFilled = false;
            rectangle.LineStyle = ls;
            rectangle.Thickness = Thickness;
            Chart.DrawIcon("iconName", ChartIconType.DownArrow,GetHighLowInSelection().Point1.BarIndex, Bars.HighPrices.Maximum(Period), "Blue");

            if (Midline)
            {
                var trendLine = Chart.DrawTrendLine("trendLine", Chart.LastVisibleBarIndex + 1, (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2, Chart.LastVisibleBarIndex - Period, (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2, Color2, Thickness2, ls2);
            }
            if (MidTimeline)
            {
                var trendLine1 = Chart.DrawTrendLine("TimeLine",(Chart.LastVisibleBarIndex+Chart.LastVisibleBarIndex - Period)/2,Bars.HighPrices.Maximum(Period),(Chart.LastVisibleBarIndex+Chart.LastVisibleBarIndex - Period)/2,Bars.LowPrices.Minimum(Period), Color2, Thickness2, ls2);
            }


        }
         private ChartPoints GetHighLowInSelection()
        {
            var priceMax = double.MinValue;
            var priceMin = double.MaxValue;
            int barIndexMin = -1;
            int barIndexMax = -1;
            for (int i = Chart.LastVisibleBarIndex; i >= Chart.LastVisibleBarIndex-Period; i++)
            {
                var high = Bars.HighPrices[i];
                var low = Bars.LowPrices[i];
                if (high > priceMax)
                {
                    priceMax = high;
                    barIndexMax = i;
                }
                if (low < priceMin)
                {
                    priceMin = low;
                    barIndexMin = i;
                }
            }

            var maximum = new ChartPoint(barIndexMax, priceMax);
            var minimum = new ChartPoint(barIndexMin, priceMin);
            return new ChartPoints(minimum, maximum);
        }
        class ChartPoint
    {
        public ChartPoint(int barIndex, double price)
        {
            BarIndex = barIndex;
            Price = price;
        }

        public int BarIndex { get; private set; }
        public double Price { get; private set; }
    }

    class ChartPoints
    {
        public ChartPoints(ChartPoint point1, ChartPoint point2)
        {
            Point1 = point1;
            Point2 = point2;
        }

        public ChartPoint Point1 { get; private set; }
        public ChartPoint Point2 { get; private set; }
    }
      





    }
}

@ctrader 4.3 suspend this code:  08 Jul 2022, 12:32


PanagiotisCharalampous said:

Hi khoshroomahdi,

You need to be more specific regarding what is not working.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Arguments out of range error in logs. 

@ctrader 4.3 suspend this code:  08 Jul 2022, 08:27


i have a problem with this code in 4.3

but it works in 4.1

using cAlgo.API;
using System;
using Microsoft.Win32;
namespace cAlgo
{
    // This sample indicator shows how to add a text box control on your chart
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWCalcVolume : Indicator
    {

        double risk;
        double pip;
        TextBox textBox3 = new TextBox();



        [Parameter("Horizontal Alignment ", DefaultValue = HorizontalAlignment.Left)]
        public HorizontalAlignment HAlignment { get; set; }

        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top)]
        public VerticalAlignment VAlignment { get; set; }

        [Parameter("Orientation", DefaultValue = Orientation.Horizontal)]
        public Orientation Orientation1 { get; set; }

        [Parameter("Color", DefaultValue = "Red")]
        public string color { get; set; }


        protected override void Initialize()
        {
            var mainStackPanel = new StackPanel 
            {
                HorizontalAlignment = HAlignment,
                VerticalAlignment = VAlignment,
                Orientation = Orientation1
            };
            var StackPanel1 = new StackPanel 
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Orientation = Orientation.Vertical
            };
            var StackPanel2 = new StackPanel 
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Orientation = Orientation.Vertical,
                Margin = 3
            };
            var StackPanel3 = new StackPanel 
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                Orientation = Orientation.Vertical
            };
            var textBlock1 = new TextBlock 
            {
                ForegroundColor = color,
                HorizontalAlignment = HorizontalAlignment.Center,
                Text = "Risk%"
            };

            var textBox1 = new TextBox 
            {
                ForegroundColor = color,
                HorizontalAlignment = HorizontalAlignment.Center,
                Width = 50,
                BorderThickness = 2,
                BorderColor = color,
                TextAlignment = TextAlignment.Center
            };
            var textBlock2 = new TextBlock 
            {
                ForegroundColor = color,
                HorizontalAlignment = HorizontalAlignment.Center,
                Text = "SL(pips)"
            };
            var textBox2 = new TextBox 
            {
                ForegroundColor = color,
                HorizontalAlignment = HorizontalAlignment.Center,
                Width = 50,
                BorderThickness = 2,
                BorderColor = color,
                TextAlignment = TextAlignment.Center
            };


            var textBlock3 = new TextBlock 
            {

                ForegroundColor = color,
                HorizontalAlignment = HorizontalAlignment.Center,
                Text = "Volume"
            };


            textBox3.ForegroundColor = color;
            textBox3.HorizontalAlignment = HorizontalAlignment.Center;
            textBox3.Width = 50;
            textBox3.BorderThickness = 2;
            textBox3.BorderColor = color;
            textBox3.IsEnabled = false;
            textBlock3.TextAlignment = TextAlignment.Center;


            textBox1.TextChanged += TextBox1_TextChanged;
            textBox2.TextChanged += TextBox2_TextChanged;

            StackPanel1.AddChild(textBlock1);
            StackPanel1.AddChild(textBox1);

            StackPanel2.AddChild(textBlock2);
            StackPanel2.AddChild(textBox2);

            StackPanel3.AddChild(textBlock3);
            StackPanel3.AddChild(textBox3);

            mainStackPanel.AddChild(StackPanel1);
            mainStackPanel.AddChild(StackPanel2);
            mainStackPanel.AddChild(StackPanel3);

            Chart.AddControl(mainStackPanel);
        }
        private void TextBox1_TextChanged(TextChangedEventArgs obj)
        {
            risk = Convert.ToDouble(obj.TextBox.Text);
        }
        private void TextBox2_TextChanged(TextChangedEventArgs obj)
        {
            pip = Convert.ToDouble(obj.TextBox.Text);
        }
        public override void Calculate(int index)
        {
            textBox3.Text = CalcVolume(risk, pip);

        }

        public string CalcVolume(double r, double p)
        {

            return Math.Round(Symbol.VolumeInUnitsToQuantity(Account.Balance * r / 100 / (pip * Symbol.PipValue)), 2).ToString();


        }
    }
}

@midline doesn't move:  19 Jun 2022, 11:21


in this below code i have a box with mid line.

when i move vertical line box move but midline disapper.

i know that problem is in Chart_ObjectsUpdated part. but i coudln't fix that.

using cAlgo.API;
using System.Linq;
using System;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWBoxOffline2 : Indicator
    {
        private ChartVerticalLine _vl;

        private ChartRectangle _box;
        
        private ChartTrendLine _midline;

        [Parameter("Period", DefaultValue = 60, MinValue = 1)]
        public int Period { get; set; }

        [Parameter("Line Color", DefaultValue = "Red", Group = "Line")]
        public string LineColor { get; set; }

        [Parameter("LineStyle", DefaultValue = LineStyle.Solid, Group = "Line")]
        public LineStyle ls { get; set; }

        [Parameter("Thickness", DefaultValue = 2, Group = "Line")]
        public int Thickness { get; set; }
        
        [Parameter("Mid Line", DefaultValue = true, Group = "Mid Line")]
        public bool Midline { get; set; }
        
        [Parameter("Mid Line Color", DefaultValue = "Red", Group = "Mid Line")]
        public string Color2 { get; set; }
        [Parameter("Mid Line Style", DefaultValue = LineStyle.Solid, Group = "Mid Line")]
        public LineStyle ls2 { get; set; }
        [Parameter("Mid Line Thickness", DefaultValue = 2, Group = "Mid Line")]
        public int Thickness2 { get; set; }

        protected override void Initialize()
        {
            _vl = Chart.DrawVerticalLine("scrollLine", Chart.LastVisibleBarIndex, Color.FromName(LineColor), Thickness, ls);
            _vl.IsInteractive = true;
            var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);
            
             if (Midline)
            {
                _midline = Chart.DrawTrendLine("trendLine",verticalLineBarIndex , (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2, verticalLineBarIndex-Period, (Bars.LowPrices.Minimum(Period) + Bars.HighPrices.Maximum(Period)) / 2,Color2,Thickness2,ls2);
            }


            _box = Chart.DrawRectangle("rectangle_sample", verticalLineBarIndex, Bars.LowPrices.Minimum(Period), verticalLineBarIndex - Period, Bars.HighPrices.Maximum(Period), Color.FromArgb(100, Color.Red));
            _box.IsFilled = true;
            _box.IsInteractive = false;
            _box.IsFilled = false;
            _box.Thickness = Thickness;
            _box.Color = LineColor;
            _box.LineStyle = ls;

            Chart.ObjectsUpdated += Chart_ObjectsUpdated;
        }

        private void Chart_ObjectsUpdated(ChartObjectsUpdatedEventArgs obj)
        {
            if (!obj.ChartObjects.Contains(_vl))
                return;

            var verticalLineBarIndex = Bars.OpenTimes.GetIndexByTime(_vl.Time);

            _box.Time1 = Bars.OpenTimes[verticalLineBarIndex];
            _box.Time2 = Bars.OpenTimes[verticalLineBarIndex - Period];

            _box.Y1 = GetMinimum(Bars.LowPrices, verticalLineBarIndex, Period);
            _box.Y2 = GetMaximum(Bars.HighPrices, verticalLineBarIndex, Period);
            
            _midline.Time1=Bars.OpenTimes[verticalLineBarIndex];
            _midline.Time2 = Bars.OpenTimes[verticalLineBarIndex - Period];

            _midline.Y1=GetMinimum(Bars.LowPrices, verticalLineBarIndex, Period)+GetMaximum(Bars.HighPrices, verticalLineBarIndex, Period)/2;
            _midline.Y2 = GetMinimum(Bars.LowPrices, verticalLineBarIndex, Period)+GetMaximum(Bars.HighPrices, verticalLineBarIndex, Period)/2;
        }

        private double GetMinimum(DataSeries source, int index, int periods)
        {
            double min = double.MaxValue;

            var lastBarIndex = index - periods;

            for (int i = index; i > lastBarIndex; i--)
            {
                min = Math.Min(min, source[i]);
            }

            return min;
        }

        private double GetMaximum(DataSeries source, int index, int periods)
        {
            double max = double.MinValue;

            var lastBarIndex = index - periods;

            for (int i = index; i > lastBarIndex; i--)
            {
                max = Math.Max(max, source[i]);
            }

            return max;
        }

        public override void Calculate(int index)
        {
        }
    }
}

@problem with 4.2(aw ichimoku indicator):  30 May 2022, 18:47


amusleh said:

Hi,

Try this:

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    [Cloud("Up Kumo", "Down Kumo", Opacity = 0.2)]
    public class AwIchimoku : Indicator
    {
        [Parameter("Tenkan sen", DefaultValue = 9, MinValue = 1)]
        public int Ten_Period { get; set; }

        [Parameter("Kijun sen", DefaultValue = 26, MinValue = 1)]
        public int K_Period { get; set; }

        [Parameter("Senkou span B", DefaultValue = 52, MinValue = 1)]
        public int SB_Period { get; set; }

        [Output("Tenkan sen", LineStyle = LineStyle.Solid, LineColor = "Red")]
        public IndicatorDataSeries Ten_Result { get; set; }

        [Output("Kijun sen", LineStyle = LineStyle.Solid, LineColor = "Blue")]
        public IndicatorDataSeries K_Result { get; set; }

        [Output("Chiku span", LineStyle = LineStyle.Solid, LineColor = "Purple")]
        public IndicatorDataSeries C_Result { get; set; }

        [Output("Up Kumo", LineStyle = LineStyle.Solid, LineColor = "Green")]
        public IndicatorDataSeries Up_Result { get; set; }

        [Output("Down Kumo", LineStyle = LineStyle.Solid, LineColor = "FFFF6666")]
        public IndicatorDataSeries Down_Result { get; set; }

        [Output("Span A", LineStyle = LineStyle.Solid, LineColor = "Green")]
        public IndicatorDataSeries SA_Result { get; set; }

        [Output("Span B", LineStyle = LineStyle.Solid, LineColor = "FFFF6666")]
        public IndicatorDataSeries SB_Result { get; set; }

        private IchimokuKinkoHyo _ICHI;

        protected override void Initialize()
        {
            _ICHI = Indicators.IchimokuKinkoHyo(Ten_Period, K_Period, SB_Period);
        }

        public override void Calculate(int index)
        {
            Ten_Result[index] = _ICHI.TenkanSen[index];
            K_Result[index] = _ICHI.KijunSen[index];
            C_Result[index - 26] = _ICHI.ChikouSpan[index];
            SA_Result[index + 26] = (_ICHI.TenkanSen[index] + _ICHI.KijunSen[index]) / 2;
            SB_Result[index + 26] = _ICHI.SenkouSpanB[index];
            Up_Result[index + 26] = (_ICHI.TenkanSen[index] + _ICHI.KijunSen[index]) / 2;
            Down_Result[index + 26] = _ICHI.SenkouSpanB[index];
        }
    }
}

it doesn't show chico span

@problem with 4.2(aw ichimoku indicator):  28 May 2022, 14:17


this code work in 4.1 but doesn't work correctly in 4.2. i couldn't resolve that.


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    [Cloud("Up Kumo", "Down Kumo", Opacity = 0.2)]

    public class AwIchimoku : Indicator
    {


        [Parameter("Tenkan sen", DefaultValue = 9, MinValue = 1)]
        public int Ten_Period { get; set; }

        [Parameter("Kijun sen", DefaultValue = 26, MinValue = 1)]
        public int K_Period { get; set; }

        [Parameter("Senkou span B", DefaultValue = 52, MinValue = 1)]
        public int SB_Period { get; set; }



        [Output("Tenkan sen", LineStyle = LineStyle.Solid, LineColor = "Red")]
        public IndicatorDataSeries Ten_Result { get; set; }

        [Output("Kijun sen", LineStyle = LineStyle.Solid, LineColor = "Blue")]
        public IndicatorDataSeries K_Result { get; set; }

        [Output("Chiku span", LineStyle = LineStyle.Solid, LineColor = "Purple")]
        public IndicatorDataSeries C_Result { get; set; }

        [Output("Up Kumo", LineStyle = LineStyle.Solid, LineColor = "Green")]
        public IndicatorDataSeries Up_Result { get; set; }

        [Output("Down Kumo", LineStyle = LineStyle.Solid, LineColor = "FFFF6666")]
        public IndicatorDataSeries Down_Result { get; set; }


        [Output("Span A", LineStyle = LineStyle.Solid, LineColor = "Green")]
        public IndicatorDataSeries SA_Result { get; set; }

        [Output("Span B", LineStyle = LineStyle.Solid, LineColor = "FFFF6666")]
        public IndicatorDataSeries SB_Result { get; set; }


        private IchimokuKinkoHyo _ICHI;

        protected override void Initialize()
        {
            _ICHI = Indicators.IchimokuKinkoHyo(Ten_Period, K_Period, SB_Period);

        }


        public override void Calculate(int index)
        {
            Ten_Result[index] = _ICHI.TenkanSen.Last(0);
            K_Result[index] = _ICHI.KijunSen.Last(0);
            C_Result[index - 26] = _ICHI.ChikouSpan.Last(0);
            SA_Result[index + 26] = (_ICHI.TenkanSen.Last(0) + _ICHI.KijunSen.Last(0)) / 2;
            SB_Result[index + 26] = _ICHI.SenkouSpanB.Last(0);
            Up_Result[index + 26] = (_ICHI.TenkanSen.Last(0) + _ICHI.KijunSen.Last(0)) / 2;
            Down_Result[index + 26] = _ICHI.SenkouSpanB.Last(0);

        }

    }

}



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.
Aw Slowing Moving
  3
  0
  199
free  01 Jan 2023
Add Slowing to Aw Moving Average.
Aw Ichimoku Macd
  5
  0
  164
free  31 Dec 2022
this indicaotr show distance between Tenkan to Kijun, Close to Kijun and Close to Tenkan 
Aw Macd on Chart
  3
  0
  183
free  31 Dec 2022
this indicator show macd on chart.
AW Ichimoku no Kumo
  5
  0
  219
free  18 Nov 2022
i makethis indicator for someone who want practice ichimoku. in ichimoku indicator we couldn't  hide kumo easily. but in this indicator you could hide it .  
AW Macd +MacdLine
  2
  0
  549
free  31 Aug 2022
some user add moving average to macd to see better. in ctrader 4.3.11 there is a problem with this . I make a macd that have macdline for that users.
AW Calc Volume
  4
  0
  771
free  27 Jan 2023
this indicator calculate your olume based on your risk percent and stop(pip).
AW Ichimoku
  3
  0
  821
free  04 Jun 2022
it's defualt ichimoku but you could use differnet color for kumo and span A and span B. 2022/06/04 update: compiled in NET 6. (Ctrader 4.2)
AW Box Live
  9
  0
  888
free  27 Jan 2023
this indicator add rectangle to your chart from last bar. update: NET6 update: add arrow  add mid time line Atention:: ex: you set Period 10 This indicagtor shows 10 Candle in box but if you use Ctrader ruler that shows 9 because ctrader ruler shows distance.    
AW Moving Cloud
  12
  0
  1294
free  08 Jul 2022
 moving average cloud. you could change cloud color. to disable cloud just set color as transparent. update: NET 6
AW Macd Color
  1
  0
  1331
free  08 Jul 2022
MACD Default Color like AWESOME OSCILLATOR (AO)   update: NET 6    
AW Coral
  1
  0
  1245
free  08 Jul 2022
Coral indicator update: NET 6
AW Multi Data
  2
  5
  1083
free  27 Jan 2023
show symbol and time fram, daily net profit percent, daily net profit, and spread ln your chart. consider that timezone set to utc to show daily proift correctly. update 2022/09/10: optional Data  
AW Spread
  0
  5
  1665
free  27 Jan 2023
show spread on chart update :2022/07/08 update for NET 6    
AW Moving MTF
  1
  0
  1042
free  08 Jul 2022
multi time frame moving averge. you could choose different type of price like median ,high and ... and differnt type of moving average. you could shift moving in this indicator. update: NET 6  
AW Moving Average
  0
  0
  1428
free  08 Jul 2022
 this moving include everything that a trader needs from Moving Average. PriceType: Open,Close,High,Low, Median,Typical,Weighted Support all moving average type. update: NET 6      
AW Vline
  0
  5
  1585
free  27 Jan 2023
don't move to the end of chart after timeframe changing. it should be better to use for near history. for long history this have delay. 2022/06/04 update: Net 6(ctrader 4.2)
Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.
AW Manager
  7
  0
  705
free  08 Jul 2022
close position in specefic equity. it's useful for someone that couldn't control himself in live market.
AW CP Step
  1
  0
  922
free  08 Jul 2022
this bot close all position and cancel all order after get step profit percent. step calculate by ((equity/balance)-1)*100   update: Net 6
AW CP Daily
  5
  0
  994
free  08 Jul 2022
AW Close Position. this bot close all position and cancel all order after get daily profit percent. update: NET 6