Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

draw something above/below working entry limit order

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

    draw something above/below working entry limit order

    Hello,

    how can I programmatically say: when there is a limit entry order (working buy or sell limit order) draw something x tics above/below that price?

    Just one notice: I´m trying to create an indicator, not strategy!

    Thank you,
    emuns

    #2
    Hello emuns,

    Thank you for your post.

    To clarify, would these be manually placed limit orders, ones placed by a NinjaScript Strategy, or both?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Hello Kate,

      these would be manually placed limit orders.

      Comment


        #4
        I think the only way is to query the current account's Executions (working orders) and try to draw using that price data.
        This could be a bit difficult.

        Here are some code snippets and links to help.

        Code:
        lock (Account.All) {
          account = Account.All.FirstOrDefault(a => a.Name == DailySumLossAccount);
        }
        Code:
        foreach (Execution execution in account.Executions) {
            if (execution.Instrument == this.Instrument) {
            // do something here to get the price of the limit order
            }
        }
        Code:
        foreach (Execution execution in account.Executions) {
          if (execution.Instrument == this.Instrument) {
            if (execution.Time.DayOfWeek == DateTime.Now.DayOfWeek) {
              // Long trades
              if (execution.IsEntry && execution.MarketPosition == MarketPosition.Long) {
                avgEntryPriceLong += execution.Price * execution.Quantity;
                sumQuantityLong += execution.Quantity;
              }
              if (execution.IsExit && execution.MarketPosition == MarketPosition.Short) {
                avgExitPriceLong += execution.Price * execution.Quantity;
              }
              // Short trades
              if (execution.IsEntry && execution.MarketPosition == MarketPosition.Short) {
                avgEntryPriceShort += execution.Price * execution.Quantity;
                sumQuantityShort += execution.Quantity;
              }
              if (execution.IsExit && execution.MarketPosition == MarketPosition.Long) {
                avgExitPriceShort += execution.Price * execution.Quantity;
              }
              sumCommission += execution.Commission;
            }
          }
        }
        Drawing is simple. Start with Draw.HorizontalLine, work your way through Draw.Text after.

        Comment


          #5
          Hello emuns,

          Thank you for your post.

          Gorkhaan is on the right track.

          I'm attaching a sample script for a simple indicator that monitors the account and draws text to the chart when a manually placed limit order is made. You can use this script as a jumping off point for your own logic.

          Please let us know if we may be of further assistance to you.
          Attached Files
          Last edited by NinjaTrader_Kate; 08-29-2019, 12:37 PM. Reason: Hit reply before uploading script, sorry!

          Comment


            #6
            Hello
            Gorkhaan and Kate,

            thank you very much for your help.

            I have used Kate´s example to elaborate it further (see attachment). It works as expected, with one limitation. The indicator draws line when I place limit order. When the order is cancelled or filled, than the drawing line dissappears. So, so far everything works as expected. But when I place another limit order, than there is no line. I need to reload the chart to work it again as expected.

            Could you be so kind please to advise me how to change the script to work it without reloading a chart.
            Attached Files

            Comment


              #7
              Hello Emuns,

              Thank you for your note.

              I notice that while you're setting isBuyLimitOrder and IsSellLimitOrder to true within OnOrderUpdate, you aren't setting them back to false, and you also weren't removing the lines quite in the proper place.

              I've made some adjustments that should work better for you. Note that this will only work with a single active limit order at a time.

              Please let us know if we may be of further assistance to you.
              Attached Files

              Comment

              Latest Posts

              Collapse

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