Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing a line from averageFillPrice data

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

    Drawing a line from averageFillPrice data

    Hello there,

    I have a strategy that is going long and short, and I’m trying to use OnOrderUpdate() and averageFillPrice to draw two lines that keep track of the long and short entries:
    * One line is formed by the entry price for each long entry,
    * The other line is formed by the entry price for each short entry.

    For example, looking at just the long entries line, here is a hypothetical situation:
    A. The strategy buys NQ at 8,700 at 10:00, at 10:09 it sells NQ at 8,750, then at 10:20 it buys NQ again at 8,720.

    B. Therefore, the long entries line would be:
    From 10:00 to 10:19: 8,700
    From 10:20 onwards: 8,720

    I suspect I need to create a variable which is equal to the averageFillPrice when it goes long and only changes when there is another long fill.

    However: when I tried the following code, it did not work! I only get a line segment.

    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
    {
    if (order.Name == "MyLong")
    {
    if (!pos1)
    {
    posb1 = CurrentBar; //save the start bar for the region
    pos1 = true;
    pos2 = false;
    }

    pos1price = averageFillPrice;
    }

    StrategyPlot5[0] = pos1price;

    Could there be any example code to which you could point me so I might see an example of this?

    I would really appreciate the help. Thank you in advance!

    #2
    Hi catinabag, thanks for your question.

    I would recommend using OnExecutionUpdate instead. This will be called for each execution that happens so you can keep better track of what executions are buy orders and which are sell orders.



    For the logic that actually draws the lines, I am not aware of any existing example. A community member here on the forum would need to help out with that portion of the script.

    Kind regards.

    Comment


      #3
      You can probably use something from my post here:


      Comment


        #4
        Thanks for the replies!

        Comment


          #5
          This is a conversion of the NT7 misc ProfitTargetTrailingStop_101b Stop Strategy Framework Please contact the original author for any questions or comments. NT8‐ Added optional plot lines for Profit target and Stop. 7-8-2020 Changed the Calculate.OnBarClose to Calculate.OnPriceChange and relocated entry logic for best practice

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X