if else statement

Created at 30 Jun 2022, 11:42
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!
RJ

rjalopes

Joined 01.07.2021

if else statement
30 Jun 2022, 11:42


so i have an indicator for round numbers that i can change the default pips value and works fine what i would like to is to have an if else  statement in the code that for 1 min charts the size of the line would be "2" but when i change to 15min chart the lines would be size "1" so that the indicator does not pop up as much in the 15min charts.

the code is simple and i just af to add a if else statement but i don´t know how to do this is ctrader can some help me with this ? Thank you.

 

Here is the code:

using System;
using cAlgo.API;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class PVSRARoundNumbers : Indicator
    {
        [Parameter(DefaultValue = 100)]
        public int StepPips { get; set; }

        protected override void Initialize()
        {
            double max = Bars.HighPrices.Maximum(Bars.HighPrices.Count);
            double min = Bars.LowPrices.Minimum(Bars.LowPrices.Count);

            double step = Symbol.PipSize * StepPips;
            double start = Math.Floor(min / step) * step;
            double half = step / 2;
            double quarter = step / 4;

            Color cWhole = Color.FromHex("#f09898");
            Color cHalf = Color.FromHex("#151313");
            Color cQuarter = Color.FromHex("#bcbcbc");

            for (double level = start; level <= max + step; level += step)
            {
                Print("{0} {1} {2}", level, level + half, level + quarter);

                Chart.DrawHorizontalLine("WholeLine" + level, level, cWhole, 2, LineStyle.Solid);
                Chart.DrawHorizontalLine("HalfLine" + level, level + half, cHalf, 1, LineStyle.Lines);
                Chart.DrawHorizontalLine("QuarterUpLine" + level, level + quarter, cQuarter, 2, LineStyle.Dots);
                Chart.DrawHorizontalLine("QuarterDownLine" + level, level - quarter, cQuarter, 2, LineStyle.Dots);
            }
        }

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

 


@rjalopes
Replies

firemyst
01 Jun 2023, 05:22

//Sample code to help you get started:

//Set the line size. If timeframe is "Minute", make it 2. Otherwise, make it 1.
int lineSize = (Chart.TimeFrame == TimeFrame.Minute ? 2 : 1);

for (double level = start; level <= max + step; level += step)
{
    Print("{0} {1} {2}", level, level + half, level + quarter);

    Chart.DrawHorizontalLine("WholeLine" + level, level, cWhole, lineSize, LineStyle.Solid);
    Chart.DrawHorizontalLine("HalfLine" + level, level + half, cHalf, lineSize, LineStyle.Lines);
    Chart.DrawHorizontalLine("QuarterUpLine" + level, level + quarter, cQuarter, lineSize, LineStyle.Dots);
    Chart.DrawHorizontalLine("QuarterDownLine" + level, level - quarter, cQuarter, lineSize, LineStyle.Dots);
}

 


@firemyst