Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Previous Bar Strategy Question

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

    Previous Bar Strategy Question

    When writing a Strategy Script, how can I test for the Background Color of the chart that was used on the Previous Bar?

    Thanks,

    jhill

    #2
    Hi jhill,

    There's unfortunately no supported way to access this from a strategy. You need to be able to know the conditions that caused a background color change, and can then use these same conditions in a strategy.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks very much for your prompt reply.

      jhill

      Comment


        #4
        Hi Ryan,

        One more question if I may.
        When writing a Strategy Script, how can I test for the Background Color of the chart that is used on the current Bar?

        Thanks,

        jhill

        Comment


          #5
          There is no way to access this from any bar. You need the underlying conditions that cause a background color change.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Thanks Ryan for your response. The conditions that you referred to are in a 3rd party Indicator script. Since I won’t be needing the plotting logic in my Strategy Script, can you suggest a simple way of eliminating the script that is only associated with the actual plotting, keeping only the conditions necessary for determining a color change?

            Also, I use 4 different indicators in order to visually place a trade, so do I assume correctly that I’ll have to merge the 4 of them together into one Strategy in order to properly place an Auto Trade?

            Comment


              #7
              If you don't have the source code available for these indicators, you will not be able to access the color changing conditions from a strategy.

              Without the source code from the indicator, the only values you can access from the strategy are indicator plots.

              Best may be to work with the 3rd party vendor to see if they offer an automated trading system based on their indicators.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Again, thanks for your time and prompt responses. I have set up a good Trading methodology using these indicators but wanted to try and create an auto system for me to eliminate the Psy. problems that I have in pulling the trigger. I'll keep plugging along to try and get the auto system to work.

                jhill

                Comment


                  #9
                  Hi Ryan, your response resulted in one more question.

                  Thanks for your prompt response!

                  I have the .cs files from the 3rd party, for the indicators I currently use, and have opened them with the NinjaScript Editor. I assume that these .cs files are the source code which you addressed in the previous email?

                  If so, is there a simple way to create a Strategy from the Indicator script?

                  Thanks,

                  jhill

                  Comment


                    #10
                    Yes .cs can be used as source files, but also as a wrapper for protected dlls.

                    If you can view the indicator source code, you should be able to see the conditions that result in background color change. You can use the same conditions that are in the indicator code in your strategy, or create a bool series from the conditions, and expose the values of the boolseries following this sample:

                    Last edited by NinjaTrader_RyanM1; 08-15-2011, 01:36 PM.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Again Ryan your time and responses are very much appreciated.

                      thanks,

                      jhill

                      Comment


                        #12
                        You're welcome, jhill. Best of luck with the strategy creation. Let me know if you have any additional questions.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Ryan,
                          I have pasted below, the script that I added to my Indicator and Strategy, which follows the Strategy and Indicator examples in the SampleBoolSeries.zip from NT. My Indicator compiled fine, but the Strategy generated an error. Could you look at the code and help me understand what I need to correct? Thanks so much for your help!


                          MY STRATEGY:

                          protected override void Initialize()
                          {
                          // Add(JnD_ZlemaVma(14,6,9)); //JnD
                          // Add(JnD_ZlemaVma()); //JnD
                          CalculateOnBarClose = false;
                          }

                          MY INDICATOR:

                          namespace NinjaTrader.Indicator
                          {
                          [Description("Combination of ZLEMA and VMA with background shading when the two cross. (v7.1)")]
                          public class JnD_ZlemaVma : Indicator
                          /*
                          Revision 0. Combined indicators and used background flooding schemes and rising/falling selectable colors.
                          Revision 1. Corrected error that removed changes to background flooding when the program was rebooted.
                          */

                          {
                          #region Variables
                          private int zlemaPeriod = 14;
                          private int downIntensity = 65;
                          private int upIntensity = 75;
                          private int direction = 0;
                          private int lag = 0;
                          private int vmaPeriod = 9;
                          private int volatilityPeriod = 9;

                          private double value1 = 0;
                          private double value2 = 0;
                          private double k = 0;
                          private double oneMinusK = 0;

                          private bool showFlooding = true;

                          private Color backColorUp = Color.Green;
                          private Color backColorDown = Color.Red;
                          private Color colorUp = Color.Green;
                          private Color colorDown = Color.Red;

                          private DataSeries zlemaSeries;

                          private BoolSeries bearIndication; //JnD
                          private BoolSeries bullIndication; //JnD
                          private double exposedVariable; //JnD
                          #endregion

                          Comment


                            #14
                            Originally posted by jhill View Post
                            Thanks Ryan for your response. The conditions that you referred to are in a 3rd party Indicator script. Since I won’t be needing the plotting logic in my Strategy Script, can you suggest a simple way of eliminating the script that is only associated with the actual plotting, keeping only the conditions necessary for determining a color change?

                            Also, I use 4 different indicators in order to visually place a trade, so do I assume correctly that I’ll have to merge the 4 of them together into one Strategy in order to properly place an Auto Trade?
                            The only things that an indicator exposes are its public properties and methods. You need to know how those properties and methods create the color change. Then you just need to call them directly in your strategy, by reference to the indicator.

                            In other words, if the indicator generates trade signals, then the calculation logic behind those signals is implied by the signals themselves: you only need to process the signals, as if they were coming from a black box, which, in the absence of the source code, they in fact, are.

                            Comment


                              #15
                              In your indicator code, you need a couple more components:

                              You need to set the boolseries when your condition is true.
                              You need the properties region linking the private boolseries to the public (Uppercase) one that you then reference in your strategy.

                              This is all in the sample you downloaded, so will have to look at how it's used there and do the same in your scripts.
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by CarlTrading, 03-31-2026, 09:41 PM
                              1 response
                              67 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by CarlTrading, 04-01-2026, 02:41 AM
                              0 responses
                              36 views
                              0 likes
                              Last Post CarlTrading  
                              Started by CaptainJack, 03-31-2026, 11:44 PM
                              0 responses
                              59 views
                              1 like
                              Last Post CaptainJack  
                              Started by CarlTrading, 03-30-2026, 11:51 AM
                              0 responses
                              62 views
                              0 likes
                              Last Post CarlTrading  
                              Started by CarlTrading, 03-30-2026, 11:48 AM
                              0 responses
                              53 views
                              0 likes
                              Last Post CarlTrading  
                              Working...
                              X