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

A very simple question for programmers

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

  • pstrusi
    replied
    Thanks a lot for your help. best regards

    Leave a comment:


  • koganam
    replied
    Originally posted by pstrusi View Post
    Koganan in my backtesting I'd need to compare 2 values like differences between average, therefore I have two questions in order to find the best solution:

    1. The best way could be using for example:
    if (Instrument.MasterInstrument.Compare(Price1, Price2) == 1)

    2. Or can I format double values to a fix format, for example: round to 0.000000 format but not necessarily divisible exactly by ticksize ?

    Thanks for all inputs my friends
    To start off with, anything that attempts to calculate an output to a greater accuracy than its inputs is mathematically meaningless. Hence my use of Round2TickSize().

    That mathematical puritanism aside, yes you can round to any value you want. There is the C# Math.Round() function. ref: http://msdn.microsoft.com/en-us/library/75ks3aby.aspx
    Last edited by koganam; 06-03-2012, 05:24 PM.

    Leave a comment:


  • pstrusi
    replied
    Originally posted by koganam View Post
    Code:
     
    double ComparisonValue = Close[0]-(Close[0]+Open[0])/2;
    if (Instrument.MasterInstrument.Round2TickSize(ComparisonValue) == 0.000175)
    {
    //MakeMegaBucks();
    }
    That, of course assumes that your tickSize accuracy matches the value that you are comparing. I do not know any instrument that has a tickSize that goes to 6 digits. Therefore, given that you are using Close and Open, which are both exactly sized to tickSize, there is only one very limited exact condition under which your equation will be satisfied.

    It seems to me that you may be better off multiplying both sides by a suitable factor, such as 1000, so that you are comparing values of like accuracy, or else mathematically rounding to 6 decimal places, which will allow a match if, and only if, the instrument has a tickSize to 5 decimal places, and the range of the candle is exactly 0.00035.

    Edit: As a matter of fact, writing
    Code:
     
    if ((Close[0] - Open[0]) == 0.00035) ...
    might be the better condition to write, as on an instrument with a 5 decimal place tickSize, that equation is already exactly matched to ticSize, and so avoids all rounding errors.
    How could I round to 6 decimal places?

    Leave a comment:


  • sledge
    replied
    Originally posted by koganam View Post
    Code:
     
    double ComparisonValue = Close[0]-(Close[0]+Open[0])/2;
    if (Instrument.MasterInstrument.Round2TickSize(ComparisonValue) == 0.000175)
    {
    //MakeMegaBucks();
    }
    This isn't the first time Koganam has left out the MakeMegaBucks function.

    One day there will be a slip up.

    Leave a comment:


  • pstrusi
    replied
    Koganan in my backtesting I'd need to compare 2 values like differences between average, therefore I have two questions in order to find the best solution:

    1. The best way could be using for example:
    if (Instrument.MasterInstrument.Compare(Price1, Price2) == 1)

    2. Or can I format double values to a fix format, for example: round to 0.000000 format but not necessarily divisible exactly by ticksize ?

    Thanks for all inputs my friends

    Leave a comment:


  • koganam
    replied
    Originally posted by pstrusi View Post
    I meant those format values ( 6 digits after 0 ), I didn't understand how the round off will work out with it

    Thanks Koganan, I'll try it that way; this is embarrassing cause it should be pretty easy to solve
    Code:
     
    double ComparisonValue = Close[0]-(Close[0]+Open[0])/2;
    if (Instrument.MasterInstrument.Round2TickSize(ComparisonValue) == 0.000175)
    {
    //MakeMegaBucks();
    }
    That, of course assumes that your tickSize accuracy matches the value that you are comparing. I do not know any instrument that has a tickSize that goes to 6 digits. Therefore, given that you are using Close and Open, which are both exactly sized to tickSize, there is only one very limited exact condition under which your equation will be satisfied.

    It seems to me that you may be better off multiplying both sides by a suitable factor, such as 1000, so that you are comparing values of like accuracy, or else mathematically rounding to 6 decimal places, which will allow a match if, and only if, the instrument has a tickSize to 5 decimal places, and the range of the candle is exactly 0.00035.

    Edit: As a matter of fact, writing
    Code:
     
    if ((Close[0] - Open[0]) == 0.00035) ...
    might be the better condition to write, as on an instrument with a 5 decimal place tickSize, that equation is already exactly matched to ticSize, and so avoids all rounding errors.
    Last edited by koganam; 06-03-2012, 05:17 PM.

    Leave a comment:


  • pstrusi
    replied
    I meant those format values ( 6 digits after 0 ), I didn't understand how the round off will work out with it

    Thanks Koganan, I'll try it that way; this is embarrassing cause it should be pretty easy to solve

    Leave a comment:


  • koganam
    replied
    Originally posted by pstrusi View Post
    Thanks Koganan but I'd need to work with those values, so what others ways are there?
    I do not understand what you just wrote. Use any values you want; just round off before/when you do the comparison. Comparison of doubles requires exactitude. IOW, leave the values intact; just round off the result of your calculation at the time that you do the comparison. Your values remain. So what is the problem again?

    Leave a comment:


  • pstrusi
    replied
    Thanks Koganan but I'd need to work with those values, so what others ways are there?

    Leave a comment:


  • sledge
    replied
    Turn on output window from tools menu item.

    Then use a print statement before your if condition.

    Print("result="+(Close[0]-(Close[0]+Open[0])/2));

    You will see if you ever get -0.000175.
    Last edited by sledge; 06-03-2012, 04:34 PM. Reason: removed * typo

    Leave a comment:


  • koganam
    replied
    Originally posted by pstrusi View Post
    I apologize for my programming ignorance but I'm stuck in something that it shouldn't happen

    I'm testing a very simple condition:

    if ( (Close[0]-(Close[0]+Open[0])/2) < -0.000175)
    {
    EnterShort(100000, "SELL");

    }

    I work with Range bars, onBarUpdate=true....ect etc

    The problem comes whenever I set "==" instead of ", or >" , there's not any result, when I've previously checked that actually there are a lot of results with that condition...so when I use < or > no problem, but if I use == I got NONE results....

    how is this possible?
    How could I fix it?

    Thanks in advance
    Try rounding your calculation off; either mathematically, or to tickSize. ref: http://www.ninjatrader.com/support/h...trument_ro.htm

    Leave a comment:


  • pstrusi
    started a topic A very simple question for programmers

    A very simple question for programmers

    I apologize for my programming ignorance but I'm stuck in something that it shouldn't happen

    I'm testing a very simple condition:

    if ( (Close[0]-(Close[0]+Open[0])/2) < -0.000175)
    {
    EnterShort(100000, "SELL");

    }

    I work with Range bars, onBarUpdate=true....ect etc

    The problem comes whenever I set "==" instead of ", or >" , there's not any result, when I've previously checked that actually there are a lot of results with that condition...so when I use < or > no problem, but if I use == I got NONE results....

    how is this possible?
    How could I fix it?

    Thanks in advance

Latest Posts

Collapse

Topics Statistics Last Post
Started by DayTradingDEMON, Today, 09:28 AM
4 responses
21 views
0 likes
Last Post DayTradingDEMON  
Started by geddyisodin, Yesterday, 05:20 AM
9 responses
50 views
0 likes
Last Post NinjaTrader_Gaby  
Started by George21, Today, 10:07 AM
1 response
11 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Started by Stanfillirenfro, Today, 07:23 AM
9 responses
24 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by navyguy06, Today, 09:28 AM
1 response
9 views
0 likes
Last Post NinjaTrader_Gaby  
Working...
X