Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Referencing OCHL from where?

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

    #16
    Jesse - (and PatrickH) - Thank you very much for your generous assistance. I am into a slow but serious endeavor to learn NinjaScript Strategy coding, and your willingness to reach to my beginner level is incredibly much appreciated !!!

    I understand all of your comments re: this thread and I can self-correct the errors in this example. In the course of this exercise, and in anticipation of importing your corrected version, I trashed my .cs file in Documents\NT7\bin\Custom\Strategy. Then I put your .cs version into that Custom\Strategy folder.
    Now I cannot import it into NT using ControlCenter\File\Utilities\ImportNinjaScript. That way apparently needs to import a .zip file. I have run into this before, so I may as well learn now how to solve this problem.

    Please advise. Thanks again.

    Comment


      #17
      Jesse - I see that your corrected version is showing up as an editable strategy using ControlCenter\Tools\EditNinjaScript. I also see that it appears as a selectable Strategy on my chart.

      So I ran this strategy for 1 week using the Strategy Analyzer, and it shows that it took one trade instead of 5 trades, one per session.

      I assume that the Variable0 switch trick that you taught me needs to be re-set every session, and does not do so automatically with the Order Handling/Exit on Close function. Is that correct? If so, do I just create another condition to re-set Variable0 back to 0 at the end of every session?

      Thank you.

      Comment


        #18
        Hello,

        Yes the variable would need to be reset at each session if you need to make sure it is a specific value at the start of the session.

        I would like to stop to note that Variable0 - Variable9 are default variables in a strategy only, these come by default in every strategy. As you progress in programming you will find that a very descriptive variable name makes a world of difference so I just wanted to make it known that these are just here as defaults and you are free to make your own named variables also. Also these are not used in Indicators, so please keep this in mind when using these names specifically.

        Additionally in your learning, I would highly recommend sections 5 - 11 in this guide if you have the time: http://www.techotopia.com/index.php/C_Sharp_Essentials
        This is one of the documents that I have found that is the most simple to follow in relation to NinjaScript.

        Going back to your question of how to determine the start of a new session, you would need to check if the current bar is the first bar of a new session, you can do that using FirstBarOfSession: http://www.ninjatrader.com/support/h...htsub=firstbar

        A simple usage of this would be:

        if(Bars.FirstBarOfSession)
        {
        //reset any variables you need to
        }

        I look forward to being of further assistance.

        Comment


          #19
          Thank you very much. I am getting it.

          Thanks for the webpage on C#. It is all slowly moving from slightly familiar to a part of my vocabulary.

          Comment


            #20
            Jesse - much obliged for this thread of private instruction. As I have said, I am learning NT Strategy coding slowly but seriously. I have re-vamped this simple FirstTrade111 Strategy to comply with what I think I understand from your replies and the tutorial videos and references you have given me. I would like to take one trade per day, either long or short, after (x)DelayBars have elapsed from the beginning of the session.

            Please look at the attached. I think I am using Initialize() and OnBarUpdate() correctly now, however the StopLoss and ProfitTarget variables are not showing up as user-defined variables when I test the strategy in the Strategy Analyzer. Where did I go wrong?
            Attached Files

            Comment


              #21
              Hello,

              In the strategy, any user input you need will have two parts, lets look at one of the working inputs first to compare what is wrong.

              First there is the backing property, this holds the default value and stores the value for delayBars.

              Code:
              private int delayBars = 6;
              The second half that actually makes this show up in the interface is missing from the two you have defined, this is the public property, here is the second half of delayBars:

              Code:
              [Description("")]
              [GridCategory("Parameters")]
              public int DelayBars
              {
                         get { return delayBars; }
                          set { delayBars = Math.Max(1, value); }
              }
              A public property is needed for this to appear in the interface, this is a getter setter which gets the private fields value or sets it when you call DelayBars, notice the Capital oppsed to the lowercase names.

              To make StopLoss and ProfitTarget work as you intended, you need to add two more public properties that point to these variables. You can repeat the process below for both variables.

              Lets look at StopLoss.

              First you would want to change the following for consistancy:

              Code:
              private int [B]S[/B]topLoss = 200;
              to
              private int [B]s[/B]topLoss = 200;
              a lower case generally means in programming this is a private variable.

              Next you would add the following to the Properties near the bottom of the script.

              Code:
              [Description("")]
              [GridCategory("Parameters")]
              public int [B]StopLoss[/B]
              {
                     get { return [B]stopLoss[/B]; }
                     set { [B]stopLoss [/B]= value; }
              }
              This will allow for these to be displayed as properties, when using StopLoss now make sure to call this by its public name or the StopLoss.

              I look forward to being of further assistance.

              Comment


                #22
                Got it!

                Voila !!! My lesson #1 is complete. Thanks so much for your guidance, Jesse. I think that I have enough from this simple sample exercise to further successfully explore the Forum, User Guide and Reference Samples that NT provides.

                Best regards to you and NT Customer Service!

                Comment


                  #23
                  Jesse - Whoops, I spoke too soon. (see attached) I tried to apply the getter/setter in the Strategy "Properties" section using Public Variables StopLoss and ProfitTarget and placing those values as doubles (Currency) according to the Help Guide's instructions to SetProfitTarget() and SetStopLoss().

                  Using the Strategy Analyzer, I get the Variables to show up, but StopLoss reads 1 and will not adjust to -$200 as per default. ProfitTarget reads $500 as per default

                  Am I missing something?
                  Attached Files

                  Comment


                    #24
                    Hello,

                    It looks like you just need to use the user inputs in the code now, they are defined but unused currently.

                    you have "hard" values defined in Initialize:

                    Code:
                    SetStopLoss (-200);
                    SetProfitTarget(500);
                    Instead you would need to use your public input's name, or:

                    Code:
                    SetStopLoss (StopLoss);
                    SetProfitTarget(ProfitTarget);
                    Once you make that change, after changing the values in the properties you should see it reflected in the results.

                    I look forward to being of further assistance.

                    Comment


                      #25
                      Jesse - OK. I understand now to use the PublicName of the variable instead of a hard coding since I created the variable for that purpose. However, I changed the getter setter in the properties to read: (attached)

                      get { return stopLoss; }
                      set { stopLoss = value; }

                      Now the strategy stops out the second it enters.

                      Please clarify the needed getter setter. Thank you.
                      Attached Files

                      Comment


                        #26
                        Hello,

                        In this case it looks like you have entered a negative value for the Stop where NinjaTrader would be looking for a positive value.

                        Please change -200 to 200 and this should no longer stop out immediately as it will have a value.

                        I look forward to being of further assistance,

                        Comment


                          #27
                          OK. Got it!

                          Yes. Thanks very much. Working fine now.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          574 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          333 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          101 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          553 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          551 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X