Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Mirroring Color Plot with a text value

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

    Mirroring Color Plot with a text value

    I am trying to create a text version of KwikPop colors so that I can effectively use the KP ScoreCard Color in a strategy. I'm attaching some code to show what I tried to do. The first code sample comes from the KP indicator which paints color on bars or candles. I then took the code and simply recreated the same code logic after the first set, and substituted a double variable that I created and assigned a numeric value to the variable based on what color is being plotted. Please see the second code sample.

    Code:
    	if( sum >= 5 )
    	BarColor = Color.Blue;
    	else if( sum <= -5 )
    	BarColor = Color.Red;
    	else
    	BarColor = Color.Yellow;
    Code:
    	if( sum >= 5 )
    	Bias = 1.0;
    	else if( sum <= -5 )
    	Bias = -1.0;
    	else
    	Bias = 0.0;
    When I tested this indicator in a strategy, the "Bias" variable was not visible in the strategy when I used the indicator. I tried to add a properties section to make the variable visible like it is in some of my other strategies. The code would not compile when I added this last section in:

    Code:
    //		#region Properties
    //        [Description("")]
    //       [Category("Parameters")]
    //        public double Bias
    //        {
    //            get { return bias; }
    //            set { bias = Math.Max(1, value); }
    //        }			
    //		#endregion
    		}

    I commented it out so the code would compile. So my question is, "How can I make the variable "Bias" visible when I use this indicator in strategy. right now it isn't visible.
    Thanks
    DaveN
    Last edited by daven; 09-08-2008, 04:52 PM. Reason: Misspelling

    #2
    Hi daven,

    Good question. Please see this reference sample for how to do it: http://www.ninjatrader-support.com/v...ead.php?t=4991
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Mirroring plot value with text

      I followed the example you provided and I was able to redo the code so that the variable I had created based on the color of the bar is now exposed and available to be used in a strategy. I'm attaching a screen shot which shows it in a strategy condition.

      Now I've created a strategy using that indicator in a very simple test, "buy if the previous bar value was not blue and this bar value is blue, and sell if the previous bar value was not red and this bar is red. (Though I am using a value of "1" for a blue bar and a value of "-1" for a red bar and conditioning the previous bar test as less than 1 for a long condition and greater than 1 for a short condition.

      The indicator code compiled and the strategy code compiled but the strategy doesn't ever execute a trade. Is there a way to print out the value of the text indicator using the strategy wizard? (I suspect not.) I tried to open the code and simply put in a print statement, but when I try to print the value of the indicator text value, I get an error message saying that indicator text value name doesn't exist in the context of the code, (or something like that).
      How can it not exist when it is an integral part of the logic being used to decide to take a long or short position?
      DaveN
      Attached Files

      Comment


        #4
        Hello,

        Please post the code you are using.

        Generally, the error you are getting means that you have a scoping issue. Whatever you are using is not declared for that block of code most likely. Is there a spelling error? Is the variable declared in your Variable section? These are guesses without the code of course.
        DenNinjaTrader Customer Service

        Comment


          #5
          Suspect code

          Here is the code I am using. I have separate code which adds a variable and logic so that if the bar is going to plot "blue" then the the variable "KPSCTextval" is assigned a value of 1.0. Similarly if the bar is plotted "red" then the same variable takes on a value of -1.0. I created a second variable in the strategy, "sctextval" to assign the embedded variable value to which I thought would allow me to print that value, but running the code (which did compile) no trades are taken and no print statements are generated.
          It may be something in my indicator code, and if you need that I will post it.
          DaveN




          Code:
              /// <summary>
              /// Enter the description of your strategy here
              /// </summary>
              [Description("Enter the description of your strategy here")]
              public class DNKPScoreCardColorMod2 : Strategy
              {
                  #region Variables
                  // Wizard generated variables
                  private int profit = 6; // Default setting for Profit
                  private int stop = 8; // Default setting for Stop
                  // User defined variables (add any user defined variables below)
          		private double sctextval = 0 ;
                  #endregion
          
                  /// <summary>
                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                  /// </summary>
                  protected override void Initialize()
                  {
                      SetProfitTarget("", CalculationMode.Ticks, Profit);
                      SetStopLoss("", CalculationMode.Ticks, Stop, false);
          
                      CalculateOnBarClose = true;
                  }
          
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                      // Condition set 1
                      if (KPScoreCardText().KPSCTextval[1] < 1
                          && KPScoreCardText().KPSCTextval[0] == 1)
                      {
                          EnterLong(DefaultQuantity, "");
          	   sctextval = KPScoreCardText().KPSCTextval[0];
          	   Print (sctextval);
                      }
          
                      // Condition set 2
                      if (KPScoreCardText().KPSCTextval[1] > -1
                          && KPScoreCardText().KPSCTextval[0] == -1)
                      {
                          EnterShort(DefaultQuantity, "");
          	   sctextval = KPScoreCardText().KPSCTextval[0];
          	   Print (sctextval);
                      }
                  }

          Comment


            #6
            Hello,


            Please post the indicator and the strategy files in compiled form and I'll take a look at it and see if I can tell what is wrong.
            DenNinjaTrader Customer Service

            Comment


              #7
              Mirroring Plots - Compiled Code

              I've attached the code examples you requested. The compiled export contains an indicator file which actually adds a text variable that maps to the color of the bar. The strategy code uses that indicator to execute a long or sort transaction based on what color the current bar is and what color the previous bar was.
              Thanks
              DaveN
              Attached Files

              Comment


                #8
                Daven,

                You are working outside the scope of what we can offer support for. You are making your own classes and such. What we can support is the simple modification of an indicator that changes BarColor to also have an additional variable that can be used in a strategy to notify that such a color change happened. This is done through this reference sample: http://www.ninjatrader-support.com/v...ead.php?t=4991
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Using the Boolean Series Example

                  Ben,
                  I downloaded and examined the Boolean Series example you provided. I had already received this sample yesterdat and tried to do the same thing but using a data series since the value I was trying to expose had three potential cases, (positive or +1, negative or -1, and neutral or 0). I tried to further experiment with the boolean series example but it isn't at all clear to me how that example does anything useful. When I tried to use it in a strategy, there was no accessable value to base any logic on. Further, at the end of the example there is a step which makes no sense to me. The step where the exposed variable is set to close[0]. Why is that done? Also, how does one use this in a strategy? I understand that by setting a boolean variable to be true for bullish or true for bearish, based on a MACD crossover one can have a generally bullish or bearish trigger, but how can I access that variable in a strategy. When I try to use it in a strategy, the bullish or bearish variables don't even show up?

                  Code:
                  // MACD Crossover: Fast Line cross below Slow Line
                  else if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
                      {
                        // Paint the current price bar magenta to draw our attention to it
                  	BarColor = Color.Magenta;
                  				
                  /* This crossover condition is considered bearish so we set the "bearIndication" BoolSeries object to true.
                  We also set the "bullIndication" object to false so it does not take on a null value. */
                  	bullIndication.Set(false);
                  	bearIndication.Set(true);
                  }
                  			
                  // MACD Crossover: No cross
                  else
                  {
                  /* Since no crosses occured we are not receiving any bullish or bearish signals so weset our BoolSeries objects both to false. */
                  	bullIndication.Set(false);
                  	bearIndication.Set(false);
                  }
                  		
                  	// We set our variable to the close value.
                  [COLOR="Red"]	exposedVariable = Close[0];[/COLOR]
                  Last edited by daven; 09-10-2008, 06:58 PM. Reason: Code sample was hard to read.

                  Comment


                    #10
                    Hello,

                    exposedVariable = Close[0]; is included just to show you that you can still do normal operations/assignments while you are doing a boolseries operation. You can ignore it...

                    The value of the sample is that you can set a boolean series to true or false for that designated bar and refer back to it using a bar reference/index value.

                    This link may help:
                    DenNinjaTrader Customer Service

                    Comment


                      #11
                      daven,

                      I think you are misunderstanding. The SampleBoolSeries reference comes with two files. One for the indicator and one for the strategy. The indicator file is the one with more logic. That is what you need to implement in your own indicator. The strategy will then just utilize what is done in the indicator. Nothing fancy in the strategy.

                      You can replace the BoolSeries with a DataSeries, an IntSeries, anything you want. They are interchangeable.

                      As Ben mentioned, the exposedVariable is to show you how to access a different value. IDataSeries or similar objects are already in sync with the bars objects when you run access them from a strategy, but when you try to access a variable that has simply been exposed it is not necessarily in sync with the bars. This reference sample demonstrates how to get them in sync with each other, but it does not pertain to your case. What matters to you is the use of the BoolSeries and how it is accessed from the strategy.

                      For you, just create a DataSeries, store your -1, 0, 1 values into it when appropriate and simply access that series from the strategy.

                      For example. If your indicator was called Indicator and your DataSeries was called Paint then do this in your strategy:
                      Code:
                      if (Indicator().Paint[0] == -1)
                           // Do something;
                      In your indicator instead of .Set(false) or .Set(true) you would just do:
                      Code:
                      Paint.Set(-1);
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        How to expose the variable in the Strategy Wizard

                        Josh,
                        Using the
                        Sample Boolean indicator and strategy as a guide I have been able to create a functional strategy using a KwikPop function. However, I can only access that function by writing a strategy in NinjaScript using the following convention:
                        Code:
                        if (orderId.Length == 0 && atmStrategyId.Length == 0 &&
                        	KPScoreCardText().BullIndication[0]
                        The properties statement for the indicator looks like this:
                        Code:
                        // Important code segment in the Properties section. Please expand to view.
                                #region Properties
                        		
                        // Creating public properties that access our internal BoolSeries allows external access to this indicator's BoolSeries
                        		
                        [Browsable(false)]
                        [XmlIgnore()]
                        public BoolSeries BearIndication
                                {
                                    get { return bearIndication; }
                        // Allows our public BearIndication BoolSeries to access and expose our interal bearIndication BoolSeries
                                }
                        		
                        [Browsable(false)]
                        [XmlIgnore()]
                        public BoolSeries BullIndication
                                {
                                    get { return bullIndication; }	
                        // Allows our public BullIndication BoolSeries to access and expose our interal bullIndication BoolSeries
                                }
                        Why is this indicator variable not visible when I use a strategy wizard to construct the logic? It seems I have properly exposed it, as illuminated in the sample test I downloaded?
                        Thanks
                        DaveN

                        Comment


                          #13
                          Which indicator variable are you referring to? I only see code for the BoolSeries. This is why you have access to the BoolSeries in your strategy.

                          To expose the variable you need to do the code pertaining to that variable:
                          Code:
                          [Browsable(false)]
                          [XmlIgnore()]
                          public double ExposedVariable
                          {
                              // We need to call the Update() method to ensure our exposed variable is in up-to-date.
                              get { Update(); return exposedVariable; }
                          }
                          There are two distinct concepts revealed in that reference sample. If you want the variable you need to use the code related to the variable. If you want a BoolSeries, use the code for the BoolSeries. You can exchange the BoolSeries with a DataSeries or IntSeries, anything else if you desire.

                          Doing this will not work with the Strategy Wizard. You are already custom coding so you are already working outside the confines of the Strategy Wizard.
                          Last edited by NinjaTrader_JoshP; 09-17-2008, 10:39 AM.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Exposing the Indicator in the strategy wizard

                            Josh,
                            I think I need to rephrase the question. Having written a custom indicator which has two states (true and false), is it possible to get at those two states when using the indicator in a stategy wizard? The only reason I custom coded the stategy was because I couldn't see the variable I was looking for when I tried to use it in the wizard. As an example using the strategy wizard, say I want to go long when price closes above the bollinger upperband. I can set that up in the wizard and merely select the "UpperBand" as the plot variable I want to compare to the close price. When I try to use the ScoreCardColorText indicator I created, when I put it in the left side of the strategy wizard I would like to make it equal to "true" on the right side of the wizard but the only thing that shows when I pull up the indicator on the left side, is the indicator value itself. There is no opportunity to equate "BullishIndication" to true on the right side of the wizard condition. Perhaps the only way to do this is custom coding, which is fine I guess since I'm doing it now, but the wizard is so much easier.
                            Guess I might be a little lazy.
                            Thanks
                            DaveN

                            Comment


                              #15
                              Daven,

                              Nope, it will not show up in the Strategy Wizard. The reason the Bollinger Band plots show up is because they are actual indicator plots that are drawn. If you wish to do it this way you can instead use an indicator plot and just set the values as either 1, 0, or -1. Then compare against these values based on what the interpretation for them would be.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              18 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Javierw.ok  
                              Started by timmbbo, Today, 08:59 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post bltdavid  
                              Started by alifarahani, Today, 09:40 AM
                              6 responses
                              41 views
                              0 likes
                              Last Post alifarahani  
                              Working...
                              X