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 i019945nj, 12-14-2023, 06:41 AM
    4 responses
    63 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by thread, Yesterday, 11:58 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by stafe, Yesterday, 08:34 PM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by jclose, Yesterday, 09:37 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by firefoxforum12, Yesterday, 08:53 PM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X