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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    630 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    364 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    566 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    568 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X