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 alifarahani, 04-19-2024, 09:40 AM
    8 responses
    52 views
    0 likes
    Last Post alifarahani  
    Started by mmckinnm, Today, 01:34 PM
    2 responses
    4 views
    0 likes
    Last Post mmckinnm  
    Started by Conceptzx, 10-11-2022, 06:38 AM
    3 responses
    60 views
    0 likes
    Last Post NinjaTrader_SeanH  
    Started by f.saeidi, Today, 01:32 PM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by traderqz, Today, 12:06 AM
    9 responses
    16 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X