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 Christopher_R, Today, 12:29 AM
    0 responses
    9 views
    0 likes
    Last Post Christopher_R  
    Started by sidlercom80, 10-28-2023, 08:49 AM
    166 responses
    2,235 views
    0 likes
    Last Post sidlercom80  
    Started by thread, Yesterday, 11:58 PM
    0 responses
    3 views
    0 likes
    Last Post thread
    by thread
     
    Started by jclose, Yesterday, 09:37 PM
    0 responses
    8 views
    0 likes
    Last Post jclose
    by jclose
     
    Started by WeyldFalcon, 08-07-2020, 06:13 AM
    10 responses
    1,415 views
    0 likes
    Last Post Traderontheroad  
    Working...
    X