Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Blinking Chart Background

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Blinking Chart Background

    Hello

    I have quite a lot of charts with a custom strategy on my screens and whenever there's a trading signal my strategy will put an arrow on the corresponding chart and generate a sound.

    What I'd like to do to save some time is to include a code snippet into my strategy that additionally makes the chart "blink" while there's an active signal on it.

    By blinking I mean that the chart background color should change between white and gray in a 2 second interval during the 60 seconds the signal is active (I'm trading on a 1 minute chart and a signal is cancelled if it is not triggered within this 60 second interval). I've already played with the background color using

    BackColorAll = Color.White etc

    but the tricky part is to make the background color change every 2 seconds, thus creating the blinking effect.

    How should I go about this?

    Thanks

    #2
    laocoon,

    You will need to add a "1 second" dataseries to your indicator in order to get the granularity to keep track of something like this.



    Then, you can simply check if BarsInProgress == 1, if so increment a counter until its equal 2, then reset the counter and change color. Once the signal occurs for that minute, you just need to reset the signal flag the next minute.

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      AdamP

      Thanks a lot for that. Could I ask you to have a look at the following code. It makes the chart background color change every 2 seconds.

      public class ChartBlink : Indicator
      {
      #region Variables
      // Wizard generated variables
      private int xSeconds = 2; // Default setting for XSeconds
      private bool myCondition = false; // Default setting for MyCondition
      // User defined variables (add any user defined variables below)
      private DateTime conditionTime;
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      Overlay = true;
      CalculateOnBarClose = false;

      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      if(MyCondition)
      {
      conditionTime = DateTime.Now;
      myCondition = false;
      }

      if (DateTime.Compare(conditionTime.AddSeconds(600), DateTime.Now) >= 0) //Chart flashing is active for the first 600 seconds after setting MyCondition = true.
      {
      if (DateTime.Now.Second % xSeconds == 0) //xSeconds controls how often the chart background changes to Gray
      {
      for (int x = 0; x < CurrentBar; x++)
      BackColorAllSeries[x] = Color.Gray;
      }

      else
      {
      for (int x = 0; x < CurrentBar; x++)
      BackColorAllSeries[x] = Color.White;
      }
      }

      else //Sets back to white after done flashing
      for (int x = 0; x < CurrentBar; x++)
      BackColorAllSeries[x] = Color.White;

      }


      What I'm trying to do now is to call the indicator from my strategy to make the chart backgound of the market with a trading signal blink while the signal is valid (ie during the duration of the most recent 10 minute bar). (The strategy also draws a black diamond above the bar that gave the signal).

      if (my conditions here)
      {
      DrawDiamond("BlackDiamondLong" + CurrentBar, false, 0, High[0]+ 3*(TickSize), Color.Black);
      MyCondition = true;

      }

      My question now is: how can I call the ChartBlink indicator from my strategy? I'm not sure how to link the "MyCondition" part of the (strategy) code to the ChartBlink indicator.

      Thanks a lot for your help.

      Comment


        #4
        laocoon,

        I would suggest adding your blinking code to the indicators you want to use it as this would be the surest way to get it to work correctly.

        Otherwise, here is a reference sample : http://www.ninjatrader.com/support/f...ead.php?t=4991

        The main issue here is you will have to have an indicator call another indicator before this may work. There is no way to link the MyCondition across separate indicator instances.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by geddyisodin, Yesterday, 05:20 AM
        8 responses
        49 views
        0 likes
        Last Post geddyisodin  
        Started by DayTradingDEMON, Today, 09:28 AM
        3 responses
        19 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Stanfillirenfro, Today, 07:23 AM
        9 responses
        23 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by George21, Today, 10:07 AM
        0 responses
        8 views
        0 likes
        Last Post George21  
        Started by navyguy06, Today, 09:28 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X