Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Average Losses Indicator Question

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

    Average Losses Indicator Question

    Hey guys, I'm working on a formula to determine my Average Consecutive Loss (ACL) for my custom Indicator. and The problem I'm having is with a couple of Variables.

    My indicator Works like this:
    Step 1: A Trade Losses, Variable lastTradeLoss++;
    Step 2: A Trade Wins, Variable lastTradeLoss = 0; //Resets Variable at each Win
    Step 3: Two Losses in a Row, if(lastTradeLoss > 1) //This Triggers my Loss Sequence
    Code:
    	//CONSECUTIVE LOSSes ALGORITHM: Fires Only after 2 Consecutive Losses
    					#region Losses Algorithm
    						if(lastTradeLoss > 1)
    						{
    							beginSequence = true;	
    					lossPerSeq = lastTradeLoss; //Amount of Losses for This Sequence
    						}
    Up to this point everything is Good. the lossPerSeq variable Holds the Amount of Trades Lost in this sequence. Here's a problem I'm having. I want to take the lossPerSeq and Store it in another Variable (totalLossPerSeq) that will later be used in my ACL = totalLossPerSeq / numberOfSeq;

    But every time a Trade Wins the lastTradeLoss = 0;
    So I tried this totalLossPerSeq = lossPerSeq; and that can't work cause of the resetting problem.

    I tried totalLossPerSeq = lossPerSeq + totalLossPerSeq; and that Didn't work either.

    BASICALLY: I just want to know how should I store the Number of Losses from each Sequence so that it can be used in A.C.L calculation. Without storing every single Loss taken. that's why I RESET lastTradeLoss at the End of Each Sequence.

    Thanks in ADvance

    #2
    Hello,

    Thank you for the question.

    I would need to see where you have the reset for lossPerSeq in order to determine what may be happening.

    What you have pasted looks correct, you are setting lossPerSeq to the current value of lastTradeLoss. If lastTradeLoss is not reset before this point I would expect the lossPerSeq to be the same value.

    Have you put a Print() in the condition where the following syntax is located to see the value of lastTradeLoss at the time it is set?

    Code:
    lossPerSeq = lastTradeLoss;
    Print("lossPerSeq " + lossPerSeq + "  lastTradeLoss " + lastTradeLoss);
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      The Reset for lossPerSeq happens when a { Trade Wins }, This Breaks the Consecutive Losing Sequence.

      So imagine, after 2 Losses, if next 2 trade lose, then a Win occurs, the Sequence is Exited and lossPerSeq is = 0; but the Total Losses in that Sequence is 4 Losses. How do I extract that Number and keep it updating on Every Sequence.

      I don't have a Print statement but I made a DrawText that shows exactly Where and When The Sequence is and The Current Values for each sequence.

      Here's a Pic: http://screencast.com/t/NhcT4wEg

      Comment


        #4
        Hello,

        Thank you for the reply.

        Can you please try using a print in the condition instead?

        The condition is happening but the value is not what you are expecting, so knowing when is not necessarily what we need to know in this situation. This would likely be easier to understand if we know the value at the time of the condition to see if the reset has already occurred or if this is related to the other code for the visual that is on the chart.

        If at that point in time the lastTradeLoss value equals 0 or has already been reset, then logic would be working correctly in the sense that it just assigned the correct value to the variable for that time. Otherwise if the value is the correct value, this would indicate it is not this section of code and is likely somewhere else.

        In either case you would need to take a look at the order of events happening in the script to see where the error is.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by ginx10k View Post
          Hey guys, I'm working on a formula to determine my Average Consecutive Loss (ACL) for my custom Indicator. and The problem I'm having is with a couple of Variables.

          My indicator Works like this:
          Step 1: A Trade Losses, Variable lastTradeLoss++;
          Step 2: A Trade Wins, Variable lastTradeLoss = 0; //Resets Variable at each Win
          Step 3: Two Losses in a Row, if(lastTradeLoss > 1) //This Triggers my Loss Sequence
          Code:
          	//CONSECUTIVE LOSSes ALGORITHM: Fires Only after 2 Consecutive Losses
          					#region Losses Algorithm
          						if(lastTradeLoss > 1)
          						{
          							beginSequence = true;	
          					lossPerSeq = lastTradeLoss; //Amount of Losses for This Sequence
          						}
          Up to this point everything is Good. the lossPerSeq variable Holds the Amount of Trades Lost in this sequence. Here's a problem I'm having. I want to take the lossPerSeq and Store it in another Variable (totalLossPerSeq) that will later be used in my ACL = totalLossPerSeq / numberOfSeq;

          But every time a Trade Wins the lastTradeLoss = 0;
          So I tried this totalLossPerSeq = lossPerSeq; and that can't work cause of the resetting problem.

          I tried totalLossPerSeq = lossPerSeq + totalLossPerSeq; and that Didn't work either.

          BASICALLY: I just want to know how should I store the Number of Losses from each Sequence so that it can be used in A.C.L calculation. Without storing every single Loss taken. that's why I RESET lastTradeLoss at the End of Each Sequence.

          Thanks in ADvance
          //Step 1.5
          totalLossPerSeq = lastTradeLoss; //will hold value until next bar.

          Comment


            #6
            Okay, I've created a Sample of what my indicator does. You can see for yourself where the Value resets and what not. It's a super simplified version. but hopefully it'll help you see what It does so that you can help me get the value of totalLossesPerSeq to keep increasing by ONLY taking the Losses on Each Sequence. Not every Loss that occurs.
            Attached Files

            Comment


              #7
              Originally posted by koganam View Post
              //Step 1.5
              totalLossPerSeq = lastTradeLoss; //will hold value until next bar.
              Thanks, but I already have that Line written in, and it Doesn't help. But thanks anyways Koganam.

              I need some sort of way to keep the Value of TOTAL LOSSeS in a Sequence and when that Sequence Ends, and another begins, the TotalLosses keeps getting Updated. The Only thing that totalLossPerSeq = lastTradeLoss; is doing right now, is Keeping the value until the Next Win. at which Point it will be Reset.

              Comment


                #8
                Hello,

                I wanted to get some clarification, are you saying that you want to be able to access farther back that 1 instance of the value? I.E. like a DataSeries with a BarsAgo?

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello,

                  I wanted to get some clarification, are you saying that you want to be able to access farther back that 1 instance of the value? I.E. like a DataSeries with a BarsAgo?

                  I look forward to being of further assistance.

                  Let me see if I can rephrase this: First what I'm about to write, don't think of it as Code yet. just the Concept then maybe it'll be clearer for you. and thanks for taking your time with this, by the way.


                  STEP 1: Two Losses Occur in a Row ---->>>>>This Triggers Sequence 1,
                  Code:
                  if(lastTradeLoss > 1)
                  						{
                  							beginSequence = true;	
                  							lossPerSeq = lastTradeLoss; //Amount of Losses for This Sequence
                  						}
                  That Part is Okay for Now

                  STEP 2: While in Sequence 1, 2 More Losses Occur (NO WINNING Trades) --->>
                  Code:
                  lossPerSeq = lastTradeLoss;
                  Adds those Two Losses to Total Losses For This Single Sequence 1.

                  STEP 3: a Winning Trade Occurs, --> This CLOSES Sequence 1 and Resets lastTradeLoss = 0. Here's a Problem because I DO want lastTradeLoss to be Reset to 0. But Now I want to Store the Value of lossPerSeq which I tried to do by
                  Code:
                  ttlLssPerSeq = lossPerSeq;
                  I hope I've been clear So Far. Now, if I only wanted One Single Sequence, this code so far would be Perfect. but the problem is that the Next sequence occurs

                  STEP 1: Two Losses Occur in a Row ---->>>>>This Triggers Sequence 2
                  .....etc...

                  So now that Sequence 2 is triggered, if I use the Line
                  Code:
                  ttlLssPerSeq = lossPerSeq;
                  It Resets the ttlLssPerSeq to equal the New Value of lossPerSeq.

                  BUT THAT"S NOT WHAT I WANT. I WANT To HOLD the Old Value of ttlLssPerSeq from the last sequence, this has Nothing to do with Dataseries. I Simply Want to HOLD the Value of Each Sequence's Losses, and Accumulate them in Some Kind of Variable that will Later be referenced for What Ever

                  Comment


                    #10
                    Before this is Posted. I HAVe also Tried this Code
                    Code:
                    ttlLssPerSeq = lossPerSeq; + ttlLssPerSeq
                    But That Does NOT work either. So Please Help.

                    Comment


                      #11
                      Hello,

                      Just to be clear, you are simply trying to Accumulate the values over a period of time correct?

                      If so, the following would not work as there is a semi colon between the variable and the plus symbol:

                      Code:
                      ttlLssPerSeq = lossPerSeq; + ttlLssPerSeq
                      Would this not be what you are looking to do:.

                      Code:
                      if(lastTradeLoss > 1)
                      {
                      	beginSequence = true;	
                      	lossPerSeq = lastTradeLoss; //Amount of Losses for This Sequence					
                      }
                      //Total Losses Accumulated over each sequence
                      ttlLssPerSeq += lossPerSeq;
                      Print("LastLoss =: " + ttlLssPerSeq);

                      Using += I can accumulate the new value, the resulting output on my end was:

                      Code:
                      LastLoss =: 2
                      LastLoss =: 4
                      LastLoss =: 6
                      LastLoss =: 9
                      LastLoss =: 12
                      LastLoss =: 15
                      LastLoss =: 18
                      LastLoss =: 22
                      LastLoss =: 26
                      LastLoss =: 30
                      LastLoss =: 35
                      LastLoss =: 40
                      LastLoss =: 45
                      LastLoss =: 51
                      LastLoss =: 57
                      etc..
                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        To Be Clear, Yes I am Looking for Accumulated value Per Sequence. I used you're exact statement, and I'm still getting something Odd.

                        First I added the
                        Code:
                        	if(Bars.FirstBarOfSession)
                        		{	//First Bar of NEW Day, RESET ALL COUNTERS
                        			lastTradeLoss = 0; ttlLssPerSeq = 0;
                        			numOfSequences = 0;	ACL = 0;	beginSequence = false;	lossPerSeq = 0;
                        		}
                        Because I want the Losses for the Current Day ONLY.

                        Then when I look at the first Sequence (which had 2 Losses only) somehow the TotalLossPerSq shows = 17

                        PIC HERE: http://screencast.com/t/gViYk6Uuy4rJ

                        I don't understand why it's showing this many losses.

                        Comment


                          #13
                          Originally posted by ginx10k View Post
                          Let me see if I can rephrase this: First what I'm about to write, don't think of it as Code yet. just the Concept then maybe it'll be clearer for you. and thanks for taking your time with this, by the way.


                          STEP 1: Two Losses Occur in a Row ---->>>>>This Triggers Sequence 1,
                          Code:
                          if(lastTradeLoss > 1)
                          						{
                          							beginSequence = true;	
                          							lossPerSeq = lastTradeLoss; //Amount of Losses for This Sequence
                          						}
                          That Part is Okay for Now

                          STEP 2: While in Sequence 1, 2 More Losses Occur (NO WINNING Trades) --->>
                          Code:
                          lossPerSeq = lastTradeLoss;
                          Adds those Two Losses to Total Losses For This Single Sequence 1.

                          STEP 3: a Winning Trade Occurs, --> This CLOSES Sequence 1 and Resets lastTradeLoss = 0. Here's a Problem because I DO want lastTradeLoss to be Reset to 0. But Now I want to Store the Value of lossPerSeq which I tried to do by
                          Code:
                          ttlLssPerSeq = lossPerSeq;
                          I hope I've been clear So Far. Now, if I only wanted One Single Sequence, this code so far would be Perfect. but the problem is that the Next sequence occurs

                          STEP 1: Two Losses Occur in a Row ---->>>>>This Triggers Sequence 2
                          .....etc...

                          So now that Sequence 2 is triggered, if I use the Line
                          Code:
                          ttlLssPerSeq = lossPerSeq;
                          It Resets the ttlLssPerSeq to equal the New Value of lossPerSeq.

                          BUT THAT"S NOT WHAT I WANT. I WANT To HOLD the Old Value of ttlLssPerSeq from the last sequence, this has Nothing to do with Dataseries. I Simply Want to HOLD the Value of Each Sequence's Losses, and Accumulate them in Some Kind of Variable that will Later be referenced for What Ever
                          Not clear. If you want to keep more than one value, you will need a collection of values. Use a generic List.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by gbal16, Yesterday, 08:12 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post gbal16
                          by gbal16
                           
                          Started by BraisedInBlue, Today, 06:43 AM
                          1 response
                          9 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Started by AaronKoRn, Today, 06:28 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_Zachary  
                          Started by Mabba, Today, 04:56 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Started by moehsan, Yesterday, 09:47 PM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Working...
                          X