Chart.DrawText error. please help.

Created at 16 Feb 2020, 19:13
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
TR

traderfxmaster007

Joined 09.07.2019

Chart.DrawText error. please help.
16 Feb 2020, 19:13


please help me fix the error code. i dont know how to code.

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

namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class LEXtrend : Indicator
{
[Parameter("LEX Period", DefaultValue = 14, MinValue = 1, MaxValue = 25)]
public int Period { get; set; }

[Parameter("LEX Threshold", DefaultValue = 20, MinValue = 20, MaxValue = 60)]
public int Threshold { get; set; }

[Parameter("Arrow Offset", DefaultValue = 5, MinValue = 1, Step = 1)]
public double arrowOffset { get; set; }

private string upArrow = "▲";
private string downArrow = "▼";

  private IchimokuKinkoHyo Ichimoku;
  private DirectionalMovementSystem dms;

protected override void Initialize()
{
Ichimoku= Indicators.IchimokuKinkoHyo(9, 26, 52);
dms = Indicators.DirectionalMovementSystem (Period);

arrowOffset = Symbol.PipSize * arrowOffset;

}
public override void Calculate(int index)
{
double high = Bars.HighPrices[index];
double low = Bars.LowPrices[index];

if (BuySignal())
Chart.DrawText(string.Format("Buy {0}", index), upArrow, index - 1, low - arrowOffset, VerticalAlignment.Top, HorizontalAlignment.Center, Color.Lime);

if (SellSignal())
Chart.DrawText(string.Format("Sell {0}", index), downArrow, index - 1, high + arrowOffset, VerticalAlignment.Top, HorizontalAlignment.Center, Color.Red);
}

#region Predicate
public bool BuySignal()
{
return 

Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1) && Bars.ClosePrices.Last(1) > Ichimoku.KijunSen.Last(1) && dms.DIPlus.Last(1) > dms.DIMinus.Last(1) && 
dms.DIPlus.Last(1) > Threshold &&
(Bars.ClosePrices.Last(2) < Bars.OpenPrices.Last(2) || Bars.ClosePrices.Last(2) < Ichimoku.KijunSen.Last(2) || dms.DIPlus.Last(2) < dms.DIMinus.Last(2) || dms.DIPlus.Last(2) <= Threshold);
}
public bool SellSignal()
{
return 

Bars.ClosePrices.Last(1) < Bars.OpenPrices.Last(1) && Bars.ClosePrices.Last(1) < Ichimoku.KijunSen.Last(1) && dms.DIPlus.Last(1) < dms.DIMinus.Last(1) && 
dms.DIMinus.Last(1) > Threshold &&
(Bars.ClosePrices.Last(2) > Bars.OpenPrices.Last(2) || Bars.ClosePrices.Last(2) > Ichimoku.KijunSen.Last(2) || dms.DIPlus.Last(2) > dms.DIMinus.Last(2) || dms.DIMinus.Last(2) <= Threshold);

}
#endregion

}
}

 


@traderfxmaster007
Replies

PanagiotisCharalampous
17 Feb 2020, 09:50

Hi traderfxmaster007,

See below

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class LEXtrend : Indicator
    {
        [Parameter("LEX Period", DefaultValue = 14, MinValue = 1, MaxValue = 25)]
        public int Period { get; set; }

        [Parameter("LEX Threshold", DefaultValue = 20, MinValue = 20, MaxValue = 60)]
        public int Threshold { get; set; }

        [Parameter("Arrow Offset", DefaultValue = 5, MinValue = 1, Step = 1)]
        public double arrowOffset { get; set; }

        private string upArrow = "▲";
        private string downArrow = "▼";

        private IchimokuKinkoHyo Ichimoku;
        private DirectionalMovementSystem dms;

        protected override void Initialize()
        {
            Ichimoku = Indicators.IchimokuKinkoHyo(9, 26, 52);
            dms = Indicators.DirectionalMovementSystem(Period);

            arrowOffset = Symbol.PipSize * arrowOffset;

        }
        public override void Calculate(int index)
        {
            double high = Bars.HighPrices[index];
            double low = Bars.LowPrices[index];

            if (BuySignal())
                Chart.DrawStaticText(string.Format("Buy {0}", index), upArrow, VerticalAlignment.Top, HorizontalAlignment.Center, Color.Lime);

            if (SellSignal())
                Chart.DrawStaticText(string.Format("Sell {0}", index), downArrow, VerticalAlignment.Top, HorizontalAlignment.Center, Color.Red);
        }

        #region Predicate
        public bool BuySignal()
        {

            return Bars.ClosePrices.Last(1) > Bars.OpenPrices.Last(1) && Bars.ClosePrices.Last(1) > Ichimoku.KijunSen.Last(1) && dms.DIPlus.Last(1) > dms.DIMinus.Last(1) && dms.DIPlus.Last(1) > Threshold && (Bars.ClosePrices.Last(2) < Bars.OpenPrices.Last(2) || Bars.ClosePrices.Last(2) < Ichimoku.KijunSen.Last(2) || dms.DIPlus.Last(2) < dms.DIMinus.Last(2) || dms.DIPlus.Last(2) <= Threshold);
        }
        public bool SellSignal()
        {

            return Bars.ClosePrices.Last(1) < Bars.OpenPrices.Last(1) && Bars.ClosePrices.Last(1) < Ichimoku.KijunSen.Last(1) && dms.DIPlus.Last(1) < dms.DIMinus.Last(1) && dms.DIMinus.Last(1) > Threshold && (Bars.ClosePrices.Last(2) > Bars.OpenPrices.Last(2) || Bars.ClosePrices.Last(2) > Ichimoku.KijunSen.Last(2) || dms.DIPlus.Last(2) > dms.DIMinus.Last(2) || dms.DIMinus.Last(2) <= Threshold);

        }
        #endregion

    }
}

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous