• 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

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 stefanrvc, Today, 04:59 AM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Marco  
          Started by 7robert, Yesterday, 08:30 PM
          2 responses
          16 views
          0 likes
          Last Post NinjaTrader_Marco  
          Started by pjsmith, Today, 01:13 AM
          1 response
          15 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by yukashg, Yesterday, 09:56 PM
          1 response
          16 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by cutzpr, Yesterday, 09:19 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Working...
          X