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

account positions and strategy position.

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

    account positions and strategy position.




    people with nt,


    i have a question that should be quite simple.


    all my strategies are directional, so i would only have one instance of one strategy active at any time for any instrument because i would only be interested in having one single position in any particular instrument. in order to avoid duplicate orders or positions, i had to make entries and exits conditional and add position checks to all my strategies.


    something like this:



    Code:
    // Set 1
    if ( conditions for short
    && (Position.MarketPosition != MarketPosition.Short) )
    {
    EnterShort( );
    }
    
    
    else
    
    
    // Set 4
    if ( (Position.MarketPosition == MarketPosition.Long)
    && conditions to exit long )
    {
    ExitLong( );
    }
    
    
    // Set 3
    if ( conditions for long
    && (Position.MarketPosition != MarketPosition.Long) )
    {
    EnterLong( );
    }
    
    
    else
    
    
    // Set 2
    if ( (Position.MarketPosition == MarketPosition.Short)
    && conditions to exit short )
    {
    ExitShort( );
    }

    i am currently working on a different structure, so i still have to evaluate whether using if else conditionals would be beneficial.


    and i would like to know whether using any checks is of any use. as i remember, the marketposition checks never helped to avoid duplicate orders or positions. ¿is it possible to use both account positions and strategy position checks simultaneously? ¿is there any benefit to including both checks simultaneously? the definitions for accounts positions https://ninjatrader.com/support/help...ns_account.htm include locks, ¿could these account positions checks cause any problems when automating strategies or negatively impact performance? ¿are there any samples of how to use account positions checks? i am considering getting rid of all checks altogether if they are not productive.



    very well, regards.

    #2
    Hello rtwave,

    Thanks for your post.

    I understand you are asking about account positions and strategy positions but I think the issue is not how to use those to control the orders so much as what is causing the duplicate entries.

    In the code examples you have shown, you have both entry and exit conditions. If the entry and exit conditions are the same (IE: the condition to enter long are the same as the conditions to exit short) then that can cause unexpected positions. Here is why:

    It is important and fundamental to understand that ALL entry methods will automatically close a position in the opposite direction. For example, if you are in a Long position and your strategy issues EnterShort(), the EnterShort method will see that there is a long position and will first issue a sell market order called "Close position" to close the long position, and then it will issue a second sell market order to leave your strategy in the intended short position.

    If your long exit conditions are the same as the entry conditions for short, that means your strategy is sending a sell market order to close the position at the same time. That is the situation when instead of being 1 contract short you would now be 2 contracts short.

    Even if your entry and exit conditions are not exactly the same but the entry and exit occur at the same time, you will get unexpected positions.

    If you look at the code of the strategy SampleMA Crossover, you will not see any exit methods at all, and this demonstrates that the entry methods do close the opposite positions.

    In order for you to be only in one position at a time, your entry conditions need to check that the MarketPosition is Flat as this will prevent entering if there is an existing position.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by r68cervera, Today, 05:29 AM
    0 responses
    2 views
    0 likes
    Last Post r68cervera  
    Started by geddyisodin, Today, 05:20 AM
    0 responses
    3 views
    0 likes
    Last Post geddyisodin  
    Started by JonesJoker, 04-22-2024, 12:23 PM
    6 responses
    35 views
    0 likes
    Last Post JonesJoker  
    Started by GussJ, 03-04-2020, 03:11 PM
    12 responses
    3,239 views
    0 likes
    Last Post Leafcutter  
    Started by AveryFlynn, Today, 04:57 AM
    0 responses
    6 views
    0 likes
    Last Post AveryFlynn  
    Working...
    X