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

How do i find do this pseudo code logic in ninjascript.

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

    How do i find do this pseudo code logic in ninjascript.

    NT8 controller shows Position= FLAT, Account Position=1, Synch=false, whenever this situation happens, it goes and buys because synch = false. When i initially place order , it longs and sets Position=1, Account pos=1 and Synch=true,
    then it changed after 5pm and set Position==flat, Account pos= 1 and Synch=false. whenever false, next day ninjascript checks and longs(buys). I dont want this to long more than one position. So i want to check if the account with that instrument has any position.Currently, i am checking Market.position, which is not working.....
    How do i find do this pseudo code logic in ninjascript.----Account.Instrument["ZN"].getposition() ===> here the instrument is ZN. Pls refer my screen enclosed. The last one on the list. Pls help me
    Attached Files

    #2
    Hello prabbala,

    I wanted to check, it looks like you are using two strategies on the same instrument/account. Are you seeing that when using both strategies this occurs?

    Strategies by default do not observe the global account position, they have their own virtual position and account reporting which is not shared between strategies. In most cases, we suggest to combine logic if you have two strategies that should both be working on the same instrument at the same time, this prevents the disconnect of position information. If you are creating a more complex script, you may be able to use the PositionsAccount object however this is reserved for advanced programmers as using multiple scripts on one instrument can result in discrepancies in reporting.

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

    Comment


      #3
      Thanks for responding me. No, I am not using multiple strategies . I am using only 1 strategy. I guess, virtual position is represented by Position.MarketPosition . How do i check for strategy account position? I see a method : Account.GetPosition() . Not sure if this would check that "one strategy.Account.Getposition()". pls advise

      Comment


        #4
        Hello prabbala,

        guess, virtual position is represented by Position.MarketPosition
        Correct, your strategy has its own position object, generally from a strategy you will never have to access the actual account position directly.

        How do i check for strategy account position?
        I provided a link in the last email about this question, have you reviewed PositionAccount?

        I would likely suggest to first try to address why the strategy is becoming out of sync, using the account directly is not often the correct solution. This also prevents your script from being able to work correctly in historical data because you are accessing the selected accounts position which will not be changed in historical data. if you plan on using historical data/strategy analyzer this is not a solution, using the actual position will only work in realtime when the strategy can affect the actual account position.

        From the image you provided, it seems that the strategy is current flat based on its logic/what occurred with its trading while you account currently is in a 2 long position. When you started the strategy, was the account flat at that time? If so were manual trades placed to the account, or had other strategies been run on the account which placed a trade to this instrument?

        It is also possible to cause discrepancies in your logic, for example if you are 1 long and wanted to reverse the position to 1 short, if you accidentally Exit and Enter in the same bar, it will both reverse and close the position creating a 2 short position instead of 1. Depending on the logic you used, you may be running into one of these type of situations where the logic used is causing a difference in the expected position.

        I look forward to being of further assistance.


        JesseNinjaTrader Customer Service

        Comment


          #5
          what does Account.GetPosition() do?
          how do i use this to filter strategy positions?

          Comment


            #6
            Hello prabbala,

            This is not a documented method, I am unsure what that could be used for. This is not something you would normally use in a NinjaScript strategy.

            The information in my prior posts would be my suggestions toward your questions. If you need to reference the account position you can use the PositionAccount to do that. My prior recommendation of instead trying to understand why the account is becoming out of sync would be a better direction to explore, as noted using the Accounts position limits the script to working only in realtime, historical positions will not be accurate.

            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              When Ninjatrader 8 is restarted ,this.strategy.this_instrument.Virtual position != RealPosition (Pseudo code) , because virtual position is wiped off,

              Comment


                #8
                Hello prabbala,

                Correct, When you disable a strategy it will loose the virtual information that it has when running. This information only exists because the strategy worked through processing historical data into realtime. Once the strategy is turned off, that information is not longer needed and cleared. This also plays into the start behavior that your strategy uses and how the account sync system works.

                If you are expecting the strategy to be in sync with the account when it starts, you need to research the start behavior in contrast to the logic you made: https://ninjatrader.com/support/help...hlightsub=sync

                When the strategy processes, it is possible to become in sync with the account if the logic and start behavior used allow for that. Otherwise, it is expected in most cases that your strategy will have a unique position to its self which could match or could not match the actual account position. This is mostly seen when using more than one strategy on a single instrument/account as the actual position no longer relates to a single strategies position.



                Please let me know if I may be of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by lorem, Yesterday, 09:18 AM
                5 responses
                19 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by WHICKED, Today, 12:56 PM
                2 responses
                15 views
                0 likes
                Last Post WHICKED
                by WHICKED
                 
                Started by Felix Reichert, Today, 02:12 PM
                0 responses
                1 view
                0 likes
                Last Post Felix Reichert  
                Started by Tim-c, Today, 02:10 PM
                0 responses
                1 view
                0 likes
                Last Post Tim-c
                by Tim-c
                 
                Started by cre8able, Today, 01:16 PM
                2 responses
                9 views
                0 likes
                Last Post cre8able  
                Working...
                X