Visual disable function does not work

Created at 02 Feb 2024, 01:07
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!
HH

hhhvons

Joined 28.12.2023

Visual disable function does not work
02 Feb 2024, 01:07


Hi there,

I made an indicator but somehow object visual function is not working.

Why is that happen? Am I missing something?

Thanks

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(IsOverlay = true, AccessRights = AccessRights.None)]
    public class OpenCountDownClocks : Indicator
    {

        private TextBlock newYorkCountdownText;
        private TextBlock frankfurtCountdownText;

        [Parameter("Horizontal Alignment", DefaultValue = HorizontalAlignment.Left)]
        public HorizontalAlignment HorizontalPos { get; set; }

        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top)]
        public VerticalAlignment VerticalPos { get; set; }
        
        public DateTime newYorkTime;
        
        public DateTime LondonTime;
        
        public DateTime frankfurtTime;

        protected override void Initialize()
        {
       frankfurtCountdownText = new TextBlock
    {
        Padding = "30 0 0 0",
        ForegroundColor = "D21C1B21",
        FontSize = 16,
        FontWeight = FontWeight.Normal,
        FontStyle = FontStyle.Normal,
        FontFamily = "Digital-7",
        HorizontalAlignment = HorizontalPos,
        VerticalAlignment = VerticalPos,
    };

    Chart.AddControl(frankfurtCountdownText);
    
            newYorkCountdownText = new TextBlock
    {
        Padding = "30 0 0 0",
        ForegroundColor = "D21C1B21",
        FontSize = 16,
        FontWeight = FontWeight.Normal,
        FontStyle = FontStyle.Normal,
        FontFamily = "Digital-7",
        HorizontalAlignment = HorizontalPos,
        VerticalAlignment = VerticalPos,
    };
            
            

            Chart.AddControl(newYorkCountdownText);

            Timer.Start(1); // 1秒ごとに更新
        }

        public override void Calculate(int index)
        {
            // Calculateメソッドは通常、インジケーターのロジックを計算するために使用されますが、この例では時間の更新のみ行います。
            UpdateClock();
        }

        private void UpdateClock()
        {
            DateTime currentTime = DateTime.Now;

            UpdateFrankfurtCountdown(currentTime);
            
            UpdateNewYorkCountdown(currentTime);
           
        }
        
       private void UpdateNewYorkCountdown(DateTime currentTime)
{
    // ニューヨーク市場のオープン時間(例:午前9時30分)
    int openHour = 8;
    int openMinute = 30;

    // 現在のローカル時刻をニューヨークのタイムゾーンに変換
    DateTime currentNewYorkTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(currentTime, "Eastern Standard Time");
    
    // 現在の時刻と市場のオープン時刻を比較
    DateTime newYorkOpenTimeToday = currentNewYorkTime.Date.AddHours(openHour).AddMinutes(openMinute);
    DateTime nextNewYorkOpenTime;

    if (currentNewYorkTime < newYorkOpenTimeToday)
    {
        // 今日のオープン時間までのカウントダウン
        nextNewYorkOpenTime = newYorkOpenTimeToday;
    }
    else
    {
        // 翌日のオープン時間までのカウントダウン
        nextNewYorkOpenTime = newYorkOpenTimeToday.AddDays(1);
    }

    // カウントダウンの計算
    TimeSpan countdown = nextNewYorkOpenTime - currentNewYorkTime;

    // カウントダウンをテキストブロックに設定
    newYorkCountdownText.Text = "NewYork Opens in: " + countdown.ToString(@"hh\:mm\:ss");
    newYorkCountdownText.Margin = "0 20 25 0";
}

private void UpdateFrankfurtCountdown(DateTime currentTime)
{
    // フランクフルト市場のオープン時間(例:午前1時)
    int openHour = 9;

    // 現在のローカル時刻をフランクフルトのタイムゾーンに変換
    DateTime currentFrankfurtTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(currentTime, "W. Europe Standard Time");
    
    // 現在の時刻と市場のオープン時刻を比較
    DateTime frankfurtOpenTimeToday = currentFrankfurtTime.Date.AddHours(openHour);
    DateTime nextFrankfurtOpenTime;

    if (currentFrankfurtTime < frankfurtOpenTimeToday)
    {
        // 今日のオープン時間までのカウントダウン
        nextFrankfurtOpenTime = frankfurtOpenTimeToday;
    }
    else
    {
        // 翌日のオープン時間までのカウントダウン
        nextFrankfurtOpenTime = frankfurtOpenTimeToday.AddDays(1);
    }

    // カウントダウンの計算
    TimeSpan countdown = nextFrankfurtOpenTime - currentFrankfurtTime;

    // カウントダウンをテキストブロックに設定
    frankfurtCountdownText.Text = "Frankfurt Opens in: " + countdown.ToString(@"hh\:mm\:ss");
    frankfurtCountdownText.Margin = "0 5 25 0";
}
    }
}

@hhhvons