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 helpwanted, Today, 03:06 AM
        1 response
        10 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        8 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        386 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X