How to add a Horizontal Line to specific Pip Value

Created at 27 Sep 2021, 18:35
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!
DI

DiamondTrades

Joined 14.09.2021

How to add a Horizontal Line to specific Pip Value
27 Sep 2021, 18:35


I would like to have an indicator add a Horizontal line any time the chosen Pip value appears.

For example, if I selected "89" as the value, I would like a line to be added  to 1.0089, 1.0189, 1.0289.... if the value was "21" then a line would be added to 1.0021, 1.0121, 1.0221.... So the indicator does not add a line every X pips but rather only on the exact pip that matches the value chosen. 

I currently am able to populate a line every X pips however I would like to have an indicator that does the above to study, however unfortunately I do not know how to go about this. Any help appreciated!


 


@DiamondTrades
Replies

amusleh
28 Sep 2021, 09:38

Hi,

You have to define a mathematical relation between those numbers, then you can code it.

Try this:

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class test : Indicator
    {
        [Parameter("Amount (Pips)", DefaultValue = 21)]
        public double AmountInPips { get; set; }

        [Parameter("Step (Pips)", DefaultValue = 100)]
        public double StepInPips { get; set; }

        [Parameter("Min Level (Price)", DefaultValue = 1)]
        public double MinLevelInPrice { get; set; }

        [Parameter("Max Level (Price)", DefaultValue = 10)]
        public double MaxLevelInPrice { get; set; }

        protected override void Initialize()
        {
            AmountInPips *= Symbol.PipSize;
            StepInPips *= Symbol.PipSize;

            for (var level = MinLevelInPrice; level < MaxLevelInPrice; level += StepInPips)
            {
                var lineLevel = Math.Round(level + AmountInPips, Symbol.Digits);

                Chart.DrawHorizontalLine(lineLevel.ToString(), lineLevel, Color.Red);

                // Uncomment the print if you want to check the line levels on your cTrader automate logs tab
                //Print(lineLevel);
            }
        }

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

You might be able to find other better ways to code the same thing witch will be much faster than mine.


@amusleh

DiamondTrades
28 Sep 2021, 11:14

RE:

amusleh said:

Hi,

You have to define a mathematical relation between those numbers, then you can code it.

Try this:

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class test : Indicator
    {
        [Parameter("Amount (Pips)", DefaultValue = 21)]
        public double AmountInPips { get; set; }

        [Parameter("Step (Pips)", DefaultValue = 100)]
        public double StepInPips { get; set; }

        [Parameter("Min Level (Price)", DefaultValue = 1)]
        public double MinLevelInPrice { get; set; }

        [Parameter("Max Level (Price)", DefaultValue = 10)]
        public double MaxLevelInPrice { get; set; }

        protected override void Initialize()
        {
            AmountInPips *= Symbol.PipSize;
            StepInPips *= Symbol.PipSize;

            for (var level = MinLevelInPrice; level < MaxLevelInPrice; level += StepInPips)
            {
                var lineLevel = Math.Round(level + AmountInPips, Symbol.Digits);

                Chart.DrawHorizontalLine(lineLevel.ToString(), lineLevel, Color.Red);

                // Uncomment the print if you want to check the line levels on your cTrader automate logs tab
                //Print(lineLevel);
            }
        }

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

You might be able to find other better ways to code the same thing witch will be much faster than mine.

Thank you very much! This does the job perfectly 


@DiamondTrades