• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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,
    http://ninjatrader.com/support/helpG...ng_changes.htm

    To check if you have a current position you could use,
    http://ninjatrader.com/support/helpG...etposition.htm

    To adjust your stop based off the close, you might consider using SetTrailStop,
    http://ninjatrader.com/support/helpG...ttrailstop.htm

    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.
    http://ninjatrader.com/support/helpG...erageprice.htm

    I would encourage you to see OrderMethods section of our helpguide,
    http://ninjatrader.com/support/helpG...er_methods.htm

    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
    https://ninjatrader.com/support/help...operations.htm

    The following will introduce you to the strategy builder;

    Strategy Builder Intro: 7 Minutes
    https://www.youtube.com/watch?v=xpgC...vDBcC&index=32

    Strategy Builder NT8:
    https://www.youtube.com/watch?v=HCyt...We0Nf&index=10

    See the NinjaScript Editor Youttube,
    https://www.youtube.com/watch?v=Q06x...ZmVnauWXkWe0Nf

    A link to our Help Guide NinjaScript section can be found here,
    https://ninjatrader.com/support/help...injascript.htm

    Click here to see our NinjaScript Reference Samples:
    http://ninjatrader.com/support/forum...splay.php?f=30

    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.
        http://ninjatrader.com/support/helpG...tionupdate.htm

        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.LimitPrice.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.StopPrice.ToString());
        I would encourage you to read about Order objects should you not be familiar,
        http://ninjatrader.com/support/helpG...-us/?order.htm

        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 Emma1, Today, 02:42 PM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_DrewO  
              Started by fx.practic, Today, 03:10 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by jertrade, Today, 02:50 PM
              2 responses
              11 views
              0 likes
              Last Post jertrade  
              Started by RedDuke, Today, 01:59 PM
              1 response
              19 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by MarianApalaghiei, Today, 01:18 PM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Working...
              X