Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pricing of Forex – determining programmatically?

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

    #16
    Hello,

    I see this issue too when trying to express calculation results in terms of PIP-values while using the option HalfPip or TenthPip.
    I think NT "owes" us an interface providing this kind of information, something like IsHalfPip and IsTenthPip. There is no reliable programmatic solution providing 100% confidence about what the basic Forex pip-size value is.
    Currently I use the following workaround, to determine the basic pip-size (variable 'tickSize' in this example):
    Code:
    ...
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]private [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] tickSize; [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// Basic tick size of the instrument[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]...[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnS[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]tartUp()[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (TickSize == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.00005[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] || TickSize == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.00001[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] tickSize = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.0001[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (TickSize == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.005[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] || TickSize == [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.001[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New] tickSize = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0.01[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT]
    [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] tickSize = TickSize;[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
    [/SIZE][/FONT]
    Here is the result of a test print explaining what I try to find out:

    TickSize: 1E-05 tickSize: 0,0001
    TickSize: 5E-05 tickSize: 0,0001
    TickSize: 0,0001 tickSize: 0,0001
    TickSize: 0,01 tickSize: 0,01
    TickSize: 0,005 tickSize: 0,01
    TickSize: 0,001 tickSize: 0,01

    Regards
    Ralph

    Comment


      #17
      Ralph, I'll pass that on as a feature request.
      AustinNinjaTrader Customer Service

      Comment


        #18
        Ralph,

        Thanks very much for adding to this thread.

        Looking at your post and code (thank you for posting that I appreciate it) I think you have taken a slightly different approach to solving the problem. If I have interpreted your code correctly (please feel free to correct me if I’ve misunderstood), your approach is to standardise on using Pips for calculations and then submit orders in whatever is required by the broker, thereby segmenting your strategy calculations from the order submission of the broker?

        Just to reiterate this problem occurs for me when moving between historical data that is priced in pips and then to live (or other historical data) that is priced in 1/10th of pips.

        With regards to your point on the functionality being provided by NT, like you, I feel that this functionality isn’t really up to scratch, not nearly robust enough. Unfortunately, it think it reflects the Futures / exchange traded nature of NT beginnings. I don’t think they have the depth of experience in operating in a Forex world. I have now spoken with others users on this point, they have also had to write workarounds.

        I eventually come up with a workaround of just setting NT to price and pips and ignore the 1/10th pip pricing. I suspect it isn’t as a robust a way for the strategy to trade it as you are losing some precision in the pricing. But it is a workaround for now. I did get a reply from MBT support on this – interestingly I had to email their MetaTrader support address. They suggested that I shouldn’t see any issues with operating NT in Pips. I’m at a relatively early point in testing this, so I’m happy to keep updating this thread and working with NT support via this thread and others to see if we can’t, at a minimum, get some agreed workarounds.

        I would also like to hear a little more from Adamus (see post below) with his proposed workaround of using “price”. But I didn’t fully understand his solution. I think he is differentiating between using TickSize as opposed the actual “price” (e.g. Close[0]).

        Thank you again for collaborating on this and sharing your experience.

        Kind regards,

        drolles

        Comment


          #19
          Hello drolles,

          I am personally use prices for calculation, no matter what fraction of a PIP I set in the options tab. Price is presented correctly by NT and the indicators are calculate correctly too. Don't see any problems there.
          Occasionally I use an indicator to print some numbers into the Log-tab and sometimes I prefer to express these numbers in terms of a PIP. That's were it is getting more difficult, as discussed in this thread.

          Regards
          Ralph

          Comment


            #20
            I see that you specify your stop size in pips and work out your position sizing in dollars based on that and your account size. Can you hard-code your stop size in dollars instead against the instrument? Or is it dynamic?

            I had an issue with multiple datasets for history - I have Interactive Brokers historical data, FXCM and Disktrading (DTC). Since I found that the results from the trading systems I favour are quite different for the same time period from provider to provider, I keep them seperate and run tests on all datasets before I'm done.

            I have the simple default symbol for Interactive Brokers, e.g. $AUDJPY - and I created another one for FXCM and DTC respectively in the Instrument Manager - $AUDJPY_FXCM and $AUDJPY_DTC with the appropriate data provider symbol translation in the corresponding cell on the Misc tab / Symbol Map. I just connect this machine to IQFeed for FXCM and to IB for IB once a week to download those symbols and I manually import the DTC data. On my live machine, I only use IB data.

            Check out this thread for more info: http://www.ninjatrader.com/support/f...ad.php?t=32590

            I have found that NT7 loses its correct TickSize setting per instrument when running a strategy using multiple symbols. This is quite a mess when looking at the logging, but fortunately I don't do position sizing in the way you do (yet). I think maybe the MasterInstrument for the strategy stays the same, despite the instrument changing every onBarUpdate call.

            It would be good to get that verified - NinjaTrader Support?
            Last edited by adamus; 01-20-2011, 07:28 AM.

            Comment


              #21
              Originally posted by adamus View Post

              I have found that NT7 loses its correct TickSize setting per instrument when running a strategy using multiple symbols. This is quite a mess when looking at the logging, but fortunately I don't do position sizing in the way you do (yet). I think maybe the MasterInstrument for the strategy stays the same, despite the instrument changing every onBarUpdate call.

              It would be good to get that verified - NinjaTrader Support?
              Thanks for reporting this observation in adamus, we will look into and investigate.

              Comment


                #22
                adamus, which NT 7 version where you exactly working on? I was testing for example the attached script on IB (TWS 911.3) set to halfPip and did not see an issue, ticksizes were reported as set in the instrument manager, not only for the primary series but for the Add()ed ones as well.
                Attached Files

                Comment


                  #23
                  I have the following with your script:


                  EURUSD 0.005
                  EURJPY 0.005
                  EURAUD 5E-05
                  EURCAD 5E-05
                  EURUSD 0.005
                  EURUSD 0.005

                  EURUSD is the only one at fault.

                  However when I use it with my strategy (where I have 20 extra instruments, each with 4 different time series) I get all the wrong displays for JPY based pairs - i.e. two extra zeroes in each case.

                  Im using NT7.0.1000.2 and have it sets to half-pips.

                  Comment


                    #24
                    Hello,

                    Just so that I understand correctly.

                    Berts test works ok, it only doesnt work in your strategy.

                    If this is the case any chance I can have you pull some code out of your strategy and still duplicate and post on the forum so I can get this to development. As our testing here is not seeing the same. There must be something different in your strategy that is causing this.

                    Also, Bertrand is out for the weekend and will return on Monday so I cannot discuss this issue with him on the ticket until then on what you guys have already done.
                    BrettNinjaTrader Product Management

                    Comment


                      #25
                      No, the test strategy provided doesn't work - I think I said the EUR/USD was wrong.

                      Comment


                        #26
                        adamus, do you have any special settings for EURUSD in your instrument manager? I just tested this out with the half-pip setting, and everything looks as expected:
                        Code:
                        EURUSD .00005
                        EURJPY .005
                        EURAUD .00005
                        EURCAD .00005
                        Code:
                        protected override void Initialize()
                        {
                            CalculateOnBarClose = true;
                            Add("$EURJPY", PeriodType.Day, 1, MarketDataType.Last);
                            Add("$EURAUD", PeriodType.Day, 1, MarketDataType.Last);
                            Add("$EURCAD", PeriodType.Day, 1, MarketDataType.Last);
                        }
                        protected override void OnBarUpdate()
                        {
                            if (BarsInProgress == 0)
                                Print("EURUSD " + TickSize.ToString(".#####"));
                            if (BarsInProgress == 1)
                                Print("EURJPY " + TickSize.ToString(".#####"));            
                            if (BarsInProgress == 2)
                                Print("EURAUD " + TickSize.ToString(".#####"));            
                            if (BarsInProgress == 3)
                                Print("EURCAD " + TickSize.ToString(".#####"));            
                        }
                        If the issue persists, please try restarting your computer and see if that fixes it.
                        AustinNinjaTrader Customer Service

                        Comment


                          #27
                          Strangely the error from EUR/USD has vanished. I only see the same as you now. I have turned the computer off and on a couple of times between the posts made above so your advice to reboot was probably correct. Obviously i'm happy that this one is gone, but I'd be happier if it wasn't one of those flakey "requires a reboot" type bugs.

                          Fortunately regarding the ticksize variation I was seeing via display in my logging, I discovered I had a bug in my own script, so I can safely say the issue there is taken care of now. Sorry to waste any time.

                          Comment


                            #28
                            Just coded up a function to hard code the tick size rather than rely on the NT instrument manager in case you are running the strategy on various datasets for the same underlying instrument from different data providers using different tick size granularity.

                            I think this covers all eventualities. The boolean var "emergency" should be a strategy-level var you can code an if-statement against to stop processing if you forget to add your new instrument.

                            I plan to write a replacement for Instrument.MasterInstrument.Round2TickSize() depending on what I end up doing with this current strategy I'm working on.

                            At the moment, I figure that this code:

                            SetStopLoss(CalculationMode.Ticks, stopsTicks);

                            will only do what I expect it to do when NT is giving me the tick size I expect. In other words, I shouldn't use it.

                            Anyway, here's the code:

                            Code:
                                    public double getTickSize()
                                    {
                                        string fullName = Instrument.FullName;
                                        fullName.PadRight(7, ' ');
                                        switch (fullName.Substring(0, 7))
                                        {
                                            case "$AUDCAD":
                                                return 0.00005;
                                            case "$AUDCHF":
                                                return 0.00005;
                                            case "$AUDJPY":
                                                return 0.005;
                                            case "$AUDUSD":
                                                return 0.00005;
                                            case "$CADCHF":
                                                return 0.00005;
                                            case "$CADJPY":
                                                return 0.005;
                                            case "$CHFJPY":
                                                return 0.005;
                                            case "$EURAUD":
                                                return 0.00005;
                                            case "$EURCAD":
                                                return 0.00005;
                                            case "$EURCHF":
                                                return 0.00005;
                                            case "$EURGBP":
                                                return 0.00005;
                                            case "$EURJPY":
                                                return 0.005;
                                            case "$EURUSD":
                                                return 0.00005;
                                            case "$GBPAUD":
                                                return 0.00005;
                                            case "$GBPCAD":
                                                return 0.00005;
                                            case "$GBPCHF":
                                                return 0.00005;
                                            case "$GBPJPY":
                                                return 0.005;
                                            case "$GBPUSD":
                                                return 0.00005;
                                            case "$USDCAD":
                                                return 0.00005;
                                            case "$USDCHF":
                                                return 0.00005;
                                            case "$USDJPY":
                                                return 0.005;
                                            case "CL":
                                                return 1;
                                            default:
                                                Log(base.Name + " - no value set for Tick Size! "
                                                    + Instrument.FullName, NinjaTrader.Cbi.LogLevel.Alert);
                                                emergency = true;
                                                break;
                                        }
                                        return 0;
                                    }
                            Last edited by adamus; 02-01-2011, 01:08 AM. Reason: Realised I'd explained it badly

                            Comment


                              #29
                              Why don' you do it:
                              if (fullName.Substring(4, 3)) == "JPY" return 0.005;
                              else if (fullName.Substring(0, 1)) == "$" return 0.00005;
                              else return 1;

                              Comment


                                #30
                                Originally posted by drolles View Post
                                With regards to your point on the functionality being provided by NT, like you, I feel that this functionality isn’t really up to scratch, not nearly robust enough. Unfortunately, it think it reflects the Futures / exchange traded nature of NT beginnings. I don’t think they have the depth of experience in operating in a Forex world. I have now spoken with others users on this point, they have also had to write workarounds.

                                I eventually come up with a workaround of just setting NT to price and pips and ignore the 1/10th pip pricing. I suspect it isn’t as a robust a way for the strategy to trade it as you are losing some precision in the pricing. But it is a workaround for now.


                                drolles
                                Have you used the full pip setting enough, now, to conclude that it works well for trades in live account with MBT ??

                                Thanks,
                                Jon

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                576 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                334 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                101 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                553 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                551 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X