Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Single entry, multiple exit logic

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

  • Wick Wrangler
    replied
    Originally posted by NinjaTrader_Kate View Post

    What's occurring is that your logic is resetting the T1_xit, T2_xit, and T3_xit to false when it tries to submit an order after the inital entry has been filled.
    .
    Thanks. I suspected these vars were getting reset somehow.

    It's working properly now.




    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello Wick Wrangler,

    Thank you for your note.

    What's occurring is that your logic is resetting the T1_xit, T2_xit, and T3_xit to false when it tries to submit an order after the inital entry has been filled. Any time your conditions for entry are true, NinjaTrader will loop through and try to submit an order. If there's a position already active, it will check your Entries Per Direction setting and make sure that this entry would make the number of entries in the same direction equal or lesser to the value of that setting. If it's greater, the order will be ignored and you won't notice anything obvious to tell you that it tried to do that unless you have TraceOrders = true within the SetDefaults section of OnStateChange - if you do turn that on, a log entry will be added noting that the order was ignored and why.

    However, it will still also reset the bools to false since it's going through that particular block of code.

    If you're only using one entry at a time, then waiting to re-enter when you're in a flat position, you can fix this by adding the following to your entry conditions:

    && Position.MarketPosition == MarketPosition.Flat

    This will then not run through that code block until you are again in a flat position and ready for re-entry. This way you avoid accidentally resetting those bools before you meant to do so.

    Please let us know if we may be of further assistance to you.

    Leave a comment:


  • Wick Wrangler
    started a topic Single entry, multiple exit logic

    Single entry, multiple exit logic

    My Strat buys in once, then will scale out in 3 steps depending on price movement.

    I've tagged the entry with a signal name 'b1'.
    Exits are tagged: 't1', 't2', 't3'

    I created boolean vars associated with each exit, each turned off (set to false):
    T1_xit
    T2_xit
    T3_xit

    After each exit, I turn the associated var on (set to true).

    I coded the Set logic to not execute the actions for the exit if it's associated boolean var is true.

    PROBLEM: Though the exits are executing, I'm sometimes getting multiple t1 exits, even though the 1st exit should have set T1_xit to true. (I assume when the condition is true twice before the position is completely exited).

    If you can find any logic error in my code, I'd appreciate it.

    I've included the relevant info in the code snippet below (minus the actual condition logic).

    Code:
           protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Calculate                                    = Calculate.OnPriceChange;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.UniqueEntries;
    
                    ...
    
                    StopLoss                = 1;
                    T1_xit                    = false;
                    T2_xit                    = false;
                    T3_xit                    = false;
                }
                else if (State == State.DataLoaded)
                {                
                    ...
    
                    SetStopLoss(@"b1", CalculationMode.Currency, StopLoss, false);
                }
    
            }
    
    
            protected override void OnBarUpdate()
            {
                 // Set 1
                 // ENTRY, full position
                if ( <set 1 condition> )
                {
                    EnterLong(Convert.ToInt32(300), @"b1");
                    T1_xit = false;
                    T2_xit = false;
                    T3_xit = false;
                }
    
                 // Set 2
                 // T1 Exit, 1/3 position
                if ( <set 2 condition> )
                     && (T1_xit == false)
                     && (T2_xit == false)
                     && (T3_xit == false))
                {
                    ExitLong(Convert.ToInt32(100), @"t1", @"b1");
                    T1_xit = true;
                }
    
                 // Set 3
                 // T2 Exit, 1/3 position
                if ( <set 3 condition> )
                     && (T2_xit == false)
                     && (T1_xit == true)
                     && (T3_xit == false))
                {
                    ExitLong(Convert.ToInt32(100), @"t2", @"b1");
                    T2_xit = true;
                }
    
                 // Set 4
                 // T3 Exit, 1/3 position
                if ( <set 4 condition> )
                     && (T3_xit == false)
                     && (T1_xit == true)
                     && (T2_xit == true))
                {
                    ExitLong(Convert.ToInt32(100), @"t3", @"b1");
                    T3_xit = true;
                }                
            }

Latest Posts

Collapse

Topics Statistics Last Post
Started by Kediil, Today, 09:26 AM
0 responses
1 view
0 likes
Last Post Kediil
by Kediil
 
Started by bootize, Today, 08:37 AM
0 responses
6 views
0 likes
Last Post bootize
by bootize
 
Started by _Zero_, 01-06-2020, 01:16 PM
4 responses
138 views
2 likes
Last Post globaljobber  
Started by sukhob, Yesterday, 04:27 PM
2 responses
21 views
0 likes
Last Post sukhob
by sukhob
 
Started by zacharydw00, Yesterday, 05:36 PM
0 responses
6 views
0 likes
Last Post zacharydw00  
Working...
X