• 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

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 Austiner87, Yesterday, 09:33 PM
    0 responses
    6 views
    0 likes
    Last Post Austiner87  
    Started by HiddenPhilosopher, Yesterday, 07:24 PM
    0 responses
    10 views
    0 likes
    Last Post HiddenPhilosopher  
    Started by dkbyond, Yesterday, 06:43 PM
    0 responses
    10 views
    0 likes
    Last Post dkbyond
    by dkbyond
     
    Started by i2w8am9ii2, Yesterday, 06:05 PM
    0 responses
    5 views
    0 likes
    Last Post i2w8am9ii2  
    Started by YevhenShynkarenko, Yesterday, 05:46 PM
    0 responses
    6 views
    0 likes
    Last Post YevhenShynkarenko  
    Working...
    X