Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Newb question re stop orders

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

    Newb question re stop orders

    Sorry if this is a dumb question but why does this code never issue a sell-on-stop order? What I want to do is buy when a resistance level is broken, and set a stop at the old resistance level. However, the stop order never shows up in backtesting.

    NB this isn't a system, I just reduced it to a trivial example to figure it out.

    Code:
    protected override void Initialize()
            {
                Add(Swing(Lookback));
                Add(Swing(Lookback));
    
                CalculateOnBarClose = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1
                if (CrossAbove(Close, Swing(Lookback).SwingHigh, 1)
                    && Position.MarketPosition != MarketPosition.Long)
                {
                    EnterLong(DefaultQuantity, "");
                    ExitLongStop(Swing(Lookback).SwingHigh[0], "", "");
                }
    
                // Condition set 2
                if (CrossBelow(Close, Swing(Lookback).SwingLow, 1))
                {
                    ExitLong("", "");
                }
            }

    #2
    The ExitLongStop() is only affective once you have a position open. At the time it is called, you do not have a position open. Move this out of the condition and add something like:

    if (Position.MarketPosition == MarketPosition.Long)
    ExitLongStop(yourParametersHere);
    RayNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by techgetgame, Yesterday, 11:42 PM
    0 responses
    8 views
    0 likes
    Last Post techgetgame  
    Started by sephichapdson, Yesterday, 11:36 PM
    0 responses
    2 views
    0 likes
    Last Post sephichapdson  
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,613 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Yesterday, 05:56 PM
    0 responses
    10 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    20 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Working...
    X