Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Losses for day

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

    Losses for day

    I am running thru a number of days data.
    I want to monitor and do no more trades for day once a certain loss happens.
    But when it gets to new day trades can once again happen.

    I am getting following error after a number of days performing above goal
    **NT** Error on calling 'OnPositionUpdate' method for strategy 'BobGoldStandardV22/a08c3141938c43c085f2a5126c6981e1': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    The code I think is causing it is:
    protectedoverridevoid OnPositionUpdate(IPosition position)
    {
    if (Position.MarketPosition == MarketPosition.Flat)
    {

    if (Performance.AllTrades.LosingTrades.Count > 0)
    {
    Trade lastTrade = Performance.AllTrades.LosingTrades[Performance.AllTrades.Count -
    1];
    double profitDollars = lastTrade.ProfitCurrency;
    if (profitDollars != null && profitDollars < 0)
    {
    //The plan is once you have a negative dollar amount for day especially first trade of day
    //Stop trading until next day
    //On Barupdate if flat will reset these on new day
    bStopTrading = true;
    DayOfWeek = (
    0 - Time[0].DayOfWeek ); // Day of failure
    }
    else
    {
    bStopTrading =
    false;
    DayOfWeek = -
    99;

    }
    }
    else
    {
    bStopTrading =
    false;
    DayOfWeek = -
    99;
    }
    //Document current profit/loss
    Print(Time[0] + "Profit/Loss "+ (Performance.RealtimeTrades.TradesPerformance.Gros sProfit +
    Performance.RealtimeTrades.TradesPerformance.Gross Loss ) ) ;



    #2
    Hello bbucha_stk,

    Thank you for your post.

    Please provide a toy version of your strategy that I may test on my end to investigate this matter further.

    I look forward to your response.

    Comment


      #3
      It will be easier to send you the code..
      Let me know on my email where to email

      Comment


        #4
        Hello bbucha_stk,

        Thank you for your response.

        Please send a note to support[at]ninjatrader[dot]com with 'ATTN: Patrick' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=55538

        I look forward to assisting you further.

        Comment


          #5
          Hello bbucha_stk,

          Thank you for your response.

          You will need to make sure you have enough bars on the chart before accessing them.

          You can do this by adding the following at the start of OnBarUpdate(): if(CurrentBar < BarsRequired)return;

          For information on this matter please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170
          Please let me know if I may be of further assistance.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by OllieFeraher, 05-09-2024, 11:14 AM
          4 responses
          14 views
          0 likes
          Last Post MisterTee  
          Started by dcriador, Today, 12:06 PM
          0 responses
          10 views
          0 likes
          Last Post dcriador  
          Started by dcriador, Today, 12:04 PM
          0 responses
          6 views
          0 likes
          Last Post dcriador  
          Started by cutzpr, Today, 08:54 AM
          0 responses
          11 views
          0 likes
          Last Post cutzpr
          by cutzpr
           
          Started by benmarkal, Today, 08:44 AM
          0 responses
          23 views
          0 likes
          Last Post benmarkal  
          Working...
          X