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

  • NinjaTrader_MichaelM
    replied
    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!

    Leave a comment:


  • koganam
    replied
    Originally posted by outsource View Post
    Thanks koganam,

    i tried this very equation,but it seems after that it ignored the other confditions i have.

    Should i bracket this equation?
    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?
    Last edited by koganam; 11-16-2015, 12:17 PM. Reason: Corrected punctuation.

    Leave a comment:


  • outsource
    replied
    Originally posted by olres7 View Post
    Try this one
    SetStopLoss("Long Entry 1", CalculationMode.Ticks, Instrument.MasterInstrument.Round2TickSize(MyDoubl e*TickSize), false);
    SetProfitTarget("Long Entry 1", CalculationMode.Ticks, (2.0*A_big/TickSize));
    Hi,thank you,

    but it`s not about setting stops and profits.It`s about adding some degree of freedom to conditions to take place.

    Leave a comment:


  • outsource
    replied
    Originally posted by koganam View Post
    By separating them.
    Code:
    Value[0][0] < Value[0][1] - TickSize  || Value[0][0] > Value[0][1] + TickSize
    Thanks koganam,

    i tried this very equation,but it seems after that it ignored the other confditions i have.

    Should i bracket this equation?

    Leave a comment:


  • olres7
    replied
    Try this one
    SetStopLoss("Long Entry 1", CalculationMode.Ticks, Instrument.MasterInstrument.Round2TickSize(MyDoubl e*TickSize), false);
    SetProfitTarget("Long Entry 1", CalculationMode.Ticks, (2.0*A_big/TickSize));

    Leave a comment:


  • koganam
    replied
    Originally posted by outsource View Post
    A bit off top...

    But,how to achieve -/+ ticksize within the same condition?

    So for Value[0][0] > Value[0][1] +/- ticksize

    So,it would be true n ticks above OR n ticks below

    Thanks to All
    By separating them.
    Code:
    Value[0][0] < Value[0][1] - TickSize  || Value[0][0] > Value[0][1] + TickSize

    Leave a comment:


  • sledge
    replied
    Originally posted by outsource View Post
    A bit off top...

    But,how to achieve -/+ ticksize within the same condition?

    So for Value[0][0] > Value[0][1] +/- ticksize

    So,it would be true n ticks above OR n ticks below

    Thanks to All
    Don't do it in initialize??

    Leave a comment:


  • outsource
    replied
    A bit off top...

    But,how to achieve -/+ ticksize within the same condition?

    So for Value[0][0] > Value[0][1] +/- ticksize

    So,it would be true n ticks above OR n ticks below

    Thanks to All

    Leave a comment:


  • NinjaTrader_AdamP
    replied
    alexstox,

    Unfortunately TickSize is not accessible in the Initialize() method.



    Please keep in mind you can also specify a stop loss in the OnBarUpdate() method, where TickSize would be accessible, and it will apply this stop loss to your orders.



    Please let me know if I may assist further.

    Leave a comment:


  • alexstox
    replied
    The problem is I can't get TickSize in Initialize(), but there are conditions that use it.
    For example:
    protected override void Initialize()
    {
    SetProfitTarget("Long Entry 1", CalculationMode.Ticks, 2*A_big/TS);

    When I do like you wrote - Backtest work bad, incorrect. When I just use 0.0001 instead of TS - everything is OK. So, what can you advise? How can I use TickSize in Profit and Stop targets? I need it to be divide by TickSize to get {2*0.0112/0.0001=224} ticks for targets.

    Leave a comment:


  • NinjaTrader_AdamP
    replied
    alexstox,

    This is the issue : private double TS = TickSize;

    Here :

    Code:
    public class LWMP : Strategy
    {
    #region Variables
    private double TS = TickSize; 
    #endregion
    
    //other code and methods
    
    }
    The TickSize variable is only accessible in the OnBarUpdate() method, though some people seem to get it to work in OnStartup() which is unsupported currently.

    Basically, you need to declare your variable :

    Code:
    public class LWMP : Strategy
    {
    #region Variables
    private double TS; 
    #endregion
    
    // other code and methods
    
    }
    Then assign it in another method like :

    Code:
    private override void OnBarUpdate()
    {
    
    TS = TickSize;
    
    //other code
    
    }
    Please let me know if I may assist further.
    Last edited by NinjaTrader_AdamP; 04-18-2012, 08:13 AM.

    Leave a comment:


  • alexstox
    replied
    public class LWMP : Strategy
    {
    #region Variables
    private double TS = TickSize;
    #endregion

    error: An object reference is required for the non-static field, method, or property `NinjaTrader.Strategy.StrategyBase.TickSize.Get`


    P.S. The problem is I can't get TickSize in Initialize(), but there are conditions that use it.
    For example:
    protected override void Initialize()
    {
    SetProfitTarget("Long Entry 1", CalculationMode.Ticks, 2*A_big/TS);
    Last edited by alexstox; 04-18-2012, 08:11 AM.

    Leave a comment:


  • NinjaTrader_AdamP
    replied
    alexstox,

    Where are you using the variable ts? I suspect you would need to declare :

    private double ts;

    in the "variables" section to make it accessible by the other methods.

    A variable declared within a method like OnStartup() or OnBarUpdate() will only be accessible in OnStartup() or OnBarUpdate() respectively the way you are declaring it.

    Please let me know if I may assist further.

    Leave a comment:


  • alexstox
    replied
    before "protected override void Initialize()" I inserted
    "protected override void OnStartUp()
    {
    double ts = TickSize;
    }
    But error "The name `ts` does not exist in the current context"
    Where should I declair `ts`? In "#region Properties"? as private double or just as double?

    Leave a comment:


  • Radical
    replied
    Try 'double ts = TickSize;' in OnStartUp()

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by alifarahani, Today, 09:40 AM
0 responses
1 view
0 likes
Last Post alifarahani  
Started by Gerik, Today, 09:40 AM
0 responses
1 view
0 likes
Last Post Gerik
by Gerik
 
Started by RookieTrader, Today, 09:37 AM
0 responses
5 views
0 likes
Last Post RookieTrader  
Started by KennyK, 05-29-2017, 02:02 AM
3 responses
1,282 views
0 likes
Last Post NinjaTrader_Clayton  
Started by AttiM, 02-14-2024, 05:20 PM
11 responses
184 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X