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

Strategy Basics

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

    Strategy Basics

    1. Does your document list all of the events that can fire in a strategy, when they fire and in what order?
    2. Is there an initialize event?
    3. Here's what I'm trying to do:
    OnBarUpdate:
    Check to see if there is a position opened:
    If not, check my order entry logic
    If there is, check the close price against my current stop\limit and adjust, if necessary
    4. Does a strategy only run when OnBarUpdate fires or can other events cause a strategy to execute? (Maybe a redundant question)
    5. How do I check the # of opened orders for the same strategy?
    6. Do you offer any advance Ninjascript training that I can pay for?
    7. I see this used a lot EnterLong("myEntryOrder"); We can't use "myEntryOrder" for every order right? What should it actually be?
    Last edited by RiversideDude; 03-09-2017, 06:00 AM.

    #2
    Hello RiversideDude,

    Thank you for your note.

    Below I’ve provided links to event driven methods which can be called within a strategy.

    OnBarUpdate()
    OnFundamentalData()
    OnMarketDepth()
    OnAccountItemUpdate()
    OnStateChange()
    OnExecutionUpdate()
    OnOrderTrace()
    OnOrderUpdate()
    OnPositionUpdate()

    Regarding Initialize, please see Implementation Changes Overview at the following link in our helpguide for an explanation,


    To check if you have a current position you could use,


    To adjust your stop based off the close, you might consider using SetTrailStop,


    Alternatively you could check the close against the position average price, and adjust your stop price by saving the new stop price to a variable which you pass to your stop method.


    I would encourage you to see OrderMethods section of our helpguide,


    I have attached a strategy which provides one method of checking if an order is filled, CheckOrderStatus.

    Another sample strategy I have attached, ThreeLongsCheckIfSlOrPtHasClosedPosForEither, provides an example of using an if statement to check if the OrderState = Filled.

    We do not offer any training but do have resources available to get you started learning NinjaSript to build your strategy.

    I would encourage to see the information and links under Getting Startd with NinjaScript


    The following will introduce you to the strategy builder;

    Strategy Builder Intro: 7 Minutes
    An overview of the Strategy Builder feature in the NinjaTrader 8 platform.NinjaTrader supports over 40,000 traders around the globe with best-in-class techno...


    Strategy Builder NT8:
    Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Builder.2:45 Opening a Strategy Builde...


    See the NinjaScript Editor Youttube,
    Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.


    A link to our Help Guide NinjaScript section can be found here,


    Click here to see our NinjaScript Reference Samples:


    You can also contact a professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. I am not sure if they offer a paid training service. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      I asked about adjusting my stop and the example you sent show ExitLongStopMarket. But it clearly states below that it exits the position. That's not what I want to do so I'm not clear on your recommendation. Why wouldn't I use ChangeOrder()?

      private double stopPrice = 0;

      protected override void OnBarUpdate()
      {
      if (CurrentBar < 20)
      return;

      // Only enter if at least 10 bars has passed since our last entry
      if ((BarsSinceEntryExecution() > 10 || BarsSinceEntryExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
      {
      EnterLong("SMA Cross Entry");
      stopPrice = Low[0];
      }

      // Exits position
      ExitLongStopMarket(stopPrice);
      }

      I don't want to use SetTrailStop. How do I get the current Stop and Limit so that I can evaluate them to see if they need to be adjusted?

      Lastly, "MyEntryOrder". What is the purpose of this?

      Thanks in advance.

      Comment


        #4
        Hello RiversideDude,

        You wanted to check if a position is open, in ThreeLongsCheckSlOrPtHasClosedPosForEither, on line 104, 106, 124 and 126 I demonstrate how to check if a profit target and stop loss order exist and how to print the status of the order. If the profit target and stop loss are not filled but exist, you can assume the position is still open in this example.

        In CheckOrderStatus sample, I demonstrate on line 85 how to check if “myEntryOrder” was executed/filled, which would be another way to check if a position is opened.

        Regarding my suggestion of SetTrailStop, I offered this as a solution to checking the current close price against your stop price and adjusting. You could use ChangeOrder as well.

        One purpose of assigning a signalName to an entry method, ex “MyEntryOrder”, would be so you could check if a recent execution was that specific entry. For example see OnExecutionUpdate section of our helpguide as well as the CheckOrderStatus sample strategy I provided for an example of this.


        To get the current limit price of your profit target order, I would suggest adding the following to line 107 of the sample strategy ThreeLongsCheckSlOrPtHasClosedPosForEither, and pulling up an output window. This demonstrates how you can get the limit price of a specific order.

        Code:
        	Print("myEntryOrder1Pt myEntryOrder1Pt.LimitPrice.ToString " + myEntryOrder1Pt.[B]LimitPrice[/B].ToString());
        Adding the following to 127 of strategy ThreeLongsCheckSlOrPtHasClosedPosForEither, demonstrates how you can check the stop price of a specific stop loss order.

        Code:
        Print("myEntryOrder1Sl myEntryOrder1Sl.StopPrice.ToString()); " + myEntryOrder1Sl.[B]StopPrice[/B].ToString());
        I would encourage you to read about Order objects should you not be familiar,


        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Ok Alan thanks. Let me check again and I'll let you know.

          Thanks!

          Comment


            #6
            Ok, I see the values. But I don't understand how myEntryOrder1Pt and myEntryOrder1Sl got associated with entryOrder1 = EnterLong(1, "myEntryOrder1");

            myEntryOrder1Pt and myEntryOrder1Sl isn't defined anywhere before you start referencing it. How does this work?

            Thanks in advance!!

            Comment


              #7
              I found it.

              Thanks.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cls71, Today, 04:45 AM
              0 responses
              1 view
              0 likes
              Last Post cls71
              by cls71
               
              Started by mjairg, 07-20-2023, 11:57 PM
              3 responses
              213 views
              1 like
              Last Post PaulMohn  
              Started by TheWhiteDragon, 01-21-2019, 12:44 PM
              4 responses
              544 views
              0 likes
              Last Post PaulMohn  
              Started by GLFX005, Today, 03:23 AM
              0 responses
              3 views
              0 likes
              Last Post GLFX005
              by GLFX005
               
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              12 views
              0 likes
              Last Post XXtrader  
              Working...
              X