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 to make double check to strateg vs. account position due to bid/ask dynamics?

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

    How to make double check to strateg vs. account position due to bid/ask dynamics?

    Hello,

    Due to Bid/Ask dynamics sometimes it gets me out of a position when it shouldn't, and then if I disable/enable the strategy because of overnight/closing ninja, I get a mismatch in strategy position vs. account position, because then he calculate the position in historical terms.
    the result of that is: when he tries to get me out, he gets me out in the old position for example 200, and now I am in 100 position, so I will now be short 100.

    In short, I want to do a double check whenever he exit a trade, to make sure the position is equal to the account position.

    I am using for the stop quantity the variable: Position.Quantity , which now I know could be wrong due to historical/real-time differences.

    How can I do double check on Position.Quantity? + where should I put it? (in executionupdate?)

    something like: if (Position.Quantity > Account.Quantity) then exit with Account.quantity.

    the strategy is Long ONLY, so I know for sure that I will never want to be Short somehow.

    If you thought about this problem already, will appreciate the solution, thanks in advance!


    #2
    Hello zoharcho,

    One possible way around this would be to reference the account position instead of the strategy position. You could do this as a check in OnBarUpdate to determine what to do when the strategy starts up. For example if the account already has a position you could avoid submitting historical entries/exits and then just wait in real time until the position is closed. If you are relying on the strategy to exit the position that could also be used to delegate that situation once you are in realtime.



    I would not likely suggest trying to combine working with historical orders or trying to match quantities with using the live account position, it would be easiest to use this from OnBarUpdate to just determine how to start the strategies logic. An example would be if there is no position use one set of logic to execute normally, if there is a position use a separate set of logic to exit or wait then resume the normal logic again.

    I look forward to being of further assistance.


    JesseNinjaTrader Customer Service

    Comment


      #3
      Just what I needed! I didnt know there is a variable named: PositionAccount.Quantity

      wanted to use it, thank you for letting me know. thank you, I think it will solve the problem.

      thanks Jesse.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      26 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 04-23-2024, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      193 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,235 views
      0 likes
      Last Post xiinteractive  
      Working...
      X