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, 04-17-2024, 06:40 PM
    6 responses
    49 views
    0 likes
    Last Post algospoke  
    Started by arvidvanstaey, Today, 02:19 PM
    4 responses
    11 views
    0 likes
    Last Post arvidvanstaey  
    Started by samish18, 04-17-2024, 08:57 AM
    16 responses
    61 views
    0 likes
    Last Post samish18  
    Started by jordanq2, Today, 03:10 PM
    2 responses
    9 views
    0 likes
    Last Post jordanq2  
    Started by traderqz, Today, 12:06 AM
    10 responses
    21 views
    0 likes
    Last Post traderqz  
    Working...
    X