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

Exposing and Using a Variable in an Indicator

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

    Exposing and Using a Variable in an Indicator

    I have an indicator which I am working on that characterizes the momentum and direction of a particular bar or series of bars. It is really simple stuff, shades of blue when momentum is up, and shades of red when momentum is down. I've also created a related dataseries to assign a number to the bar color so that eventually I could use it in a strategy. The bar coloring works, but when I try to use the related bar number to paint an arrow at the first occurrence of a blue or red bar, I get a funny compile error. Here is what I am doing:

    Set the DataSeries and initialize it:
    Code:
            #region Variables
            // Wizard generated variables
    			private DataSeries bCMText;
    			private double exposedVariable;
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose	= true;
                Overlay		= true;
                PriceTypeSupported	= false;
    			
                 bCMText = new DataSeries(this);
    			
    
    	// Initialize all variables
    	bCMText.Set(0);
    Then I paint the bar color and assign a number to the associated data series variable:
    Code:
    if (Close[0] >= Open[0])
    	{
    	BarColor = Color.Blue;
    	bCMText.Set(3) ;
    All of the above codes just fine and works just fine, (though for some reason I have to take the indicator off the chart and put it back on if the chart is updated manually, but that is a different issue. Here's where I have the problem. When I try to use the variable to decide if an arrow shoud be drawn, I get a weird error message, " Operator "&&" cannot be applied to perands of type "bool" and "double", yet I think that gets done in strategies all the time, so I'm confused ast to why the following code line gets this error message.
    Code:
    if (bCMText[1] <= 1 && bCMText[0] = 3)
    	{			
    	DrawArrowUp("MyArrowUp", 0, Low[0], Color.Lime);
    	}
    	else
    	{
    	DrawDot("MyDot", true, 0, Low[0] - 4 * TickSize, Color.Red);
    	}
    	exposedVariable = Close[0];
    By the way, the exposed variable is there in an attempt to make the bCMText variable visible in a databox to help me troubleshoot it, but for reasons I don't understand, I can't seem to make that variable visible in a databox, though it can be used as a variable when I set up a strategy.
    I appreciate you looking at the code and giving me some guidance.
    Thanks
    DaveN

    #2
    Originally posted by daven View Post
    I've also created a related dataseries to assign a number to the bar color so that eventually I could use it in a strategy. The bar coloring works, but when I try to use the related bar number to paint an arrow at the first occurrence of a blue or red bar, I get a funny compile error.
    If the indicator value is a plot, then it's easily accessible from a strategy, but you need to call the indicator first. Plots are also the only values that will appear in data boxes. Example of accessing a specific plot (Diff) from MACD:

    double myIndyValue = MACD(12, 24, 3).Diff[0];

    If the indicator value is not a plot (like yours is only a DataSeries), then you must add additional code to the properties region in order to access it from other scripts. The following sample can help you expose non-plot values.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      DaveN,

      As for your compile error it's here if (bCMText[1] <= 1 && bCMText[0] = 3), you need == 3.

      VT

      Comment


        #4
        Thanks for spot VTTrader.

        For comparison you need double equal ==
        Single equal sign is used for assignment.


        Dave, in addition to resolving compile error, make sure you are following all guidelines in that sample on exposing non plot values.
        Last edited by NinjaTrader_RyanM1; 11-22-2011, 11:44 AM.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks Ryan, I mssed the second part of your message, and deleted my second question until I could check out your sample reference, but you were too fast for me. So it has to be a plot to show in the data box, or a print to the output box. I originally created this text value by making it a plot but giving it a transparent color because if I made it visible it messed up the chart by forcing it to include a small number on the same chart as the instrument itself. Is there a way to make it a plot again, but force it to plot in another panel, so it doesn't distort the main instrument chart?
          DaveN

          Comment


            #6
            Thanks VTrader, missed that it was your response the first time around. I appreciate your help.
            DaveN

            Comment


              #7
              Indicators are placed in only one panel. If the value you want to check is much different than the other plots in the indicator, then best is printing it or placing it in a separate indicator that can be in its own panel.

              If it's just a single integer, may also me worthwhile using DrawText() above each bar.
              Last edited by NinjaTrader_RyanM1; 11-22-2011, 11:53 AM.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                I'll try the draw text so I can see it on all the bars. Appreciate your help.
                Thanks again.
                DaveN

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bmartz, 03-12-2024, 06:12 AM
                5 responses
                32 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by Aviram Y, Today, 05:29 AM
                4 responses
                13 views
                0 likes
                Last Post Aviram Y  
                Started by algospoke, 04-17-2024, 06:40 PM
                3 responses
                28 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by gentlebenthebear, Today, 01:30 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by cls71, Today, 04:45 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X