Announcement

Collapse
No announcement yet.

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

    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).

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        58 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        133 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X