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

hamidrtafx@gmail.com
14 Jun 2018, 11:14

RE:

Panagiotis Charalampous said:

17 bars? If yes, you can use the code I posted

yes bars

 

but i want In the past, the market has also been featured


@hamidrtafx@gmail.com

hamidrtafx@gmail.com
14 Jun 2018, 10:29

RE:

Panagiotis Charalampous said:

Hi hamidrtafx@gmail.com,

What does -17 represent? Bars, hours, anything else?

Best Regards,

Panagiotis


17From this condition-

if (SenkouSpanA.HasCrossedBelow(SenkouSpanB, 26)

 


@hamidrtafx@gmail.com

hamidrtafx@gmail.com
14 Jun 2018, 10:26

  if (SenkouSpanA.HasCrossedBelow(SenkouSpanB, 26) && switch_komu1)
            {
                ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Black, 2);
 ChartObjects.RemoveObject((index - 1).ToString());

 


@hamidrtafx@gmail.com

hamidrtafx@gmail.com
14 Jun 2018, 10:22

RE:

Panagiotis Charalampous said:

Hi hamidrtafx@gmail.com,

Here it is 

hartObjects.DrawVerticalLine("test", MarketSeries.Close.Count - 17, Colors.Red, 2);

Best Regards,

Panagiotis

thanks a lot

:but i want market series open time -17 similar code
 

ChartObjects.DrawVerticalLine(index.ToString(), MarketSeries.OpenTime[index], Colors.Black, 2);


 


@hamidrtafx@gmail.com

hamidrtafx@gmail.com
12 Jun 2018, 20:36

RE:

Panagiotis Charalampous said:

Hi hamidrtafx@gmail.com,

Try the below

            if ((MarketSeries.Open.Last(2) < MarketSeries.Close.Last(1) && MarketSeries.Close.Last(2) > MarketSeries.Close.Last(1)) || (MarketSeries.Open.Last(2) > MarketSeries.Close.Last(1) && MarketSeries.Close.Last(2) < MarketSeries.Close.Last(1)))
            {
                // Do something
            }

Best Regards,

Panagiotis

thanks but not true

i want 

high.low.close.open) last 1 candel in the body last 2 )
 

for example picture


@hamidrtafx@gmail.com

hamidrtafx@gmail.com
12 Jun 2018, 14:03

RE:

Panagiotis Charalampous said:

Hi hamidrtafx@gmail.com,

It is not clear what you need the code to do. Please give us more information in order to help you.

Best Regards,

Panagiotis

105/5000

I need to read the code that one candel in the body of the previousl candel , as shown in the above pictures .


@hamidrtafx@gmail.com

hamidrtafx@gmail.com
22 Feb 2018, 15:08 ( Updated at: 21 Dec 2023, 09:20 )

RE:

noppanon said:

Hi Hamidrtafx,

   You may try to cut and past the code to notepad and save as ANSI text file to clean any encoding.

   I modified the code so that you can change how many periods you want to check for flating. 

   Here is sample if flat periods is 3.

TK Flat parameters

 

 

Here is the code.

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TKFlat : Indicator
    {
        [Parameter("Tenkan Sen Period", DefaultValue = 9)]
        public int TenkanPeriod { get; set; }

        [Parameter("Kijun Sen Period", DefaultValue = 26)]
        public int KijunPeriod { get; set; }

        [Parameter("Senkou Span B Period", DefaultValue = 52)]
        public int SenkouPeriod { get; set; }

        [Parameter("Flat Period", DefaultValue = 3)]
        public int FlatPeriod { get; set; }

        private IchimokuKinkoHyo Cloud;
        private Random ChartID;

        protected override void Initialize()
        {
            ChartID = new Random();
            Cloud = Indicators.IchimokuKinkoHyo(TenkanPeriod, KijunPeriod, SenkouPeriod);
        }

        public override void Calculate(int index)
        {
            for (int i = 0; i < FlatPeriod; i++ )
            {                
                if (Cloud.TenkanSen[index - i] != Cloud.TenkanSen[index - i - 1])
                {
                    return;
                }
            }

            for (int j = 0; j < FlatPeriod; j++)
            {
                if (Cloud.KijunSen[index - j] != Cloud.KijunSen[index - j - 1])
                {
                    return;
                }
            }
            ChartObjects.DrawVerticalLine("Flat_" + ChartID.Next(0, 100000).ToString(), index, Colors.Aqua, 2, LineStyle.Solid);
        }
    }
}

Happy trading,

Noppanon

 

thanks a lot.

but i wan any time  just dimension flat kijun and tenken are eqaul. not eny flat!!

are you understand?

 

send  me email please.

 

thanks


@hamidrtafx@gmail.com

hamidrtafx@gmail.com
20 Feb 2018, 19:42 ( Updated at: 21 Dec 2023, 09:20 )

for example picture:

i need when for example picture:

 

tenken &kijun flat equal :

 


@hamidrtafx@gmail.com

hamidrtafx@gmail.com
20 Feb 2018, 19:10

RE:

noppanonl said:

Hi Hamidrtafx,

   You may try quick code. I assume that you already have Ichimoku indicator present in your chart. 

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TKFlat : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Parameter("Tenkan Sen Period", DefaultValue = 9)]
        public int TenkanPeriod { get; set; }

        [Parameter("Kijun Sen Period", DefaultValue = 26)]
        public int KijunPeriod { get; set; }

        [Parameter("Senkou Span B Period", DefaultValue = 52)]
        public int SenkouPeriod { get; set; }

        private IchimokuKinkoHyo Cloud;

        protected override void Initialize()
        {
            Cloud = Indicators.IchimokuKinkoHyo(TenkanPeriod, KijunPeriod, SenkouPeriod);            
        }

        public override void Calculate(int index)
        {
            if(Cloud.TenkanSen[index] == Cloud.TenkanSen[index-1] && Cloud.KijunSen[index] == Cloud.KijunSen[index-1])
            {
                ChartObjects.DrawVerticalLine("Flat", index, Colors.Aqua, 1, LineStyle.Solid);
            }
        }
    }
}

have a good trade

Noppanon

thanks a lot

 

but  have a error:

 

Error : Error occured during parsing project file: 'System does not support 'ut-kf-8' encoding. Line 1, position 31.'

 

why?


@hamidrtafx@gmail.com