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

ExitShortStop in backtesting issue

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

    ExitShortStop in backtesting issue

    Hi,

    I have strategy that I am backtesting that makes use of the ExitShortStop function. Occasionally in my backtest results, an entry order is executed but the stop is not triggered when it should be. In one case where I notice is when the entry is on the open of the next bar and the same bar closes way above where my stop should have been executed. Could this be due to the fact that my entry and exit should have been on the same bar and that the backtesting engine does not enter the stop since the bar closes above the stop price? Would I need to worry about this if I were trading the strategy in realtime? Should I replace ExitStopShort with SetStopLoss and translate the price to ticks?

    Here is a code snippet to make sure I don't have any syntax errors along with a screenshot of where the stop does not get executed: Please note the stop variable is set to 1.00.

    //This code limits my daily loss to 400
    if(Performance.AllTrades.TradesPerformance.Currenc y.CumProfit - priorTradesCumProfit <= -400 && Position.MarketPosition==MarketPosition.Flat)
    return;

    //Simplified short entry
    if(ToTime(Time[0]) >= timeOpen && ToTime(Time[0])< timeClose &&
    Position.MarketPosition == MarketPosition.Flat)
    {

    if(Close[0]>Close[1] )

    {



    //PrintWithTimeStamp(Close[0].ToString()+" "+DayOpen.ToString());

    EnterShort("Sell");

    }

    }

    if(Position.MarketPosition == MarketPosition.Short)
    {


    //double DStop = Position.AvgPrice+stop;
    double DStop = Position.AvgPrice + ((stop*4)*TickSize);
    double DTarget=Position.AvgPrice-target;
    PrintWithTimeStamp("Entered Short. DayOpen is:"+DayOpen.ToString()+"EntryPrice :"+Position.AvgPrice+" ProfitTarget :"+DTarget.ToString()+ " Stop :"+DStop.ToString());

    ExitShortStop(Position.AvgPrice + ((stop*4)*TickSize),"BuyStp","Sell");

    ExitShortLimit(DTarget,"Sell");

    }

    As you can see from the screenshot, a short is entered around 1430 and it should have been immediately stopped out 4 ticks later but does not execute until after the market closes below the stop price and then closes back above around 15:00.

    Thanks for looking into this.
    Attached Files

    #2
    Hello Cowpux,

    Thank you for your note.

    Are you calling ExitShort() anywhere in the code? The order name on the screenshot is for a market exit order with no custom signal name attached.


    Please add TraceOrders = true; to your Initialize() method

    This will print out the orders being submitted and what their status is.
    Cal H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by arvidvanstaey, Today, 02:19 PM
    0 responses
    2 views
    0 likes
    Last Post arvidvanstaey  
    Started by mmckinnm, Today, 01:34 PM
    3 responses
    5 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by f.saeidi, Today, 01:32 PM
    2 responses
    5 views
    0 likes
    Last Post f.saeidi  
    Started by alifarahani, 04-19-2024, 09:40 AM
    9 responses
    55 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Conceptzx, 10-11-2022, 06:38 AM
    3 responses
    60 views
    0 likes
    Last Post NinjaTrader_SeanH  
    Working...
    X