flat kijunsen

Created at 27 Jun 2018, 20:01
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!
HA

hamidrtafx@gmail.com

Joined 18.02.2018

flat kijunsen
27 Jun 2018, 20:01


hi i need vertical line when kijunsen is flat.

can you help me?

 

 


@hamidrtafx@gmail.com
Replies

hamidrtafx@gmail.com
27 Jun 2018, 20:03

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using System.Threading.Tasks;
namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class IchimokuKinkoHyo : Indicator
    {
        private int alertBarIndex = 0;
        [Parameter(DefaultValue = 9)]
        public int periodFast { get; set; }
        [Parameter(DefaultValue = 26)]
        public int periodMedium { get; set; }
        [Parameter(DefaultValue = 52)]
        public int periodSlow { get; set; }
        [Parameter(DefaultValue = 26)]
        public int DisplacementChikou { get; set; }
        [Parameter(DefaultValue = 17)]
        public int DisplacementTenkansen { get; set; }
        [Parameter(DefaultValue = 26)]
        public int DisplacementCloud { get; set; }
        [Parameter(DefaultValue = 26)]
        public int Displacementkijunsen { get; set; }
        [Parameter(DefaultValue = -26)]
        public int DL { get; set; }
        [Parameter(DefaultValue = 0)]
        public int Displacemenspanb { get; set; }
        [Parameter("Text Color", DefaultValue = "Black")]
        public string TextColor { get; set; }
        [Parameter(DefaultValue = true)]
        public bool Common_cross { get; set; }
        [Parameter(DefaultValue = false)]
        public bool Uncommon { get; set; }
        [Parameter(DefaultValue = false)]
        public bool Common_cross_kumo { get; set; }
        [Parameter(DefaultValue = false)]
        public bool spanB_QL { get; set; }

        [Parameter(DefaultValue = true)]
        public bool switch_komu { get; set; }

        [Parameter(DefaultValue = true)]
        public bool switch_komu1 { get; set; }

        [Output("TenkanSen", Color = Colors.Red)]
        public IndicatorDataSeries TenkanSen { get; set; }
        [Output("Kijunsen", Color = Colors.Blue)]
        public IndicatorDataSeries KijunSen { get; set; }
        [Output("ChikouSpan", Color = Colors.DarkViolet)]
        public IndicatorDataSeries ChikouSpan { get; set; }
        [Output("qualityline", Color = Colors.Black)]
        public IndicatorDataSeries qualityline { get; set; }
        [Output("shiftt", Color = Colors.Black)]
        public IndicatorDataSeries shiftt { get; set; }
        [Output("SenkouSpanB", Color = Colors.Red, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanB { get; set; }
        [Output("SenkouSpanA", Color = Colors.Green, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanA { get; set; }
        [Output("Directionline", Color = Colors.Purple)]
        public IndicatorDataSeries Directionline { get; set; }
        private Colors color = Colors.Black;
        double maxfast, minfast, maxmedium, minmedium, maxslow, minslow, maxbig, minbig;
        protected override void Initialize()
        {
            Enum.TryParse(TextColor, out color);
        }
        public override void Calculate(int index)
        {
            if (IsLastBar)
                DisplaySpreadOnChart();
            if ((index < periodFast) || (index < periodSlow))
            {
                return;
            }
            string signalType = string.Empty;
            maxfast = MarketSeries.High[index];
            minfast = MarketSeries.Low[index];
            maxmedium = MarketSeries.High[index];
            minmedium = MarketSeries.Low[index];
            maxbig = MarketSeries.High[index];
            minbig = MarketSeries.Low[index];
            maxslow = MarketSeries.High[index];
            minslow = MarketSeries.Low[index];
            for (int i = 0; i < periodFast; i++)
            {
                if (maxfast < MarketSeries.High[index - i])
                {
                    maxfast = MarketSeries.High[index - i];
                }
                if (minfast > MarketSeries.Low[index - i])
                {
                    minfast = MarketSeries.Low[index - i];
                }
            }
            for (int i = 0; i < periodMedium; i++)
            {
                if (maxmedium < MarketSeries.High[index - i])
                {
                    maxmedium = MarketSeries.High[index - i];
                }
                if (minmedium > MarketSeries.Low[index - i])
                {
                    minmedium = MarketSeries.Low[index - i];
                }
            }
            for (int i = 0; i < periodSlow; i++)
            {
                if (maxslow < MarketSeries.High[index - i])
                {
                    maxslow = MarketSeries.High[index - i];
                }
                if (minslow > MarketSeries.Low[index - i])
                {
                    minslow = MarketSeries.Low[index - i];
                }
            }
            TenkanSen[index] = (maxfast + minfast) / 2;
            KijunSen[index] = (maxmedium + minmedium) / 2;
            ChikouSpan[index - DisplacementChikou] = MarketSeries.Close[index];
            SenkouSpanA[index + DisplacementCloud] = (TenkanSen[index] + KijunSen[index]) / 2;
            SenkouSpanB[index + DisplacementCloud] = (maxslow + minslow) / 2;
            qualityline[index + Displacementkijunsen] = (maxmedium + minmedium) / 2;
            shiftt[index + DisplacementTenkansen] = (maxfast + minfast) / 2;
            Directionline[index + DL] = (maxmedium + minmedium) / 2;
            if (KijunSen[index] == TenkanSen[index] && Common_cross)
            {
                ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Red, 1, LineStyle.DotsVeryRare);
                ChartObjects.RemoveObject((index - 1).ToString());
                TriggerAlert(TradeType.Sell, index, "Common_cross");
            }
            if (TenkanSen.HasCrossedAbove(KijunSen, 0) && Uncommon)
            {
                ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Green, 1, LineStyle.DotsVeryRare);
                ChartObjects.RemoveObject((index - 1).ToString());
                TriggerAlert(TradeType.Sell, index, "Uncommon");
            }
            if (KijunSen[index] == TenkanSen[index] && SenkouSpanA[index + DisplacementCloud] == SenkouSpanB[index + DisplacementCloud] && Common_cross_kumo)
            {
                ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Blue, 2, LineStyle.DotsVeryRare);
                ChartObjects.RemoveObject((index - 1).ToString());
                TriggerAlert(TradeType.Sell, index, "Common_cross_kumo");
            }
            if (KijunSen[index] == SenkouSpanB[index] && spanB_QL)
            {
                ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Black, 1, LineStyle.DotsVeryRare);
                TriggerAlert(TradeType.Sell, index, "spanB_QL");
            }
            if (SenkouSpanA.HasCrossedAbove(SenkouSpanB, 26) && switch_komu)
            {
                ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Black, 2, LineStyle.DotsVeryRare);


                ChartObjects.RemoveObject((index - 1).ToString());
                TriggerAlert(TradeType.Sell, index, "switch_komu");
            }
            if (SenkouSpanA.HasCrossedBelow(SenkouSpanB, 26) && switch_komu1)
            {
                ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Black, 2, LineStyle.DotsVeryRare);

                ChartObjects.RemoveObject((index - 1).ToString());
                TriggerAlert(TradeType.Sell, index, "switch_komu1");
            }

        }
        private void DisplaySpreadOnChart()
        {
            var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 4);
            string text = string.Format("{0}", spread);
            ChartObjects.DrawText("spread", "\t" + text, StaticPosition.BottomRight, Colors.Black);
        }
        private void TriggerAlert(TradeType alertType, int index, string msg)
        {
            if (index != alertBarIndex && IsLastBar && IsRealTime)
            {
                alertBarIndex = index;
            }
        }
    }
}

 


@hamidrtafx@gmail.com