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

Changing pen widths according to conditions

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

    Changing pen widths according to conditions

    Hello all,
    I'm attempting to change the pen width of my indicator according to certain conditions. When the conditions are met I want a fatter line and when conditions are no longer valid I'd like the line to narrow. Here is my code. Any suggestions would be appreciated.
    Also in this example I'm using the WilliamR indicator. I'd like to be able to add additional indicators in the Parameters. Can someone give me an example of how that is done?
    Thanks
    Attached Files

    #2
    Hello CaptainAmericaXX,

    Thank you for your note.

    You would not be able to set the plot width per a bar as you are wanting to do. The Plots Pen will affect the entire plot series from beginning to end.
    Your code will work but when the condition is true to change the width, it will affect the entire plot in the panel.

    You would need to do some custom drawing in the Plot() override in order to see this kind of plot.
    Please note that this kind of programming is unsupported with NinjaTrader, however you can view a sample on the plot override from either the HeikenAshi Indicator or from the SamplePlot Indicator, Tools -> Edit NinjaScript -> Indicators...
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I'm attempting to change the pen width of my indicator according to certain conditions. When the conditions are met I want a fatter line and when conditions are no longer valid I'd like the line to narrow. Here is my code. Any suggestions would be appreciated.
      This is a very interesting question, Captain, and I learnt a lot from Cal's reply. Thanks to both of you.

      I've thought of this sort of problem before and I have a suggestion as per this example.

      Just say I have have two conditions A and B and I want an EMA to be red width 3 for condition A and blue width 6 for condition B (or A 'else' - when the condition isn't valid). The idea is to 'add' two plots. This example illustrates:

      Code:
      protected override void Initialize()
              {
                  Add(new Plot(new Pen(Color.Red, 3), PlotStyle.Line, "Thickness3"));
                  Add(new Plot(new Pen(Color.Blue, 6), PlotStyle.Line, "Thickness6"));
                  Overlay    = true;
              }
      
      
              protected override void OnBarUpdate()
              {
      
                  if(Rising( EMA(20) ) ) 
                      
                  Thickness3.Set(EMA(20)[0]);
                    
                  else
                  
                  Thickness6.Set(EMA(20)[0]);
      Please see attached image.

      I've done this quickly and the one disadvantage is that the line is not continuous, but this isn't a huge matter. I think with further refinement the gaps can be filled in certain ways.

      Hopes this helps.
      Attached Files
      Last edited by arbuthnot; 11-06-2014, 08:23 AM.

      Comment


        #4
        Arbuthnot,

        Thank you for your post.

        This can be expanded to the colors that CaptainAmerica was using instead.

        You would want to keep the plots set for every bar but take that rising logic and set the opposite plots color to transparent so that we hide the plot we don't want to see.
        Code:
        Plot0.Set(EMA(20)[0]);
        Plot1.Set(EMA(20)[0]);
        		
        if(Rising(EMA(20)))
        	PlotColors[1][0] = Color.Transparent;
        else
                PlotColors[0][0] = Color.Transparent;
        Attached Files
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Thanks, Cal, that's brilliant. I see how you've made it continuous and I thought 'transparent' came into it somewhere!

          Thanks very much.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          603 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          23 views
          0 likes
          Last Post xiinteractive  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          22 views
          0 likes
          Last Post Pattontje  
          Started by flybuzz, 04-21-2024, 04:07 PM
          17 responses
          230 views
          0 likes
          Last Post TradingLoss  
          Working...
          X