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

tick size for Initialize()

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

  • giogio1
    replied
    Hello,
    I've actually found a possible way to access TickSize from Initialize()

    #region Variables
    protected double tickSizeForum = 0;
    #endregion Variables

    protected override void Initialize()
    {
    this.tickSizeForum = base.Instrument.MasterInstrument.TickSize;
    }

    and then, being that this is not supported, we check that this actually works

    protected override void OnStartUp()
    {
    if (this.tickSizeForum != base.Instrument.MasterInstrument.TickSize) throw new InvalidOperationException("tickSize taken from Initialize() has changed in OnStartUp()");
    }

    Regards,
    giogio

    Leave a comment:


  • outsource
    replied
    Originally posted by koganam View Post
    yeah,sure...thanks for the good morning laugh!

    Leave a comment:


  • koganam
    replied
    Originally posted by outsource View Post
    So is it applicable for the both sides - Long and Short?The expression you provided creates the tick range,correct? What "if the expression returns true" means?I`m not that good with the C# brogue yet.
    Search engines are very useful, but only if we use them.

    ref: https://msdn.microsoft.com/en-us/library/ms173144.aspx

    Leave a comment:


  • outsource
    replied
    Originally posted by koganam View Post
    If the expression returns true, that means that the "Close/current price" is within a maximum of one tick outside of the SMA of the Highs and Lows. Period.
    So is it applicable for the both sides - Long and Short?The expression you provided creates the tick range,correct? What "if the expression returns true" means?I`m not that good with the C# brogue yet.

    Leave a comment:


  • koganam
    replied
    Originally posted by outsource View Post
    So this way it could be inside the channel or TickSize outside the channel,whatever appears,for both - either long or short,correct?
    If the expression returns true, that means that the "Close/current price" is within a maximum of one tick outside of the SMA of the Highs and Lows. Period.

    Leave a comment:


  • outsource
    replied
    Originally posted by koganam View Post
    Even though that is logical it is sort of mathematically redundant. If you want to test for a value between 2 other values just test for that.
    Code:
    if (Close[0] <= SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0]  - TickSize){/* ... */}
    That takes care of both the edge and inner conditions.
    So this way it could be inside the channel or TickSize outside the channel,whatever appears,for both - either long or short,correct?

    Leave a comment:


  • koganam
    replied
    Originally posted by outsource View Post
    Because i need this logic instead:

    if (Close[0] <= SMA(High, 10)[0] || Close[0] <=SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] || Close >=SMA(Low, 8)[0] - TickSize)

    Would this equation work in real life?
    Even though that is logical, it is sort of mathematically redundant. If you want to test for a value between 2 other values just test for that.
    Code:
    if (Close[0] <= SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0]  - TickSize){/* ... */}
    That takes care of both the edge and inner conditions.
    Last edited by koganam; 11-19-2015, 06:32 PM.

    Leave a comment:


  • outsource
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello outsource,

    No, these would not be the same.

    if (Close[0] <= SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] - TickSize)

    if the close is equal to or less than the sma high plus one tick and is also equal to or greater than the sma low minus one tick trigger


    if (Close[0] <= SMA(High, 10)[0] || Close[0] <=SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] || Close >=SMA(Low, 8)[0] - TickSize)

    if the close is less than or equal to the sma high then trigger
    if the close is less than or equal to the high plus one tick and the close is greater than the sma low then trigger
    if the close is greater than or equal to the sma low minus one tick then trigger


    That said, can you respond to my question from post #25?

    I am not understanding how the example logic i provided is not what you are asking for. Can you clarify this?
    Because i need this logic instead:

    if (Close[0] <= SMA(High, 10)[0] || Close[0] <=SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] || Close >=SMA(Low, 8)[0] - TickSize)

    Would this equation work in real life?

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello outsource,

    No, these would not be the same.

    if (Close[0] <= SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] - TickSize)

    if the close is equal to or less than the sma high plus one tick and is also equal to or greater than the sma low minus one tick trigger


    if (Close[0] <= SMA(High, 10)[0] || Close[0] <=SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] || Close >=SMA(Low, 8)[0] - TickSize)

    if the close is less than or equal to the sma high then trigger
    if the close is less than or equal to the high plus one tick and the close is greater than the sma low then trigger
    if the close is greater than or equal to the sma low minus one tick then trigger


    That said, can you respond to my question from post #25?

    I am not understanding how the example logic i provided is not what you are asking for. Can you clarify this?
    Last edited by NinjaTrader_ChelseaB; 11-19-2015, 11:42 AM.

    Leave a comment:


  • outsource
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello outsource,

    Without being able to see what you have written I wouldn't be able to comment.

    However, when you say "It`s not exactly what i asked.I need the price to be inside the channel OR slightly(ticksize) above the High(10) for buy signal and vice versa for sell.", this is a bit confusing.

    Inside the channel or slightly above.

    This is telling me that if you add 1 tick to the upper channel price and then the close is at this price or below that this is what you are looking for.
    This is exactly what I have written from how i understand it.

    My comment is:
    // close is 1 tick outside of the channel or within

    Can you explain how this is incorrect?

    Would it be different or would it be the same?

    if (Close[0] <= SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] - TickSize)

    if (Close[0] <= SMA(High, 10)[0] || Close[0] <=SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] || Close >=SMA(Low, 8)[0] - TickSize)
    Last edited by outsource; 11-18-2015, 07:46 PM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello outsource,

    Without being able to see what you have written I wouldn't be able to comment.

    However, when you say "It`s not exactly what i asked.I need the price to be inside the channel OR slightly(ticksize) above the High(10) for buy signal and vice versa for sell.", this is a bit confusing.

    Inside the channel or slightly above.

    This is telling me that if you add 1 tick to the upper channel price and then the close is at this price or below that this is what you are looking for.
    This is exactly what I have written from how i understand it.

    My comment is:
    // close is 1 tick outside of the channel or within

    Can you explain how this is incorrect?

    Leave a comment:


  • outsource
    replied
    Originally posted by NinjaTrader_ChelseaB View Post
    Hello Outsource,

    As an example here is how that logic is created with TickSize. This is following the pattern set by koganam.

    Code:
    if (Close[0] <= SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] - TickSize)
    {
    	// close is 1 tick outside of the channel or within
    	// close is less than or equal to sma using high as input with a period of 10
    	// and close is greater than or equal to the sam using the low as input with period of 8
    }
    
    if (Close[0] > SMA(High, 10)[0] + TickSize || Close < SMA(Low, 8)[0] - TickSize)
    {
    	// close is more than 1 tick outside the channel
    	// close is greater than sma using high as input with period of 10
    	// OR close is less than sma using low as input with period of 8
    }
    If you wanted to increase the number of ticks, you can multiply the ticksize to add ticks.

    For example:
    int buffer = 2;
    Print(SMA(High, 10)[0] + buffer * TickSize);

    This would print the value of the sma using the high with a period of 10 plus 2 ticks.

    if buffer was equal to -3 this would subtract 3 ticks.
    Hi Chelsea,

    thank you for the example.It`s not exactly what i asked.I need the price to be inside the channel OR slightly(ticksize) above the High(10) for buy signal and vice versa for sell.

    So that

    if (Close[0] <= SMA(High, 10)[0] && Close >= SMA(Low, 8)[0] ) +/- TickSize

    Is there a way to accomplish something like this.When i try to imply the "||" statement it doesnt work properly.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Outsource,

    As an example here is how that logic is created with TickSize. This is following the pattern set by koganam.

    Code:
    if (Close[0] <= SMA(High, 10)[0] + TickSize && Close >= SMA(Low, 8)[0] - TickSize)
    {
    	// close is 1 tick outside of the channel or within
    	// close is less than or equal to sma using high as input with a period of 10
    	// and close is greater than or equal to the sam using the low as input with period of 8
    }
    
    if (Close[0] > SMA(High, 10)[0] + TickSize || Close < SMA(Low, 8)[0] - TickSize)
    {
    	// close is more than 1 tick outside the channel
    	// close is greater than sma using high as input with period of 10
    	// OR close is less than sma using low as input with period of 8
    }
    If you wanted to increase the number of ticks, you can multiply the ticksize to add ticks.

    For example:
    int buffer = 2;
    Print(SMA(High, 10)[0] + buffer * TickSize);

    This would print the value of the sma using the high with a period of 10 plus 2 ticks.

    if buffer was equal to -3 this would subtract 3 ticks.
    Last edited by NinjaTrader_ChelseaB; 11-17-2015, 03:25 PM.

    Leave a comment:


  • outsource
    replied
    Originally posted by NinjaTrader_MichaelM View Post
    Hello outsource,

    As koganam stated, if you could provide additional information as to exactly what you are trying to achieve with this particular code, we will be able to provide further guidance. A snippet of your actual code around where you are inserting this may be beneficial to include as well.

    Thank you in advance!
    Hi,Michael,

    For illustration,you can take Snake eye method as an exampe with its two SMAs one is 8 period for the Low input,and another is 10 period for the High input.Thus create a channel.So now the price should be inside the channel or slightly above(but no more then) 10 SMA of the High or below(but no more then) 8 SMA of the Low

    Leave a comment:


  • outsource
    replied
    Originally posted by koganam View Post
    Hard to say.. You asked a very specific question, and I gave you the specific expression that you would use. Generally, you have to write statements in a program, so the expression itself standing alone would not do much.

    What are you trying to do in this small instance, and I may be able to give you a complete statement, that might be more useful?
    I created sort of a channel off the two averages(one of the Low another of the High) ,and want the body of a candle to be inside the channel when other conditions are triggered,OR to be slightly(ticksize) above the Upper average for buying condition or to be inside or slightly(ticksize) below the Lower average for selling conditions.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by wzgy0920, 02-22-2024, 01:11 AM
5 responses
32 views
0 likes
Last Post wzgy0920  
Started by wzgy0920, Yesterday, 09:53 PM
2 responses
49 views
0 likes
Last Post wzgy0920  
Started by Kensonprib, 04-28-2021, 10:11 AM
5 responses
191 views
0 likes
Last Post Hasadafa  
Started by GussJ, 03-04-2020, 03:11 PM
11 responses
3,230 views
0 likes
Last Post xiinteractive  
Started by andrewtrades, Today, 04:57 PM
1 response
14 views
0 likes
Last Post NinjaTrader_Manfred  
Working...
X