Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Bar by bar backgound color

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

    Bar by bar backgound color

    Hello,

    Whenever I am in a position, I want my background color to reflect it.

    I need to have "CalculateOnBarClose = false" so that I execute on every tick.

    Now I didn't think it necessary to change BackColor on every single tick so I included a FirstTickOfBar qualifier thinking that it would only change the color once per bar when the bar opened.

    In operation, the color change occurs for only the first bar when I enter a position. Otherwise, it works as expected.

    Any ideas?

    Code:
     
           protected override void OnBarUpdate()
            {
                if(Historical) return;
                        
                if(stratPos > 0)
                {
                    if(FirstTickOfBar) BackColor = Color.AliceBlue;
                    swLow = swStop.ZigZagLow[0];
                    if(Bars.CurrentBid < swLow) CloseMyPosition();  
                }    
                
                if(stratPos < 0)
                {
                    if(FirstTickOfBar) BackColor = Color.MistyRose;
                    swHigh = swStop.ZigZagHigh[0];
                    if(Bars.CurrentAsk > swHigh) CloseMyPosition();                 
                }        
                
            }

    #2
    Hello TikDaddy,

    Thanks for your post.

    While the code you have may possibly change the background color, I could not say for sure as I do not know the values of stratPos.

    It would seem that the color for this can be changed on the first tick of a bar as long as stratPos is greater than 0. (to AliceBlue)

    On the bars where this is not working correctly, is the color being changed to MistyRose or is the color not changing at all?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChelseaB,

      Thank you for replying. Ninja staff is the best.

      On the first bar where I enter a position, the color change is correct. After that bar, the background changes back to the default background color.

      Does the code appear to be correct? Should the color stay constant until stratPos becomes 0?

      Comment


        #4
        Hi TikDaddy,

        From what I see in the code, yes, the background color should be changed on every bar as long as stratPos becomes 0 (or less).

        I recommend you add print statements and print the value of stratPos when the bar color is not changing.

        Prints will show in the Output window.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ChelseaB,

          If I remove the FirstTickOfBar qualifier, the code works fine. I don't think it is a big deal this way but I thought it would be less CPU intensive the way it was written originally.

          If you have any better method of doing it so that I don't set the color change on every tick, I'll be interested in hearing it.

          Comment


            #6
            Hello TikDaddy,

            Attached is a sample you can use as a proof of concept. Please import and run this and then look at the code for it.

            Just a tip, this doesn't change the background when then position is entered and exited on the same bar.

            I would need to see the rest of your code to find out what is going on. That or if you could add prints and send me the output so that I may see the values being used. Prints generally help to understand what your code is doing by showing you the values it is using at the time. This can help you to pin-point where things are breaking down.
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              ChelseaB,

              From your code it looks as if I should be able to change BackColor on the first tick of the bar instead of every tick. This is what I need.

              Thanks very much !!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by algospoke, Yesterday, 06:40 PM
              2 responses
              19 views
              0 likes
              Last Post algospoke  
              Started by ghoul, Today, 06:02 PM
              3 responses
              14 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              45 views
              0 likes
              Last Post jeronymite  
              Started by Barry Milan, Yesterday, 10:35 PM
              7 responses
              21 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by AttiM, 02-14-2024, 05:20 PM
              10 responses
              181 views
              0 likes
              Last Post jeronymite  
              Working...
              X