I have an Indicator with an OnBarUpdate() being called on an Indicator.Calculate = Calculate.OnPriceChange.
I wish to store indicator identified price levels as keys in a Dictionary so that when price returns to those levels I can run logic and move an drawing objects anchor value to an adjacent tradeable price value each time price hits it.
However Close[0] returns a double type value which may or may not be an actual tradeable price value. The value can be anywhere up to 17 decimal places.
All price values it seems are stored as doubles, which I have found very often can't be rounded to actual prices without conversion to decimal number types.
My first thought is to try and control actual price levels by convert the Close[0] double to a decimal and Math.Round it to 5 decimal places (Forex pips/pippetts prices).
But a rounding error of only 0.00001 or 1 pipette is potentially enough to make it possible for an OnPriceChange to fail to match and step straight past a value save in the Dictionary key.
Then at this point this indicator only works for forex, i would have to run logic for every different instrument to determine how many decimal places to round to... at this point its seems like its getting way too convoluted just to work with real world price values and I feel like I am totally missing something obvious that is already built in to Ninja Trader.
I would rather not have to iterate every key in the dictionary every price change to see if a dictionary key has been crossed. I have seen FormatPrice() but that returns a string value with a backtick in it so it can't be simply cast back to a double and applied as a chartAnchor value.(But I will use it if that really is the only option)
I essentially wish to use OnPriceChange's latest price to identify if it is crossing a ChartAnchor's price and if so have a ChartAnchor update with it and save a dictionary key value for the price level next to it to be used to test when price steps past the current ChartAnchor's price.
What I (mistakenly?) think I need is what value should be stored as a dictionary key to a reliably triggered by price passing it, that avoids having to have 12 decimal places worth of dictionary keys to insure a 0.00001 move isn't stepped over?
I am sure however I must be missing something staring me straight in the face. Sorry
Comment