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 algospoke, Yesterday, 06:40 PM
    2 responses
    23 views
    0 likes
    Last Post algospoke  
    Started by ghoul, Today, 06:02 PM
    3 responses
    14 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    45 views
    0 likes
    Last Post jeronymite  
    Started by Barry Milan, Yesterday, 10:35 PM
    7 responses
    22 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by AttiM, 02-14-2024, 05:20 PM
    10 responses
    181 views
    0 likes
    Last Post jeronymite  
    Working...
    X