Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Last trade profit

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

    #31
    Thanks Kate. the strategy does exactly do that. It takes a trade after X losers. Problem is after the first trade is taken, it completely stops taking trades. What I want to achieve is see the trades it did not take and the trades it took on the chart. I can always open another chart and see all trades taken with all the conditions except the X losers in a row. For some reason after it takes the first trade and say that is a winner, it will not calculate any further on the chart. I want it to continue doing so in order to trade after X losses in a row. Is it possible in Ninja?
    Thanks.

    Comment


      #32
      Hello Trader17,

      Thank you for your reply.

      Would you be able to give a code sample of the logic you're currently using to control your entries?

      Thanks in advance; I look forward to assisting you further.
      Kate W.NinjaTrader Customer Service

      Comment


        #33
        Sure. Here you go.

        Code:
        protected override void OnBarUpdate()
        {
        
        NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
        NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
        
        if (barsType == null)
        return;
        
        if (BarsInProgress != 0)
        return;
        
        if (CurrentBars[0] < 20)
        return;
        
        double val1 = barsType.Volumes[CurrentBar].CumulativeDelta;
        
        double val2 = barsType.Volumes[CurrentBar-BarsAgo].CumulativeDelta;
        
        
        if (SystemPerformance.AllTrades.Count > 0)
        {
        firstTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency;
        if (SystemPerformance.AllTrades.Count > 1)
        {
        secondTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 2].ProfitCurrency;
        }
        }
        
        // Set 1
        
        
        if ( Low[0] < Low[BarsAgo] && Close[0] > Open[0] && val1 > val2 && Low[0] <= MIN1[1] && firstTradeProfitCurrency <= 0 && secondTradeProfitCurrency <= 0 ) //&& Low[0] <= MIN(Low,5)[1]) // Low[1] <= MIN(Low,5)[2]
        {
        EnterLong(Convert.ToInt32(DefaultQuantity), "");
        }
        
        // Set 2
        if ( High[0] > High[BarsAgo] && Close[0] < Open[0] && val1 < val2 && High[0] >= MAX1[1] && firstTradeProfitCurrency <= 0 && secondTradeProfitCurrency <= 0 )//&& firstTradeProfitCurrency < 0 && secondTradeProfitCurrency < 0 )//High[0] >= MAX(High,5)[1] ) // High[1] >= MAX(High,5)[2]
        {
        EnterShort(Convert.ToInt32(DefaultQuantity), "");
        }
        You could use a simpler version like if Close[0] > Close[1] then Enter Long. And set profit and stop to 5 ticks.

        My problem or challenge I am facing in NT8 is how to let the strategy log in trades when conditions are met and only trade when we see a sequence of X number of winning or losing trades. Because as soon as I do it as in the code above it will not take any more trades after the first one as the sequence does not exist as I guess the strategy is not logging in any more trades. So my main issue here is logging in all trades signaled and only take trades when a sequence is met.

        Thanks a lot Angel!!

        Comment


          #34
          Hello Trader17,

          Thank you for your reply.

          SystemPerformance.AllTrades would only contain trades actually taken. Signals that do not take a trade would not be counted in SystemPerformance.AllTrades. You would need to create your own logic to check conditions, using variables to track how many times you've hit certain conditions, and if you get three conditions that would indicate you would have had a "loss" then actually enter after the third time.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment


            #35
            How would you create such logic as a trade has to be taken and completed to get the profit/loss outcome? Where is that record kept if not by System Performance? That is where I am fumbling. I am looking for a log of winning and losing trades without being actually traded by the system. I thought a trade has to be executed in order for the outcome to be logged in. How would I do that without using "Enter Long" in the conditions?
            Thanks.

            Comment


              #36
              Thanks Kate. So am I on the right track here?
              Code:
              protected override void OnBarUpdate()
              {
              
              if (CurrentBar < BarsRequiredToTrade)
              return;
              
              for (int idx = 1; idx <= 2; idx++)
              {
              
              Trade trade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - idx];
              
              if (trade.ProfitCurrency > 0)
              {
              lastTwoTrades++;
              }
              
              else if (trade.ProfitCurrency < 0)
              {
              lastTwoTrades--;
              }
              
              }
              And then in my condition to trade add a condition like if (lastTwoTrades = -2) to only take a trade after 2 losses in a row.

              Am I correct and the code above is Ninja compliant?

              Thanks a lot.

              Comment


                #37
                Originally posted by NinjaTrader_Kate View Post
                Hello Trader17,

                Thank you for your reply.

                SystemPerformance.AllTrades would only contain trades actually taken. Signals that do not take a trade would not be counted in SystemPerformance.AllTrades. You would need to create your own logic to check conditions, using variables to track how many times you've hit certain conditions, and if you get three conditions that would indicate you would have had a "loss" then actually enter after the third time.

                Please let us know if we may be of further assistance to you.
                So it is not the conditions, but rather the outcome of the condition I am interested in. Do we have an example script somewhere? How can I extract profit/loss figures on a trade without the strategy actually taking the trade? Because System performance only returns profit/loss values of trades actually taken by the strategy. So I am trying to account for "virtual" and "real" trades in a strategy at once. Can NT8 even do such a thing? I am not too sure about extracting profit/loss from a trade without actually taking it.

                Thanks for all your help.
                Last edited by Trader17; 08-22-2020, 10:22 AM.

                Comment


                  #38
                  Hello Trader17,

                  Thank you for your reply.

                  I do not have any examples of such a script. This would require you to do your own tracking with variables for the current price at the time the position would have been opened and closed, and calculating whether the trade would have been a winner or a loser by subtracting the Close price from the Open price. You could then save that value in a List<T> and refer back to that to see how many would have closed negative. The logic could be somewhat tricky and the "virtual trades" you create in this way would not be accounting for market dynamics that could affect fill prices on a "real" order.

                  Please let us know if we may be of further assistance to you.

                  Kate W.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by junkone, Today, 11:37 AM
                  2 responses
                  12 views
                  0 likes
                  Last Post junkone
                  by junkone
                   
                  Started by frankthearm, Yesterday, 09:08 AM
                  12 responses
                  43 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by quantismo, 04-17-2024, 05:13 PM
                  5 responses
                  35 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by proptrade13, Today, 11:06 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by love2code2trade, 04-17-2024, 01:45 PM
                  4 responses
                  35 views
                  0 likes
                  Last Post love2code2trade  
                  Working...
                  X