Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Consecutive Losers - Don't take next signal

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

    Consecutive Losers - Don't take next signal

    I have checked out the sample code on consecutive losers, stopping the "session" after a certain amount of consecutive losers or profit/loss target

    Two questions associated with those samples

    1) It doesn't appear that sample code defines the session. What is the session if I am using daily charts?

    2) I'd like to skip the next signal in the strategy after a loser. How do I re-start the strategy after a loser without referencing the end of a session.

    Thank you

    #2
    Hi titleistbb22,

    With some custom coding you could likely do something with BarsSinceExit(), MRO, or LRO

    BarsSinceExit - http://www.ninjatrader-support.com/H...?BarsSinceExit

    MRO - http://www.ninjatrader-support.com/H...ntOccurenceMRO

    LRO - http://www.ninjatrader-support.com/H...ntOccurenceLRO
    Last edited by NinjaTrader_Tim; 07-13-2010, 10:21 PM.
    TimNinjaTrader Customer Service

    Comment


      #3
      thank you - I will work wth that

      Comment


        #4
        Here is what I came up with

        //use MRO, realized profit > 0, returns -1 if condition didnt occur w/in look back period

        {
        int barsAgo = MRO(delegate {return Performance.AllTrades.TradesPerformance.Currency.C umProfit > 0;}, 1, 30);
        {
        if (barsAgo == -1)
        lastTrade--;
        elseif (barsAgo != -1)
        lastTrade =
        0;
        }
        }

        I am using lastTrade as a counter and placing it as a condition to my entry (i.e. if (lastTrade != -1) then enter a trade). In spot checking this doesnt appear to be working properly. Anything you can see that looks out of place? thank you

        Comment


          #5
          Hello,

          I will have someone reply to you on Monday. Thank you for your patience.
          DenNinjaTrader Customer Service

          Comment


            #6
            You appear to be looking at the cumulative profit rather than the last trade.

            try something like this in OnExecution

            Code:
               if (Position.MarketPosition == MarketPosition.Flat) { // only closing trades
                      Trade last = Performance.AllTrades[Performance.AllTrades.Count-1];
            Then check

            Code:
            last.ProfitCurrency < 0
            to tell you whether the last trade was a loser

            Comment


              #7
              Thank you - that is helpful - two questions, does this code work in OnBarUpdate as well as OnExecution? Also, similar to the sample code on this subject, do you need to define "Performance" (sample code below)

              // Loop through the last three trades and check profit/loss on each.
              for (int idx = 1; idx <= 3; idx++)
              {
              /* The Performance.AllTrades array stores the most recent trade at the highest index value. If there are a total of 10 trades,
              this loop will retrieve the 10th trade first (at index position 9), then the 9th trade (at 8), then the 8th trade. */
              Trade trade = Performance.AllTrades[Performance.AllTrades.Count - idx];
              /* If the trade's profit is greater than 0, add one to the counter. If the trade's profit is less than 0, subtract one. This logic means break-even trades have no effect on the counter. */
              if (trade.ProfitCurrency>0)
              lastThreeTrades++;
              else if (trade.ProfitCurrency < 0)
              lastThreeTrades--;


              Side note - Im struggling to understand what the red text of the sample code is doing. Thanks

              Comment


                #8
                Hello,

                The code would work in OnBarUpdate, but there's no way you could be sure the last trade had been executed, so your results wouldn't be certain.

                You don't need to define Performance. Regarding the for loop, assuming you know what a for loop does (if not you need to read about basic c# - plenty on the web) then idx goes from 1 to 3, and each time you subtract it from Count, which is the number of trades in the array. The result gives you the index in the array to those last three trades.

                If there are 10 trades, Count = 10, the indexes go from 0 to 9. So the last three trades are indexed by

                10-1 = 9
                10-2 = 8
                10-3 = 7

                The for loop gives you the 1,2,3

                Comment


                  #9
                  Hi titleistbb22,

                  Additinally, here is some more info on Looping Commands:
                  TimNinjaTrader Customer Service

                  Comment


                    #10
                    Thank you - lets set the loop aside, I dont think its needed in this case.

                    Here's what I came up with on my first run through the OnExecution method and its not compiling. I'm sure its something simple I'm missing.

                    protectedoverridevoid OnExecution(IExecution execution)
                    {
                    if (entryOrder != null && entryOrder.Token == execution.Order.Token)
                    {
                    //checks that the Trade was filled or Patially filled
                    if ((execution.Order.OrderState == OrderState.Filled ||execution.Order.OrderState == OrderState.PartFilled ))
                    {



                    if (Position.MarketPosition == MarketPosition.Flat) // only closing trades
                    {
                    Trade last = Performance.AllTrades[Performance.AllTrades.Count-
                    1];

                    if (trade.ProfitCurrency > 0)
                    input3==
                    0;
                    else (trade.ProfitCurrency < 0)
                    input3--;
                    }


                    entryOrder =
                    null;
                    }

                    Thanks in advance for taking a look - input3 is my counter and is defined in the variables section

                    Comment


                      #11
                      If something doesn't compile, you really need to give us the error to save time.

                      Having said that, at first glance you have no spaces in

                      protectedoverridevoid

                      Comment


                        #12
                        sorry - when I copied and pasted it slammed protected override void, I do have spaces.

                        The 1st error I get is " ;expected" in the "else (trade.ProfitCurrency < 0)" line.

                        when I add ";" to that line I get the following errors:

                        - only assignment, call, increment, decrement, and new object expressions on line "input3==0;" and line "input3--;"

                        - the name 'trade' does not exist in the current context on line "if (trade.ProfitCurrency > 0)" and line "else (trade.ProfitCurrency < 0);"

                        Thank you

                        Comment


                          #13
                          I think you would benefit from going through a basic c# tutorial.

                          you can't do

                          else (condition)
                          action

                          you can do

                          else if (condition)
                          action

                          or

                          else
                          action

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          647 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          368 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          108 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          571 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          573 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X