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

Limit order with SetProfitTarget

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

    Limit order with SetProfitTarget

    I use the following code:

    EnterShortLimit(DefaultQuantity, entry_priceShort, "");

    SetProfitTarget(CalculationMode.Ticks, a);

    When price hits the entry_priceShort, it's short in the market. I use 60min bars.

    If the bar that triggers the short also has prices of the profittarget (in the bar), the strategy automatic calculates this as a profitable trade. However, if you look at a shorter timeframe you see that price first hits the profittarget and then the entry_short. So actually there is no profit, the trade is still on...

    How can I avoid this? How can I set for example profit target one bar later?

    #2
    Hello no111,

    Thank you for your post.

    For historical backtesting you would need to use an Exit() method instead of the Set() method. Then either wait a set number of bars after entry (BarsSinceEntry: http://www.ninjatrader.com/support/h...sinceentry.htm) or submit the order to another time frame: http://www.ninjatrader.com/support/f...ead.php?t=6652

    Please let me know if I may be of further assistance.

    Comment


      #3
      Ok thanks.

      Would this be a correct solution?
      Barindex 0 = 1min
      Barindex 1 = 120min

      PHP Code:

         
      protected override void OnBarUpdate()
              {

      if (
      BarsInProgress == 1){
      entry_price EMA(BarsArray[1],20)[1];    


        if ( 
      Closes[1][0] > Closes[1][1
                      )
                  { 
                      
      x=1;
                      Print(
      "Long setup");     
                  }
        if ( 
      Closes[1][0] < Closes[1][1
                      )
                  { 
                      
      x=0;
                      Print(
      "No setup");     
                  }

      }
      }

      if (
      BarsInProgress == 0){
              if ( 
      x==&& Position.Quantity == 0  
                      
      ) {
                                      
                  
      LongEntryOrder EnterLongLimit(0,true1Instrument.MasterInstrument.Round2TickSize(entry_price), "LongEntry");
                  
                          
                              
                  }

      }

            protected 
      override void OnExecution(IExecution execution)
              {
                  
              
              
                  if (
      LongEntryOrder != null && LongEntryOrder == execution.Order && BarsInProgress == 0)
                  {
                      if (  
      execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled 0))
                      {
                          
      LongstopOrder     ExitLongStop(0trueexecution.Order.Filledexecution.Order.AvgFillPrice 4"MyStop""LongEntry");
                          
                          
      LongtargetOrder ExitLongLimit(0trueexecution.Order.Filledexecution.Order.AvgFillPrice 4"MyTarget""LongEntry");
                          
      x=0;

                          if (
      execution.Order.OrderState != OrderState.PartFilled)
                          {
                              
      LongEntryOrder     null;
                          }
                      }
                  }

              if ((
      LongstopOrder != null && LongstopOrder == execution.Order) || (LongtargetOrder != null && LongtargetOrder == execution.Order))
                  {
                      if (
      execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
                      {
                          
      LongstopOrder null;
                          
      LongtargetOrder null;
                      }
                  }


      Comment


        #4
        Hello no111,

        Thank you for your response.

        That would be correct for entering on the secondary series and exiting on the primary series.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Segwin, 05-07-2018, 02:15 PM
        14 responses
        1,788 views
        0 likes
        Last Post aligator  
        Started by Jimmyk, 01-26-2018, 05:19 AM
        6 responses
        837 views
        0 likes
        Last Post emuns
        by emuns
         
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        6 responses
        3,292 views
        1 like
        Last Post jgualdronc  
        Started by Touch-Ups, Today, 10:36 AM
        0 responses
        12 views
        0 likes
        Last Post Touch-Ups  
        Started by geddyisodin, 04-25-2024, 05:20 AM
        11 responses
        62 views
        0 likes
        Last Post halgo_boulder  
        Working...
        X