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

Entry, Exit and Position Issue

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

    Entry, Exit and Position Issue

    Using v6.5
    I have an issue with Entry and Exit in a Multi Time Frame Strategy when an Exit Condition and Entry Condition fires on the same bar. I don't believe the problem is due to the Multi Time Frame as I set the entries/exits on the condition of BarsInProgress =0. I'm attempting to manage the position/direction using local variables, but I'm sure there may be a cleaner way to do this. On the same OnBarUpdate event, can the strategy Exit one direction and Enter the other, as I've coded in the code below?

    Logs from the Executions tab;

    Time E/X Position Name
    8:40:56 Entry 1L LONG_ENTRY
    9:10:41 Exit - Sell
    9:10:41 Entry 1S Close Position
    9:10:42 Entry 2S SHORT_ENTRY
    9:49:40 Exit 1S Buy to cover



    if (BarsInProgress == 0)
    {
    //Exit Conditions
    if (_position = true)
    {
    if (_longposition = true)
    {
    if (exit_condition)
    {
    ExitLong("LONG_ENTRY");
    _longposition = false;
    _position = false;
    }
    }
    if (_shortposition = true)
    {
    if (exit_condition)
    {
    ExitShort("SHORT_ENTRY");
    _shortposition = false;
    _position = false;
    }
    }
    }

    //Entry Conditions
    if (_position == true) return;

    if (long_entry_condition)
    {
    EnterLong("LONG_ENTRY");
    _longposition = true;
    _position = true;
    }
    if (short_entry_condition)
    {
    EnterShort("SHORT_ENTRY");
    _shortposition = true;
    _position = true;
    }
    }

    #2
    Hello RhinoGG,

    You are running into our internal order handling rules here. An exit and entry will not be processed on the same bar.

    By default entries will reverse a position. If you want reversal behaviour you can combine your conditions for exit and entry and then only submit the entry order.



    Methods that generate orders to exit a position will be ignored if a strategy position is open and:
    • An order submitted by an enter method (EnterLongLimit() for example) is active and this entry order is used to open a position in the opposite direction
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by samish18, 04-17-2024, 08:57 AM
    16 responses
    55 views
    0 likes
    Last Post samish18  
    Started by arvidvanstaey, Today, 02:19 PM
    3 responses
    9 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Started by jordanq2, Today, 03:10 PM
    2 responses
    8 views
    0 likes
    Last Post jordanq2  
    Started by traderqz, Today, 12:06 AM
    10 responses
    18 views
    0 likes
    Last Post traderqz  
    Started by algospoke, 04-17-2024, 06:40 PM
    5 responses
    47 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X