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

Exit Strategy with point values not working

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

    Exit Strategy with point values not working

    Hi,
    I am testing a FX strategy with an exit after a certain profit. The code works fine if I define the profit in percent or currency. But if I set the PerformanceUnit to points, the strategy fails to exit at the correct moment. How can I fix this?
    Code with currency
    Code:
    if (Performance.AllTrades.TradesPerformance.Currency.CumProfit + Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) >= Profit)
                {
                    ExitLong("", "");
                    ExitShort("", "");
                }
    Code with points
    Code:
    if (Performance.AllTrades.TradesPerformance.Points.CumProfit + Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= Profit)
                {
                    ExitLong("", "");
                    ExitShort("", "");
                 }

    #2
    What is the value you are using for Profit?

    Depending on the increment you are using you may need to multiply Profit by TisckSize to get the desired size.



    Let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      I added the TickSize but still get the same result. NT is not checking the unrealized profit, only the reacts on the realized profit.
      "Profit" is a double variable. I am using 20 Ticks as profit target in this test.

      Code:
      if (Performance.AllTrades.TradesPerformance.Points.CumProfit + Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= Profit * TickSize)
                  {
                      ExitLong("", "");
                      ExitShort("", "");
                   }

      Comment


        #4
        Add a Print() statement before this if statement to ensure the values are as expected

        Print(Performance.AllTrades.TradesPerformance.Poin ts.CumProfit);
        Print(Position.GetProfitLoss(Close[0], PerformanceUnit.Points);
        Print(Profit *TickSize);

        You can watch the output by going to tools -> output window.

        Let me know what you find.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Print

          Ok, my code (with generic strategy) looks like this:

          Code:
          // Check variable and enter trade
                      if (Variable1 == 0)
                  
                      // Beginn of strategy
                      {
                          // Condition set 1
                          if (SMA(Close, P1)[0] > SMA(Close, P1)[1])
                          {
                              EnterLong(DefaultQuantity, "");
                          }
          
                          // Condition set 2
                          if (SMA(Close, P1)[0] < SMA(Close, P1)[1])
                          {
                              EnterShort(DefaultQuantity, "");
                          }
                          
                      // Check performance and exit
                          
                      Print(Performance.AllTrades.TradesPerformance.Points.CumProfit);
                      Print(Position.GetProfitLoss(Close[0], PerformanceUnit.Points));
                      Print(Profit * TickSize);
                      
                      if (Performance.AllTrades.TradesPerformance.Points.CumProfit + Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= Profit * TickSize)
                      {
                          ExitLong("", "");
                          ExitShort("", "");
                          Variable1++;
                      }
                      
                      }
                      // End of strategy
          I am getting sequences like this in the output window while backtesting:
          -1099,99999999946
          0,0071800000000001
          0,001
          -1099,99999999946
          0,00898000000000012
          0,001
          -1099,99999999946
          0,00808
          0,001
          -1099,99999999946
          0,0071800000000001
          0,001
          -1099,99999999946
          0,00627999999999997
          0,001
          -1099,99999999946
          0,00808
          0,001
          -1099,99999999946
          0,00898000000000012
          0,001
          -1099,99999999946
          0,00988000000000002
          0,001
          -1099,99999999946
          0,00808
          0,001
          6960,00000000054
          0,000879999999999901
          0,001

          Comment


            #6
            Hello,

            I've tested this with my own script and attached it. It does appear the profit and exit conditions are exiting properly when using points.

            Look at the print statements I'm using to check the values. I know that anytime the print labeled cum profit and unrealized profit are added together if they are >= 10*TickSize my trade will exit

            My assumption is that your value for Profit might be causing your trades to not exit as expected.
            Attached Files
            LanceNinjaTrader Customer Service

            Comment


              #7
              ok

              It works. Thanks!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by sidlercom80, 10-28-2023, 08:49 AM
              167 responses
              2,260 views
              0 likes
              Last Post jeronymite  
              Started by warreng86, 11-10-2020, 02:04 PM
              7 responses
              1,362 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by Perr0Grande, Today, 08:16 PM
              0 responses
              5 views
              0 likes
              Last Post Perr0Grande  
              Started by elderan, Today, 08:03 PM
              0 responses
              9 views
              0 likes
              Last Post elderan
              by elderan
               
              Started by algospoke, Today, 06:40 PM
              0 responses
              10 views
              0 likes
              Last Post algospoke  
              Working...
              X