• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 Gerik, Today, 10:58 PM
    0 responses
    1 view
    0 likes
    Last Post Gerik
    by Gerik
     
    Vps by stooby
    Started by stooby, Today, 08:32 PM
    0 responses
    11 views
    0 likes
    Last Post stooby
    by stooby
     
    Started by FaaastEddy, Today, 08:25 PM
    0 responses
    3 views
    0 likes
    Last Post FaaastEddy  
    Started by YevhenShynkarenko, Yesterday, 01:22 AM
    2 responses
    39 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by testingsarasa, 05-20-2018, 02:50 PM
    11 responses
    739 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X