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

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.
    Kate W.NinjaTrader Customer Service

    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!
          Kate W.NinjaTrader Customer Service

          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
              Kate W.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              11 views
              0 likes
              Last Post XXtrader  
              Started by Waxavi, Today, 02:10 AM
              0 responses
              6 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by TradeForge, Today, 02:09 AM
              0 responses
              11 views
              0 likes
              Last Post TradeForge  
              Started by Waxavi, Today, 02:00 AM
              0 responses
              2 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by elirion, Today, 01:36 AM
              0 responses
              7 views
              0 likes
              Last Post elirion
              by elirion
               
              Working...
              X