• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 sidviciousX, Yesterday, 07:24 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_EricB  
    Started by cls71, Today, 04:31 AM
    0 responses
    2 views
    0 likes
    Last Post cls71
    by cls71
     
    Started by KSTrader, Today, 12:45 AM
    0 responses
    3 views
    0 likes
    Last Post KSTrader  
    Started by Lklforex, Yesterday, 08:48 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_ChrisSch  
    Started by jeronymite, Yesterday, 09:41 PM
    0 responses
    8 views
    0 likes
    Last Post jeronymite  
    Working...
    X