• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.
        https://ninjatrader.com/support/foru...ead.php?t=6652

        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.
          https://ninjatrader.com/support/foru...ead.php?t=6652

          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 gngmpwdws, Today, 09:58 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post gngmpwdws  
                  Started by darkgreen, Today, 03:35 PM
                  1 response
                  14 views
                  0 likes
                  Last Post lmatiukas  
                  Started by imalil, Today, 09:46 PM
                  1 response
                  7 views
                  0 likes
                  Last Post Epistemophilic  
                  Started by SAITON, Today, 09:03 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post SAITON
                  by SAITON
                   
                  Started by suprsnipes, Today, 08:26 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post suprsnipes  
                  Working...
                  X