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

Change color of indicator via other indicator

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

    Change color of indicator via other indicator

    Hello. I add my indicator in strategy script.
    Code:
    Add(MyIndex(MyIndex2));
    MyIndex(MyIndex2).Panel=3;
    MyIndex(MyIndex2).ScaleJustification=ScaleJustification.Right;
    Than added indicator on previous indicator
    Code:
    Add(UPmDW(MyIndex(MyIndex2)));
    UPmDW(MyIndex(MyIndex2)).Panel=3;
    UPmDW(MyIndex(MyIndex2)).ScaleJustification=ScaleJustification.Left;
    This indicator should change color of MyIndex(MyIndex2)) indicator. So, it's like indicator on indicator.
    BUT! When I used something like this BarColor = Color.Green; UPmDW colors main instrument chart bars, but I need it change colors of MyIndex(MyIndex2)). Even adding DrawOnPricePanel = false; didn't help.

    #2
    Hello alexstox,

    Thank you for your post.

    Can you provide the full indicator file for review?

    Comment


      #3
      Well UpmDW works fine when I just add it to instrument. But as NT doesn't have opportunity to add instruments to Strategy Analyzer, I add those instruments via MyIdex(). That's why I need to know how to color indicator via indicator in strategy script.

      UpmDW
      Code:
      		#region Variables
      .................................................
      /* We declare two BoolSeries objects here. We will expose these objects with the use of 
      public properties later. When we want to expose an object we should always use the associated
      IDataSeries class type with it. This will ensure that the value accessed is kept up-to-date. */
      private BoolSeries uPm;
      private BoolSeries dOWNm;
      		
      		#endregion
      
      protected override void Initialize()
      		{
      ..................................................................
      		uPm = new BoolSeries(this);
      		dOWNm = new BoolSeries(this);
      			
      		}
      
      		protected override void OnBarUpdate()
      		{
      ................................................................
      if (some conditions) do smth
      ..................................................................
      			if(momUP==1) 
      			{
      				BarColor = Color.Green;
      //				Plots[0].Pen = new Pen(Color.Green);
      				dOWNm.Set(false);
      				uPm.Set(true);
      			}
      				
      			if(momDW==1) 
      			{
      				BarColor = Color.Red;
      //				Plots[0].Pen = new Pen(Color.Red);
      				dOWNm.Set(true);
      				uPm.Set(false);
      			}
      		}
      	
      			// FormatPriceMarker method of a custom indicator
      		public override string FormatPriceMarker(double price)
      		{
      			// Formats price values to 4 decimal places
      			return price.ToString("N4");
      		}
      
      		#region Properties
      		/// <summary>
      		/// </summary>
      		.............................
      ........................................................
      		//Creating public properties that access our internal BoolSeries allows external access to this indicator's BoolSeries
      		[Browsable(false)]
              [XmlIgnore()]
              public BoolSeries UPm
              {
                  get { return uPm; }	//Allows our public BearIndication BoolSeries to access and expose our interal bearIndication BoolSeries
              }
      		
      		// Creating public properties that access our internal BoolSeries allows external access to this indicator's BoolSeries
      		[Browsable(false)]
              [XmlIgnore()]
              public BoolSeries DOWNm
              {
                  get { return dOWNm; }	//Allows our public BearIndication BoolSeries to access and expose our interal bearIndication BoolSeries
              }
      	
      		#endregion
      In strategy
      Code:
      protected override void Initialize()
              {
      .......................
      Add(MyIndex(MyIndex2));
      MyIndex(MyIndex2).Panel=3;
      MyIndex(MyIndex2).ScaleJustification=ScaleJustification.Right;
      
      Add(UPmDW(MyIndex(MyIndex2)));
      UPmDW(MyIndex(MyIndex2)).Panel=3;
      UPmDW(MyIndex(MyIndex2)).ScaleJustification=ScaleJustification.Left;
      ........................................
       protected override void OnBarUpdate()
              {
      ...........................................
      if (UPmDW(MyIndex(MyIndex2)).DOWNm[0]) 
      ...........................................
      if (UPmDW(MyIndex(MyIndex2)).UPm[0]
      ..........................................

      Comment


        #4
        Well, I think I know the problem. Still need your advise.
        If I use indicator1 on instrument I can use Close[0].
        BUT if I use indicator1 on indicator2 I can't use Close[0], I should use value of this indicator2: MyIndex()[0]. Is it right?

        Comment


          #5
          In this case how can I define value of Indicator2 in Indicator1? Because Indicator1 can be used in different indicators.

          Should I use Input[0]?
          Last edited by alexstox; 02-14-2014, 05:26 AM.

          Comment


            #6
            Hello alexstox,

            Correct, using an Indicator's value inside of your calculations you may want to use Input[0].



            Please note that BarColor is only going to change the color of the Price Bar, not an indicators plots. If you want to change the color of a Plot (indicator) you may want to try to use PlotColors.
            JCNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_JC View Post
              Hello alexstox,

              Correct, using an Indicator's value inside of your calculations you may want to use Input[0].



              Please note that BarColor is only going to change the color of the Price Bar, not an indicators plots. If you want to change the color of a Plot (indicator) you may want to try to use PlotColors.
              http://www.ninjatrader.com/support/h...plotcolors.htm
              Thank you. So, let see my case.
              1) There is Indicator2 in my strategy script. I want to add Indicator1 in script.
              Indicator1 track value of Indicator2.
              So, in Indicator1 I use Input[] that represents value of every bar of future instrument (indicator or not) and will define Close[] for stocks and Value[] for indicators?

              2) How to use PlotColors in Indicator1, if I need to change Indicator2 color? Otherwise I need to change color of indicator, to which Indicator1 will be added.

              Comment


                #8
                Hello alexstox,

                1. Inside of Indicator1 if you pass the values of Indicator2, you will not be able to access the Close price of the Stock since by default inside of NinjaTrder you are only able to pass it 1 IDataSeries.

                You may want to either add another Data Series to pass it both the Price data and the Indicator2 Data Series, otherwise you may want to check these values inside of the Strategy.

                2. Changing a PlotColor for Indicator2 inside of Indicator1 would be possible but it would not do anything since calling an Indicator inside of another indicator will only get values and not visually display anything.

                If you wanted to change this inside of the strategy since a strategy can add the indicator visually here is a post that gives you an example of how this can be done.

                JCNinjaTrader Customer Service

                Comment


                  #9
                  I wrote this
                  protected override void OnBarUpdate()
                  Code:
                          {.............
                  if(UPmDW(MyIndex(MyIndex2)).DWm[0]) MyIndex(MyIndex2).Plots[0].Pen.Color=Color.Red;
                  if(UPmDW(MyIndex(MyIndex2)).UPm[0]) MyIndex(MyIndex2).Plots[0].Pen.Color=Color.Green;
                  ...........................
                  1) But trough all history MyIndex() is only red.
                  2) UPmDW() indicator also draws triangles and lines on master chart, it should draw it on MyIndex() chart.
                  DrawOnPricePanel = false; in UPmDW() code didn't help.

                  Comment


                    #10
                    Hello alexstox,

                    1. This is most likely due to your first condition being true so the entire plot is going to be set to "red".

                    If you wanted to change the color of the Plot to multiple colors then you would have to add this logic inside of the Indicator and use PlotColors instead of the Strategy.

                    2. Where did you place DrawOnPricePanel in UPmDW?
                    JCNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_JC View Post
                      Hello alexstox,

                      1. This is most likely due to your first condition being true so the entire plot is going to be set to "red".

                      If you wanted to change the color of the Plot to multiple colors then you would have to add this logic inside of the Indicator and use PlotColors instead of the Strategy.

                      2. Where did you place DrawOnPricePanel in UPmDW?
                      1. You mean that it change color live, not through history?
                      But how to change color of MyIndex() in UPmDW() if UPmDW()'s script doesn't know to which data it will be added? How can I use PlotColors in this case?

                      If there is no solution, can I change the color and thickness of master instrument bars contour?

                      2. I've found mistake. I add DrawOnPricePanel=false in UPmDW().

                      Comment


                        #12
                        Hello alexstox,

                        1. Changing the Color of the Pen will change the color of the entire plot so it will not change Historically.

                        You may see my Post #6 for a link to our Help Guide that demonstrates how you may use the PlotColors to change the color of your Plots Historically.

                        Note this has to be done inside of the Indicator not the strategy.
                        JCNinjaTrader Customer Service

                        Comment


                          #13
                          Yes. than I asked
                          How to use PlotColors in Indicator1, if I need to change Indicator2 color? Otherwise I need to change color of indicator, to which Indicator1 will be added.
                          and you answered
                          Changing a PlotColor for Indicator2 inside of Indicator1 would be possible but it would not do anything since calling an Indicator inside of another indicator will only get values and not visually display anything
                          So, we reach an impasse

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by nandhumca, Yesterday, 03:41 PM
                          1 response
                          12 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by The_Sec, Yesterday, 03:37 PM
                          1 response
                          11 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by vecnopus, Today, 06:15 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post vecnopus  
                          Started by Aviram Y, Today, 05:29 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post Aviram Y  
                          Started by quantismo, 04-17-2024, 05:13 PM
                          3 responses
                          27 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Working...
                          X