Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change Swing Plot Colors Based On Condition

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

    Change Swing Plot Colors Based On Condition

    I want to modify the Swing indicator so that the plot colors are set based on a condition.

    Can you provide a link or sample to help accomplish that?

    #2
    Hello ScorpioTravis,

    Thank you for the post.

    The swing can be duplicated and then edited by using the NinjaScript editor. To duplicate the file you would first need to open it and then right click in the file -> Save as.

    The swing is a fairly complicated indicator which can be pretty difficult to edit. We would likely need more specific details on what kind of conditions you are looking to make in order to provide more relevant help here.

    To color plots you can use PlotBrushes https://ninjatrader.com/support/help...ub=PlotBrushes



    I look forward to being of further assistance.

    Comment


      #3
      Jesse, I made a copy and modified it by adding the following lines at the end of the protected override void OnBarUpdate() section (CONDITION# = other indicator values):

      Code:
      {
      if (CONDITION1 && CONDITION2)
      {
      PlotColors[0][0] = Color.Transparent;
      PlotColors[1][0] = Color.Yellow;
      }
      else if (CONDITION3 && CONDITION4)
      {
      PlotColors[0][0] = Color.Cyan;
      PlotColors[1][0] = Color.Transparent;
      }
      else
      {
      PlotColors[0][0] = Color.Transparent;
      PlotColors[1][0] = Color.Transparent;
      }
      }
      It seems to work as expected, however, there are some yellow plots even though CONDITION1 and CONDITION2 are both false.

      I can't determine if that's caused by something in the original SWING code or if it's because of an error I made in the additional code logic for changing the colors.

      Update: I sent the indicator data used for the CONDITION#s to an output window, but it doesn't match what's on the chart and data box. I'm still investigating.
      Last edited by ScorpioTravis; 10-05-2021, 06:00 PM.

      Comment


        #4
        Hello ScorpioTravis,

        When you say that you sent the indicator data are you referring to the plot data from the indicator or are you using SwingLowBar/HighBar?

        For your conditions you would need to use a print to see what the values are on each bar where the conditions are both false.



        I look forward to being of further assistance.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello ScorpioTravis,

          When you say that you sent the indicator data are you referring to the plot data from the indicator or are you using SwingLowBar/HighBar?

          For your conditions you would need to use a print to see what the values are on each bar where the conditions are both false.



          I look forward to being of further assistance.
          Yes, I used PRINT to confirm that for some reason I have yet to determine, the CONDITION#s are both true even though on the chart they're both false.

          Comment


            #6
            Hello ScorpioTravis,

            Could you provide more details about the condition? Are you using indicator values and comparing against manually added indicators? That could be a situation where the chart may differ from the script.


            I look forward to being of further assistance.

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello ScorpioTravis,

              Could you provide more details about the condition? Are you using indicator values and comparing against manually added indicators? That could be a situation where the chart may differ from the script.


              I look forward to being of further assistance.
              I don't think I can sufficiently explain it without sending the indicators to you, and I don't expect you to review them.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              558 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X