Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Open extra order

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

    Open extra order

    Hi, I have looked at the posts for "closed" orders and still need some help. I am entering the trades with "condition 1" and exiting the trades with 'condition 2".

    // Condition set 1
    if (Position.MarketPosition == MarketPosition.Flat
    &&Close[0] >=Condition 1
    && Rising(Condition 1) == true)

    {
    EnterLong(Contracts, "");
    }

    // Condition set 2
    if (Position.MarketPosition == MarketPosition.Long
    && Falling(Condition 2)) == true)
    {
    ExitLong("", "");
    }

    // Condition set 3
    if ( Position.MarketPosition == MarketPosition.Flat
    &&Close[0] == Condition 1
    && Falling(Condition 1) == true)

    {
    EnterShort(Contracts, "");
    }

    // Condition set 4
    if (Position.MarketPosition == MarketPosition.Short
    && Rising(Condition 2) == true)
    {
    ExitShort("", "");
    }

    This code is creating 2 entries.. How to get the code "exit and enter" to produce only 1 contract?

    #2
    Hi n1144n,

    This looks like it is pseudo code and the Condition 1 text is to be replaced by a double the first time it is used, a dataseries the second time it is used, while Condition 2 is used a dataseries each time it is used.


    By using if Position.MarketPosition == MarketPosition.Flat, this should prevent further entries on the next bar.
    By using Rising(Condition 1) == true for entering long and Falling(Condition 1) == true for entering short, these should be opposite and prevent a long and a short from being entered on the same bar.

    At this point, I would need to add prints to the code to see what conditions are being triggered at the same time.

    May I have an export of this code? (Just a strategy demonstrating this code with no other code added)

    To export your script do the following:
    1. Click File -> Utilities -> Export NinjaScript
    2. Enter a unique name for the file in the value for 'File name:'
    3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
    4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


    Below is a link to the help guide on Exporting NinjaScripts.
    http://www.ninjatrader.com/support/h...nt7/export.htm
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    134 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    75 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    119 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    114 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    92 views
    0 likes
    Last Post CarlTrading  
    Working...
    X