Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Profit in bar update

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

    Profit in bar update

    Hi I trying to set

    SetProfitTarget(CalculationMode.Ticks,Position.Avg Price-low[1])

    In barupdate but It seems to not work properly, I keep getting an error that my order is above market and that the order is rejected.

    Any idea?

    #2
    Hello calhawk01,

    Thank you for your post.

    Is this a Profit Target for short positions or long positions? If this is for long positions you are submitting the order below the market and this will be rejected as limit orders (profit targets) on the sell side (when in a long position) must be above the market and must be below the market on the buy side (when in a short position).

    Please let me know if you have any questions.

    Comment


      #3
      if (Position.MarketPosition == MarketPosition.Long)
      {
      // Once the price is greater than entry price+50 ticks, set stop loss to breakeven
      if (Close[1] > 0)
      {
      SetProfitTarget(CalculationMode.Ticks,Position.Avg Price-stoplong);
      }
      }

      if (Position.MarketPosition == MarketPosition.Short)
      {
      // Once the price is greater than entry price+50 ticks, set stop loss to breakeven
      if (Close[1] > 0)
      {
      SetProfitTarget(CalculationMode.Ticks,stopshort-Position.AvgPrice);
      }
      }

      Comment


        #4
        the orders are calculated correctly for shorts and long, but they r still rejected

        Comment


          #5
          Hello calhawk01,

          Thank you for your response.

          Does this code still return an error on your end? If so can you provide the full strategy file so I may investigate this matter further?

          If you prefer you can send the strategy to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 864598' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=58469

          I look forward to your response.

          Comment


            #6
            Originally posted by calhawk01 View Post
            the orders are calculated correctly for shorts and long, but they r still rejected
            What instrument?

            Comment


              #7
              Emini

              Would you guys expect the above statements to work properly in barupdate?

              I can't send the strategy as I'm at work right now..

              Comment


                #8
                Code:
                           /// <summary>
                        /// This method is used to configure the strategy and is called once before any strategy method is called.
                        /// </summary>
                        protected override void Initialize()
                        {
                            RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
                            TraceOrders = true;
                            CalculateOnBarClose = true;
                        }
                 
                        private double stopshort;
                        private double stoplong;
                                
                        /// <summary>
                        /// </summary>
                        protected override void OnBarUpdate()
                        {
                            
                            
                          
                            stoplong= Low[1];
                            stopshort= High[1];
                            
                            if (..............)
                            {
                                EnterLong();
                                SetStopLoss(CalculationMode.Price,stoplong);
                
                            }
                            else if (...............)
                            {
                                EnterShort();
                                SetStopLoss(CalculationMode.Price,stopshort);
                
                            }
                            
                                        if (Position.MarketPosition == MarketPosition.Long)
                            {
                                
                            if (Close[1] > 0)
                                {
                                SetProfitTarget(CalculationMode.Ticks,Position.AvgPrice-stoplong);
                                }
                            }
                
                            if (Position.MarketPosition == MarketPosition.Short)
                            {
                
                            if (Close[1] > 0)
                                {
                                SetProfitTarget(CalculationMode.Ticks,stopshort-Position.AvgPrice);
                                }
                            }

                Comment


                  #9
                  Hello calhawk01,

                  Thank you for your response.

                  The following line of code will fail as the Limit order on the sell side cannot be below the current market price:
                  Code:
                  if (Position.MarketPosition == MarketPosition.Long)
                              {
                                  
                              if (Close[1] > 0)
                                  {
                                  SetProfitTarget(CalculationMode.Ticks,Position.AvgPrice-stoplong);
                                  }
                              }
                  I would assume that you intend to add the StopLong distance to the AvgPrice instead of subtracting that value from it.

                  Please let me know if you have any questions.

                  Comment


                    #10
                    Originally posted by NinjaTrader_PatrickH View Post
                    Hello calhawk01,

                    Thank you for your response.

                    The following line of code will fail as the Limit order on the sell side cannot be below the current market price:
                    Code:
                    if (Position.MarketPosition == MarketPosition.Long)
                                {
                                    
                                if (Close[1] > 0)
                                    {
                                    SetProfitTarget(CalculationMode.Ticks,Position.AvgPrice-stoplong);
                                    }
                                }
                    I would assume that you intend to add the StopLong distance to the AvgPrice instead of subtracting that value from it.

                    Please let me know if you have any questions.
                    if average price= 1000
                    and stoplong= 990

                    1000-990= 10 ticks? is the profit target


                    what am i missing here?

                    i guess i could:
                    SetProfitTarget(CalculationMode.Ticks,(Position.Av gPrice-stoplong)/.25);

                    to get the exact ticks for emini but that still gives same error, why?

                    Comment


                      #11
                      Hello calhawk01,

                      Thank you for your response.

                      You need to divide the value returned by the TickSize:
                      Code:
                      SetProfitTarget(CalculationMode.Ticks, (Position.AvgPrice-stoplong) / TickSize);
                      Please let me know if you have any questions.

                      Comment


                        #12
                        hi how can i access position.avgprice in stoploss??

                        basically i enter with a limit order of close[0]
                        i want my stoploss to be set at: SetStopLoss("", CalculationMode.Ticks, ((Position.AvgPrice-stoplong)/.25), false); //stoplong is low[1]
                        and i want my profit to be ticks.... profit works. but it seems anytime i try to use avg position in my profit or stoploss.. it does not work properly..

                        the above statement for stoploss gives me extremely high values (upper 3k).. even though 1600-1599=1/.25=4!

                        Comment


                          #13
                          Hello calhawk01,

                          Thank you for your response.

                          Please send your strategy or a toy version of your strategy that includes the entries, StopLoss and ProfitTarget to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 864598' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=58469

                          I look forward to assisting you further.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          650 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          370 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          109 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          574 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          577 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X