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

OnEachTick vs. Timebased Entry vs. TrailingStop

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

    OnEachTick vs. Timebased Entry vs. TrailingStop

    Hi
    I have a little issue i am sure one of you codewizards can help with.


    My main strategy methid is the this
    Code:
    protected override void OnBarUpdate()
            {
                if(Time[0].Hour == 15 && Time[0].Minute == 30)//Last 1 min bar before open
                {
                    if(Open[0] < Close[0])//Up Bar
                    {
                        SetupTrade(1);
                    }
                    else if(Open[0] > Close[0])//Down Bar
                    {
                        SetupTrade(0);
                    }
                    else if(Open[0] == Close[0])
                    {
                        if(Open[1] < Close[1])
                            SetupTrade(1);
                        else
                            SetupTrade(0);
                    }
                }
    
            }
    The method it calls is the following

    Code:
            private void SetupTrade(int direction)
            {
    
                if(direction == 1)
                {
                    EnterLongStopMarket(1, High[0] ,"NQUP"+CurrentBar);
    
    
                }
                else
                {
                    EnterShortStopMarket(1, Low[0], "NQDOWN"+CurrentBar);
    
    
                }
                //SetProfitTarget(CalculationMode.Ticks, 20);
                SetTrailStop(CalculationMode.Ticks, TrailingStop);
    
    
    
            }
    My problem is that if i set
    Code:
    Calculate   = Calculate.OnEachTick;
    then the method fires away too soon.but the TrailingStop works on tick basis
    If i set
    Code:
    Calculate   = Calculate.OnBarClose;
    it fires 1 time when expected but now the trailingstop only moves at each barclose which is way to late.

    So is there a way to get the method firing precisly at 15.30 GMT+1 / 9.30 EST and at the same time have the trailingstop react to every tick ?

    Best Regards,
    Sune

    #2
    Hello SuneSorgenfrei,

    Thanks for your post.

    Use Calculate.OnEachTick and for the event to happen only once per bar use IsFirstTickOfBar
    Reference: https://ninjatrader.com/support/help...ttickofbar.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul
      Thanks for the tip but i do not think that will solve the issue as i only need the 1 minute bar from 9.29 - 9.30, but i need the high/low when the bar has finished.
      The only thing i can think of then is to set the Time to a minute later than and ask for the first tick of that bar to get access to the old bar something like

      Code:
      If(IsFirstTickOfBar)
           if(Time[0].Hour == 15 && Time[0].Minute == 31)
              Bars[1].High // that would then by the 9.29 - 9.30 bar right ?

      Comment


        #4
        Hello SuneSorgenfrei,

        Thanks for your reply.

        Sure, you could access the previous bar data using High[1] when the time condition is met along with first tick of the next bar (which is almost the same time as the close of the previous bar).
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Aviram Y, Today, 05:29 AM
        0 responses
        1 view
        0 likes
        Last Post Aviram Y  
        Started by quantismo, 04-17-2024, 05:13 PM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        34 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cls71, Today, 04:45 AM
        0 responses
        6 views
        0 likes
        Last Post cls71
        by cls71
         
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        216 views
        1 like
        Last Post PaulMohn  
        Working...
        X