• 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

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 brian meade, Today, 01:39 PM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Started by Johnny Santiago, Today, 12:20 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by NinjaTrader_Brandon, Today, 10:24 AM
                0 responses
                48 views
                0 likes
                Last Post NinjaTrader_Brandon  
                Started by ptertich, Today, 07:56 AM
                2 responses
                15 views
                0 likes
                Last Post Johnny Santiago  
                Started by aslane, Today, 08:24 AM
                1 response
                15 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Working...
                X