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

OnPositionUpdate

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

    OnPositionUpdate

    Hello, within an addon when i use...

    accountSelector.SelectedAccount.PositionUpdate += OnPositionUpdate;

    to subscribe to position updates

    for this i will get all open positions relating to this account : in order to filter down to a specific instrument ; within OnPositionUpdate i access the position fields eg

    e.Position.Instrument.FullName

    what would be the best safest way to compare this with a particular instrument i am looking at .. just a string compare on the Fullname of each?

    Also ... i am subscribing to the OnBarUpdate for a BarsRequest - i note in the sample code and framework example of having to loop ......

    /* Depending on the BarsPeriod type of your barsRequest you can have situations where more than one bar is updated by a single tick
    Be sure to process the full range of updated bars to ensure you did not miss a bar. */

    // Option 1. If you want to process updated bars on each tick
    for (int i = e.MinIndex; i <= e.MaxIndex; i++)
    {
    // Processing every single tick
    outputBox.Text = string.Format("REALTIME BARS{0}Time: {1}{0}Open: {2}{0}High: {3}{0}Low: {4}{0}Close: {5}",
    Environment.NewLine,
    e.BarsSeries.GetTime(i),
    e.BarsSeries.GetOpen(i),
    e.BarsSeries.GetHigh(i),
    e.BarsSeries.GetLow(i),
    e.BarsSeries.GetClose(i));
    }


    If i am only wanting bar updates for the current live bar ie there is not lookback for number of bars or days of bars ... i dont need to do the above and simply use

    e.BarsSeries.GetClose(e.MaxIndex)

    ?

    what situation for example would one have where more than one bar is updated by a single tick ? and then needing to process the full range of updated bars to ensure you did not miss a bar? If i am only subscribing with no lookback ; this does not apply?

    thanks

    #2
    Hello soulfx,

    Thank you for your note.

    For filtering positions down to a specific instrument, using a string to compare against Instrument.FullName would be correct.

    e.BarsSeries.GetClose(e.MaxIndex) would give you the most recent close, so yes, you would not need the loop above.

    In regards to your last question, it would not apply. A situation where more than 1 bar could be updated by a single tick could be a volume bar type which forms bars of 10 contracts but the last trade was 100 contracts.

    Please let us know if you need further assistance or if I did not understand your questions correctly.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kujista, Today, 05:44 AM
    0 responses
    5 views
    0 likes
    Last Post kujista
    by kujista
     
    Started by ZenCortexCLICK, Today, 04:58 AM
    0 responses
    7 views
    0 likes
    Last Post ZenCortexCLICK  
    Started by sidlercom80, 10-28-2023, 08:49 AM
    172 responses
    2,281 views
    0 likes
    Last Post sidlercom80  
    Started by Irukandji, Yesterday, 02:53 AM
    2 responses
    18 views
    0 likes
    Last Post Irukandji  
    Started by adeelshahzad, Today, 03:54 AM
    0 responses
    9 views
    0 likes
    Last Post adeelshahzad  
    Working...
    X