Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily Profit / loss question

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

    Daily Profit / loss question

    I’m working on a strategy that has a daily profit target and daily loss but I can’t get it to work when I back test it. it works fine when I live sim trade it. When I back test it, it makes the profit target but then stops trading for the rest of the year


    here is the code
    if (Position.MarketPosition == MarketPosition.Flat) // Only calculate when position is flat
    {
    if (Bars.FirstBarOfSession)
    {
    cumprofit = Performance.AllTrades.TradesPerformance.Currency.C umProfit; // Calculate the cumprofit all strategy days
    todaysPL = Performance.AllTrades.TradesPerformance.Currency.C umProfit - cumprofit; // Reset todays P&L
    PrintWithTimeStamp("FirstBarOfSession!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    }

    // Calculate todays P&L
    if (todaysPL != Performance.AllTrades.TradesPerformance.Currency.C umProfit - cumprofit)
    {
    todaysPL = Performance.AllTrades.TradesPerformance.Currency.C umProfit - cumprofit;

    }

    // Halts strategy when todays P&L exceeds limits


    if (Performance.AllTrades.TradesPerformance.Currency. CumProfit - cumprofit >= maxprofit
    || Performance.AllTrades.TradesPerformance.Currency.C umProfit - cumprofit <= -maxloss)


    {


    strategyHalt = true;
    return;
    }

    }




    Any ideas or can anyone point me in a direction?
    Last edited by EvilHog; 02-15-2012, 07:05 PM.

    #2
    EvilHog, it sounds then like your reset point for the historical daily calcs of stop / target is not correctly met in backtesting, I would suggest printing the values of your cumprofit and todaysPL variables to see where the values report differently as you expect and then modify as needed.

    Here's also a reference sample dealing with the same topics - http://www.ninjatrader.com/support/f...ead.php?t=4084
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Perr0Grande, Yesterday, 08:16 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by f.saeidi, Yesterday, 08:12 AM
    3 responses
    24 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by algospoke, Yesterday, 06:40 PM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by quantismo, Yesterday, 05:13 PM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by The_Sec, 04-16-2024, 02:29 PM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_ChristopherS  
    Working...
    X