• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 Simon Investimens, Today, 03:26 AM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Marco  
              Started by fx.practic, Today, 05:15 AM
              0 responses
              3 views
              0 likes
              Last Post fx.practic  
              Started by guidoisot, Today, 05:03 AM
              0 responses
              2 views
              0 likes
              Last Post guidoisot  
              Started by EnveousColnago, Yesterday, 06:58 AM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Started by owreivmatot, Today, 01:38 AM
              0 responses
              1 view
              0 likes
              Last Post owreivmatot  
              Working...
              X