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

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.
    Chris L.NinjaTrader Customer Service

    Comment


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


      Comment


        #4
        Thanks for the replies!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Started by ScottWalsh, Today, 06:52 PM
        4 responses
        36 views
        0 likes
        Last Post ScottWalsh  
        Started by olisav57, Today, 07:39 PM
        0 responses
        7 views
        0 likes
        Last Post olisav57  
        Started by trilliantrader, Today, 03:01 PM
        2 responses
        21 views
        0 likes
        Last Post helpwanted  
        Started by cre8able, Today, 07:24 PM
        0 responses
        10 views
        0 likes
        Last Post cre8able  
        Working...
        X