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

Optimization

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

    Optimization

    Hi

    Anyone in the nt community have any optimization functions that take under consideration unrealized gains? I’m basically looking to optimize the highest net pnl while having the lowest intra trade unrealized pnl

    Thanks in advance

    #2
    Hello staycool3_a,

    Thank you for your note.

    I’m unaware of any optimizations based on unrealized profits.

    I would expect most cases you’d see max unrealized PL exceed net realized PL.

    You may be interested in searching the net for risk adjusted profit metrics/formulas for what you’re looking to do.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_AlanP View Post
      Hello staycool3_a,

      Thank you for your note.

      I’m unaware of any optimizations based on unrealized profits.

      I would expect most cases you’d see max unrealized PL exceed net realized PL.

      You may be interested in searching the net for risk adjusted profit metrics/formulas for what you’re looking to do.

      Please let us know if you need further assistance.
      Alan,

      Is there anyway you can provide a super basic example for a optimization script? I can’t seem to figure out how to access strategy information within optimization functions. For example, it would be great if you can show me how to check if the previous trade is a winner or a loser. In the strategy script it’s as easy as

      SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];

      And/or

      GetUnrealized PnL

      I have no idea how to implement something like this in Optmization functions. I looked around the forums and couldn’t find anything. Is there anything in the helpguide that I’m not seeing?

      Comment


        #4
        Hello staycool3_a,

        I put together a strategy, SampleSmaCrossExposeVarToOptimizationFitness which has a public variable public double runningOTE=0;.

        I put together an OptimizationFitness called alanTrackUnrealizedPlFromStrategy. The output of this is the runningOTE variable from the strategy.

        When you run an optimization you can select, Optimize based on, alanTrackUnrealizedPlFromStrategy. When you run an optimization, the output in performance will be the runningOTE variable (marked with blue arrow).

        Now you need to set up the strategy so that you track unrealized PL. You’ll have to modify the strategy by adding a secondary tick series.
        You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


        You will also need to trace the max point from the time the trade was entered to exited, for example, you buy CL at 60.00, sell it at 61.00, but it traded up to 61.25, the var runningOTE would equal 1.25. This would be done in the strategy.

        Please let us know if you need further assistance.
        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_AlanP View Post
          Hello staycool3_a,

          I put together a strategy, SampleSmaCrossExposeVarToOptimizationFitness which has a public variable public double runningOTE=0;.

          I put together an OptimizationFitness called alanTrackUnrealizedPlFromStrategy. The output of this is the runningOTE variable from the strategy.

          When you run an optimization you can select, Optimize based on, alanTrackUnrealizedPlFromStrategy. When you run an optimization, the output in performance will be the runningOTE variable (marked with blue arrow).

          Now you need to set up the strategy so that you track unrealized PL. You’ll have to modify the strategy by adding a secondary tick series.
          You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


          You will also need to trace the max point from the time the trade was entered to exited, for example, you buy CL at 60.00, sell it at 61.00, but it traded up to 61.25, the var runningOTE would equal 1.25. This would be done in the strategy.

          Please let us know if you need further assistance.
          Thank you, Alan.
          This will opened a whole different side of NT that was not opened for me. Thanks!

          Comment


            #6
            Alan,

            I have two variables that I get by "counting"

            if (position.MarketPosition == MarketPosition.Flat)
            {
            ++strategy_trade_counts;
            Trade a = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
            if(a.ProfitCurrency>=0)
            ++winning_count;

            if(a.ProfitCurrency<0)
            ++losing_count;
            }

            Anytime I try to divide these variables together, I get a zero. It shouldn't be zero. However, I can use these variables and divide other variables with them and I get the correct values. I can also print these to the output window and it gives me the correct values. But anytime I try to divide them with one another.... it gives me zero. Is this not allowed ?
            Last edited by staycool3_a; 09-18-2018, 04:20 PM.

            Comment


              #7
              Originally posted by staycool3_a View Post
              Alan,

              I have two variables that I get by "counting"

              if (position.MarketPosition == MarketPosition.Flat)
              {
              ++strategy_trade_counts;
              Trade a = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
              if(a.ProfitCurrency>=0)
              ++winning_count;

              if(a.ProfitCurrency<0)
              ++losing_count;
              }

              Anytime I try to divide these variables together, I get a zero. It shouldn't be zero. However, I can use these variables and divide other variables with them and I get the correct values. I can also print these to the output window and it gives me the correct values. But anytime I try to divide them with one another.... it gives me zero. Is this not allowed ?
              These were INT variables. I changed them to double. And it seems to fix my problem.

              Comment


                #8
                Hello staycool3_a,

                Great. When you finish the script if you cared to share it on the forum I'm sure other users would appreciate your contribution.

                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_AlanP View Post
                  Hello staycool3_a,

                  Great. When you finish the script if you cared to share it on the forum I'm sure other users would appreciate your contribution.

                  Please let us know if you need further assistance.
                  Alan, I'd be happy to share it. I'll do that this weekend after making adding comments and stuff. Thanks for your help!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Christopher_R, Today, 12:29 AM
                  0 responses
                  9 views
                  0 likes
                  Last Post Christopher_R  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  166 responses
                  2,235 views
                  0 likes
                  Last Post sidlercom80  
                  Started by thread, Yesterday, 11:58 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post thread
                  by thread
                   
                  Started by jclose, Yesterday, 09:37 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post jclose
                  by jclose
                   
                  Started by WeyldFalcon, 08-07-2020, 06:13 AM
                  10 responses
                  1,415 views
                  0 likes
                  Last Post Traderontheroad  
                  Working...
                  X