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

Ninjatrader 8 help developpement

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

    Ninjatrader 8 help developpement

    We re using ninja trader v8 and we re wondering if accessing close[0] is still the way to get current price for backtesting or real time data.

    #2
    Hello,

    Thank you for the post.

    Yes, this would still be the case. You can locate changes made to NinjaScript in the following document: http://ninjatrader.com/support/helpG...ng_changes.htm

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Ninjatrader 8 help developpement

      Hello and thank you NinjaTrader_Jesse !
      So,
      I want to recover the price of the market in real time and test it in backtest following an intervale of 1 Ticks.
      With a stopLoss definition and target has 1 and 2 ticks.

      Here is the code I defined:

      protect override void OnStateChange () {
      **** If (state = state.configure) {
      ******* SetStopLoss (CalculationMode.Ticks, 2);
      ******* SetProfitTarget (CalculationMode.Ticks, 1);
      **** }
      }
      protect override void OnBarUpdate () {
      ****** StatePrice = Close [0]; // current price in real time
      ****** Print ("current price =" + StatePrice);
      }

      Do you think my code is correct?

      Comment


        #4
        Hello ninintrade,

        Thanks for the additional question.

        This line has some misplaced capitalization "If (state = state.configure) {" where it should be: "if (State = State.Configure) {"

        Other than that, your code looks correct for placing a static Profit Target and Stop Loss with 1 or two ticks difference in price since entry. You will still have to add entry methods to enter into the market, and you will have to assign the strategy to operate off of a single tick series or use Calculate.OnEachTick.

        Please refer to the documentation below to check your syntax and to look further into using OnStateChange()

        OnStateChange() - http://ninjatrader.com/support/helpG...tatechange.htm

        Calculate - http://ninjatrader.com/support/helpG.../calculate.htm

        Order Methods - http://ninjatrader.com/support/helpG...er_methods.htm

        Please let me know if you have any questions on the material.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello
          Thank you for answers

          I would like to know how to update total net profit and display it in real time please ?

          Comment


            #6
            Hello ninintrade,

            Thanks for the additional question.

            So I may assist you further, could you elaborate if you are not referring to the information from the Accounts tab of the control center? You can view the Realized PnL and Unrealized PnL as it updates from there.

            Accounts Tab - https://ninjatrader.com/support/help...counts_tab.htm

            If you are referring to accessing these values in realtime from NinjaScript, you can use the OnAccountItemUpdate() override.

            OnAccountItemUpdate() - https://ninjatrader.com/support/help...itemupdate.htm

            Please let me know if I may be of further help.
            JimNinjaTrader Customer Service

            Comment


              #7
              Ninjatrader 8 help developpement

              Hello NinjaTrader_Jim,
              Thanks for the previous answer!
              Also, I would like to know the meanings of:
              MarketPosition.Flat
              MarketPosition.Long
              MarketPosition.Short
              Even referring to the help guide, I didn't quite understand their function.

              Comment


                #8
                Hello ninintrade,

                Thanks for writing back.

                Those are property values for the MarketPosition property. They represent being in a long, short or flat market position. (You can read more about market positions here.)

                You can use these property values to check the position of the strategy through the Position object. Referencing the MarketPosition from Position is as follows:

                Code:
                if (Position.MarketPosition == MarketPosition.Flat)
                This will tell you if the strategy is in a flat position before executing any code within the if statement.

                Please let me know if you have any additional questions.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by PaulMohn, Today, 12:36 PM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by yertle, Yesterday, 08:38 AM
                8 responses
                36 views
                0 likes
                Last Post ryjoga
                by ryjoga
                 
                Started by rdtdale, Today, 01:02 PM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by alifarahani, Today, 09:40 AM
                3 responses
                17 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by RookieTrader, Today, 09:37 AM
                4 responses
                20 views
                0 likes
                Last Post RookieTrader  
                Working...
                X