Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change the value in SetProfitTarget?

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

    Change the value in SetProfitTarget?

    It seems to me that the SetProfitTarget(Signal, Calc Mode, Value); can only be put in Initialize(), and I'm not sure what is needed to be done to change the "Value" after the strategy starts. Please help! Thanks!

    #2
    Hello,
    You should be able to call SetProfitTarget in OnBarUpdate and even change the value of SetProfitTarget in OnBarUpdate.

    What error do you receive when entering SetProfitTarget in OnBarUpdate?

    Another note on this is if you are using it in OnBarUpdate you will need to make sure it is not in Initialize. SetProfitTarget can not be in Initialize or another method but never in Initialize() and another method.
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      When I used it in OnBarUpdate(), the strategy didn't run. I thought it couldn't be run in there, so I didn't think the problem might be on my end. I'll check my code then.

      I'm trying to use the Swing() to get the highs and lows and use those values to get a profit taker target in ticks. And I was converting the difference of high and low to int. So it must be from there.

      I'm using Convert.ToInt32(high-low). Is there something better to use?

      Comment


        #4
        Hello,
        There may be depending on what you are doing.
        For me to assist further please provide a snippet of the code for this process.
        I look forward to your reply.
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          This is for ES, so .25 per tick

          Code:
          double High = Swing(5).SwingHigh[0];
          double Low  = Swing(5).SwingLow[0];
          ProfitTgt = Convert.ToInt32((High - Low) * 4);
          
          SetProfitTarget("Long", CalculationMode.Ticks, ProfitTgt);
          With this, the code wouldn't run. If I disable these code, it runs.

          Comment


            #6
            Hello,

            I have provided how you would do this in my example below.
            Please let me know if you have any questions.

            Code:
            protected override void OnBarUpdate()
            {
                EnterLong("Long");
            
                 if(Position.MarketPosition != MarketPosition.Flat)
                 {
                     double High = Swing(5).SwingHigh[0];
            	 double Low  = Swing(5).SwingLow[0];
            	 ProfitTgt = Position.AvgPrice + (High - Low);
                
                     SetProfitTarget("Long", CalculationMode.Price, ProfitTgt);
                 }
            }
            Cody B.NinjaTrader Customer Service

            Comment


              #7
              This doesn't work. The price mode will always give me a value of 1863.25 plus whatever the difference is. But in tick mode, it works just fine.

              Comment


                #8
                Hello,
                To debug this please enter in the following Print statement.
                Code:
                Print("Average Entry Price is" + Position.AvgPrice );
                You can then view the printed statement when running the strategy by going to Tools> Output Window.

                Does the average price printout to always be 1863.25 or do you see other prices?
                Cody B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by arvidvanstaey, Today, 02:19 PM
                4 responses
                11 views
                0 likes
                Last Post arvidvanstaey  
                Started by samish18, 04-17-2024, 08:57 AM
                16 responses
                60 views
                0 likes
                Last Post samish18  
                Started by jordanq2, Today, 03:10 PM
                2 responses
                9 views
                0 likes
                Last Post jordanq2  
                Started by traderqz, Today, 12:06 AM
                10 responses
                18 views
                0 likes
                Last Post traderqz  
                Started by algospoke, 04-17-2024, 06:40 PM
                5 responses
                47 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X