How to create dynamic horizontal line

Created at 23 May 2024, 04:56
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!
TU

tuuguu177

Joined 22.05.2024

How to create dynamic horizontal line
23 May 2024, 04:56


Hello, I am newbie at Ctrader. I used Metatrader5 before. Now I am moving from MT5 to Ctrader.

I want to ask very simple question. How to create dynamic horizontal lines which is higher and lower than 200 points than price?

These horizontal lines must follow price directly.

Thank you.

 


@tuuguu177
Replies

PanagiotisCharalampous
23 May 2024, 05:36

Hi there,

You can use DrawHorizontalLine to draw horizontal lines.

Best regards,

Panagiotis


@PanagiotisCharalampous

tuuguu177
23 May 2024, 07:21 ( Updated at: 23 May 2024, 08:29 )

RE: How to create dynamic horizontal line

PanagiotisCharalampous said: 

Hi there,

You can use DrawHorizontalLine to draw horizontal lines.

Best regards,

Panagiotis

but how to make it dynamic. Dynamic means Horizontal lines follow price.


@tuuguu177

PanagiotisCharalampous
23 May 2024, 08:31

RE: RE: How to create dynamic horizontal line

tuuguu177 said: 

PanagiotisCharalampous said: 

Hi there,

You can use DrawHorizontalLine to draw horizontal lines.

Best regards,

Panagiotis

but how to make it dynamic. Dynamic means Horizontal lines follow price.

Hi there, 

Just draw the line at the specific price you want on each tick. If you use the same name for your line it will replace the previous one, making it dynamic.

Best regards,

Panagiotis


@PanagiotisCharalampous

tuuguu177
23 May 2024, 09:34 ( Updated at: 23 May 2024, 09:42 )

RE: RE: RE: How to create dynamic horizontal line

PanagiotisCharalampous said: 

tuuguu177 said: 

PanagiotisCharalampous said: 

Hi there,

You can use DrawHorizontalLine to draw horizontal lines.

Best regards,

Panagiotis

but how to make it dynamic. Dynamic means Horizontal lines follow price.

Hi there, 

Just draw the line at the specific price you want on each tick. If you use the same name for your line it will replace the previous one, making it dynamic.

Best regards,

Panagiotis

Could you please show me the code? Sorry i am super newbie at coding. Thank you very much


@tuuguu177

PanagiotisCharalampous
23 May 2024, 09:45

RE: RE: RE: RE: How to create dynamic horizontal line

tuuguu177 said: 

PanagiotisCharalampous said: 

tuuguu177 said: 

PanagiotisCharalampous said: 

Hi there,

You can use DrawHorizontalLine to draw horizontal lines.

Best regards,

Panagiotis

but how to make it dynamic. Dynamic means Horizontal lines follow price.

Hi there, 

Just draw the line at the specific price you want on each tick. If you use the same name for your line it will replace the previous one, making it dynamic.

Best regards,

Panagiotis

Could you please show me the code? Sorry i am super newbie at coding. Thank you very much

There is example code in the documentation. Try doing this yourself and let us know where you have questions and what is blocking you to move further.


@PanagiotisCharalampous

tuuguu177
23 May 2024, 09:56 ( Updated at: 23 May 2024, 11:04 )

RE: RE: RE: RE: RE: How to create dynamic horizontal line

PanagiotisCharalampous said: 

tuuguu177 said: 

PanagiotisCharalampous said: 

tuuguu177 said: 

PanagiotisCharalampous said: 

Hi there,

You can use DrawHorizontalLine to draw horizontal lines.

Best regards,

Panagiotis

but how to make it dynamic. Dynamic means Horizontal lines follow price.

Hi there, 

Just draw the line at the specific price you want on each tick. If you use the same name for your line it will replace the previous one, making it dynamic.

Best regards,

Panagiotis

Could you please show me the code? Sorry i am super newbie at coding. Thank you very much

There is example code in the documentation. Try doing this yourself and let us know where you have questions and what is blocking you to move further.

okey. I tried and created static horizontal line. This is code i write. Now I can not understand how to make it dynamic. Could you please advise?

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

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None)]
    public class dynamic_HLine : Indicator
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        protected override void Initialize()
        {
            // To learn more about cTrader Automate visit our Help Center:
            // https://help.ctrader.com/ctrader-automate
            Chart.DrawHorizontalLine("horizontalLine", 2362, Color.Red);
            //Print(Message);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = 
        }
    }
}


@tuuguu177

tuuguu177
23 May 2024, 11:38 ( Updated at: 23 May 2024, 12:59 )

RE: RE: RE: RE: RE: How to create dynamic horizontal line

PanagiotisCharalampous said: 

tuuguu177 said: 

PanagiotisCharalampous said: 

tuuguu177 said: 

PanagiotisCharalampous said: 

Hi there,

You can use DrawHorizontalLine to draw horizontal lines.

Best regards,

Panagiotis

but how to make it dynamic. Dynamic means Horizontal lines follow price.

Hi there, 

Just draw the line at the specific price you want on each tick. If you use the same name for your line it will replace the previous one, making it dynamic.

Best regards,

Panagiotis

Could you please show me the code? Sorry i am super newbie at coding. Thank you very much

There is example code in the documentation. Try doing this yourself and let us know where you have questions and what is blocking you to move further.

could you pls share example code documentation for making dynamic horizontal line?


@tuuguu177

ncel01
23 May 2024, 11:55

Hello,

You should call Chart.DrawHorizontalLine() inside Calculate() and use the current price (Symbol.Bid or Symbol.Ask) as reference. See below.

I hope it helps.

using cAlgo.API;

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None)]
    public class dynamic_HLine : Indicator
    {
        protected override void Initialize()
        {
        }

        public override void Calculate(int index)
        {
            var distanceInPips = 200;
            var highPrice = Symbol.Bid + distanceInPips * Symbol.PipSize;
            var lowPrice = Symbol.Bid - distanceInPips * Symbol.PipSize;

            Chart.DrawHorizontalLine("horizontalLineAbove", highPrice, Color.Blue);
            Chart.DrawHorizontalLine("horizontalLineBelow", lowPrice, Color.Red);
        }
    }
}

@ncel01

tuuguu177
23 May 2024, 12:17 ( Updated at: 23 May 2024, 12:59 )

RE: How to create dynamic horizontal line

ncel01 said: 

Hello,

You should call Chart.DrawHorizontalLine() inside Calculate() and use the current price (Symbol.Bid or Symbol.Ask) as reference. See below.

I hope it helps.

using cAlgo.API;namespace cAlgo{    [Indicator(AccessRights = AccessRights.None)]    public class dynamic_HLine : Indicator    {        protected override void Initialize()        {        }        public override void Calculate(int index)        {            var distanceInPips = 200;            var highPrice = Symbol.Bid + distanceInPips * Symbol.PipSize;            var lowPrice = Symbol.Bid - distanceInPips * Symbol.PipSize;            Chart.DrawHorizontalLine("horizontalLineAbove", highPrice, Color.Blue);            Chart.DrawHorizontalLine("horizontalLineBelow", lowPrice, Color.Red);        }    }}

OH, hello thank you thank you I love you bro 


@tuuguu177