Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enter trade only if not already in one?

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

  • NinjaTrader_BrandonH
    replied
    Hello LunaKai,

    Thanks for your note.

    PositionAccount.MarketPosition could be used to detect if an account's position is flat before placing an order in a strategy.
    Code:
    if (PositionAccount.MarketPosition == MarketPosition.Flat)
    {
        //do something here.
    }
    See this help guide page for more information about PositionAccount.MarketPosition and sample code: https://ninjatrader.com/support/help...etposition.htm

    Please let me know if I may assist further.

    Leave a comment:


  • LunaKai
    replied
    Originally posted by NinjaTrader_BrandonH View Post

    Position.MarketPosition == MarketPosition.Flat would be the correct way to detect if the strategy position is flat before placing an order. When this method is used in a condition, the strategy would only enter an order when the strategy position is flat (Strategy positions are separate from actual Account positions).
    This has always been something I've wanted to know. Let's say I have two charts and a separate strategy running on each one. I only want to be in one order at a time overall. If strategy A fires off, and while that one is still going strategy B meets the requirements to fire off, I want strategy B to NOT fire because I'm already in a trade.

    Is there a way to set up a condition taking into account the account position(s)? That is, not just "fire only if this strategy doesn't already have me in a trade", but "fire only if I'm entirely flat across the board in my account."

    Thank you in advance!

    Leave a comment:


  • KonstantinosNT
    replied
    What kind of Order Method is this : enterLongTrade(High[0]); which you are using ?
    Is this a valid method ?

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    Hello jaybedreamin,

    Thanks for your post.

    Position.MarketPosition == MarketPosition.Flat would be the correct way to detect if the strategy position is flat before placing an order. When this method is used in a condition, the strategy would only enter an order when the strategy position is flat (Strategy positions are separate from actual Account positions).

    Position.MarketPosition: https://ninjatrader.com/support/help...etposition.htm
    Strategy vs. Account Position: https://ninjatrader.com/support/help..._account_p.htm

    Please view the attached simple example script demonstrating entering a Long position when the strategy is in a Flat position.

    When the example script is enabled on a chart, we see that an Entry order is only submitted when the strategy position is flat. If the strategy position is not flat, an order is not placed.

    Note that enterLongTrade() is not a default NinjaScript method. See the Managed Approach order methods below.


    To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    https://ninjatrader.com/support/foru...121#post791121​​

    Let me know if I may assist further.​
    Attached Files
    Last edited by NinjaTrader_BrandonH; 02-08-2023, 08:10 AM.

    Leave a comment:


  • jaybedreamin
    started a topic Enter trade only if not already in one?

    Enter trade only if not already in one?

    Hi all,

    I'm trying to implement some simple logic that does not submit a new order until all existing positions have been closed and the user is flat

    I thought this would work

    if(Position.MarketPosition == MarketPosition.Flat){

    Print("Market Position is FLAT, going LONG -> " + Position.MarketPosition);

    enterLongTrade(High[0]);

    }

    However, I'm still noticing new orders being executed right after each other, which shouldn't happen. What could I be missing here?

Latest Posts

Collapse

Topics Statistics Last Post
Started by Pointtoni, Yesterday, 11:41 PM
3 responses
33 views
0 likes
Last Post jenacie.com  
Started by DayTradingDEMON, Yesterday, 02:10 PM
5 responses
36 views
0 likes
Last Post DayTradingDEMON  
Started by Nate G, 03-17-2025, 02:53 PM
4 responses
67 views
1 like
Last Post timko
by timko
 
Started by several, 03-18-2025, 03:53 AM
11 responses
179 views
1 like
Last Post timko
by timko
 
Started by Amelie4262, Today, 10:45 AM
0 responses
13 views
0 likes
Last Post Amelie4262  
Working...
X