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

Change Limit Price

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

    Change Limit Price

    Hello!
    Have a question. How can I change the price of Limit order (EnterLongLimit f.e.). I want the order to always be on the Bid price untill it will not be filled or cancelled by my conditions. Do I need to cancel existing order and submit another? All this code will be set in the OnMarketData. So it's critical to change order price with each new Ask/Bid update. How can I do this. Thanks.

    #2
    Hello YevhenShynkarenko,

    Thanks for your post.

    If you call an order entry method when the order is already active, the order will be changed to that price level. I would recommend using the IsLiveUntilCancelled overloads to keep the order alive until you deliberately cancel the order with CancelOrder. An example that describes how to use CancelOrder is included below. This example also uses order method overloads that use IsLiveUntilCancelled.

    SampleCancelOrder - https://ninjatrader.com/support/help...thod_to_ca.htm

    See Managed Approach documentation for all order entry methods and their overload syntax - https://ninjatrader.com/support/help...d_approach.htm

    Taking this approach, you could call your order method again and use the price reported from OnMarketData when a MarketDataType.Bid event occurs. Also to consider, you could use GetCurrentBid which will fetch the most recent Bid price. (This would be the most recent Bid price seen by NinjaTrader before the price gets processed through OnMarketData.) Open source indicators can give further example for using OnMarketData, like the open source Volume Profile indicator.

    GetCurrentBid - https://ninjatrader.com/support/help...currentbid.htm

    OnMarketData - https://ninjatrader.com/support/help...marketdata.htm

    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      So, I can just setup:
      EnterLongLimit(bipIndex, true, ordQuantity, GetCurrentBid(0), "Enter Limit");

      And if GetCurrentBid price will update - it will setup my limit order on the new Bid price? And this code I'm using in OnMarketData method.Am I right?

      Comment


        #4
        Hello YevhenShynkarenko,

        If you use the order method as you describe and you have a limit order active with the signal name "Enter Limit" then your limit order will be updated to the price level retrieved from GetCurrentBid. This can be called from OnMarketData.

        Please let me know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello,
          I currently using the conditions below on a script to generate entries.

          if (longButtonClicked
          && Close[1] >= MAX(High, 2)[2] + 0 * TickSize
          && High[1] < CurrentDayOHL().CurrentHigh[1])
          EnterLongLimit((Close[1]));
          SetProfitTarget(CalculationMode.Ticks, 12);
          SetStopLoss(CalculationMode.Ticks, 8);

          if (shortButtonClicked
          && Low[1] > CurrentDayOHL().CurrentLow[1]
          && Close[1] < MIN(Low, 2)[2] - 0 * TickSize)
          EnterShortLimit((Close[1]));
          SetProfitTarget(CalculationMode.Ticks, 12);
          SetStopLoss(CalculationMode.Ticks, 8);

          if (!longButtonClicked
          && Position.MarketPosition == MarketPosition.Long)
          ExitLong();

          if (!shortButtonClicked
          && Position.MarketPosition == MarketPosition.Short)
          ExitShort();
          }


          On close observation, I noticed that if the entry is not filled when the condition is first met, as price moves away, I get filled at higher price (if long) or at much lower price (if short) than intended. In essence, the script keeps making the order chase price. I don't want that.
          Please is there a way or command that I can use to keep the limit order at the price level where the condition was first met. For example, on a long if the limit order is triggered at 3456, and price moves to 3459, I still want my limit order prices bid to still remain at 3456, rather than chasing prices to get filled.

          Comment


            #6
            Welcome to the forums BBAbility,

            EnterLongLimit will move the order to a new price if it is called again.

            If you are calling this method in OnBarUpdate, which gets called whenever we get a bar closure (or change in price/tick for Calculate.OnEachTick or Calculate.OnPriceChange)

            If you are using buttons to control these order submissions, I might suggest submitting the order's in the button's Click event instead of in OnBarUpdate.

            Please note that you will need to use TriggerCustomEvent from the button click event since you are making a barsAgo reference for the order price: Close[1]

            TriggerCustomEvent - https://ninjatrader.com/support/help...ustomevent.htm

            You will also need to consider using IsLiveUntilCancelled order method overloads with IsLiveUntilCancelled set to true so you can keep orders alive.

            The example below demonstrates using the IsLiveUntilCancelled overloads so the order does not get cancelled automatically if a method is not called.


            JimNinjaTrader Customer Service

            Comment


              #7
              Hello Jim,

              Thank you for your help.
              I tried to follow the example but not still can't get it to work. See below.
              Please note that I am not a programmer, just trying to follow the example.
              Thanks for your help with this.

              }
              }
              protected override void OnBarUpdate()
              {
              if (longButtonClicked
              && Close[1] >= MAX(High, 2)[2] + 0 * TickSize
              && High[1] < CurrentDayOHL().CurrentHigh[1])
              TriggerCustomEvent(
              EnterLongLimit((Close[1])));
              SetProfitTarget(CalculationMode.Ticks, 12);
              SetStopLoss(CalculationMode.Ticks, 8);

              if (shortButtonClicked
              && Low[1] > CurrentDayOHL().CurrentLow[1]
              && Close[1] < MIN(Low, 2)[2] - 0 * TickSize)
              TriggerCustomEvent(
              EnterShortLimit((Close[1])));
              SetProfitTarget(CalculationMode.Ticks, 12);
              SetStopLoss(CalculationMode.Ticks, 8);

              if (!longButtonClicked
              && Position.MarketPosition == MarketPosition.Long)
              ExitLong();

              if (!shortButtonClicked
              && Position.MarketPosition == MarketPosition.Short)
              ExitShort();
              }

              private void OnButtonClick(object sender, RoutedEventArgs rea)
              {

              Comment


                #8
                Hello BBAbility,

                A basic understanding of C# will be needed to write the correct syntax.

                Some publicly available resources on C# like the ones below can be helpful.

                Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.


                W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.


                As for using TriggerCustomEvent, I suggest using the syntax:

                Code:
                TriggerCustomEvent(o =>
                {
                    Print("This line of code is run inside TriggerCustomEvent.");
                
                    // other code to run inside TriggerCustomEvent goes here.
                }, null);
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                3 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                18 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                1 view
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                6 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                10 views
                0 likes
                Last Post bltdavid  
                Working...
                X