Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

first tick of the bar or last tick of the bar

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

    first tick of the bar or last tick of the bar

    hello
    i have a strategy that i would like to run on every tick (or price change) but I am having a problem. so currently the way i have it is as follow:

    when condition A is met
    place a limit order 1 tick above that bar and since it is on bar close it is placing the limit order 1 tick above the signal bar when that bar closes.

    how can I do that if I change the strategy on every tick? because when I change it to on every tick, when conditions are met it is placing a limit order 1 tick above the high at that second of the bar and not waiting for the bar to finish. I want it to wait for the bar to finish but on every tick method will help me with my exit better.

    any help is appreciated.

    PS: I tried to use on first tick of bar to add it to the condition but that did not help.

    #2
    in other words i want the entry on bar close and exit on tick.

    Comment


      #3
      Hello babouin77,

      Thank you for the post.

      To mix OnBarClose and OnEachTick you can use the IsFirstTickOfBar property. https://ninjatrader.com/support/help...FirstTickOfBar

      A way to do what you described would be to use that property and also make a private bool variable. When your condition A is met set the bool variable to true. As condition B you can check if the IsFirstTickOfBar is true and also if your bool is true. As part of the action set the bool back to false.

      That would allow the action to be spaced until the next bar to simulate OnBarClose logic. Because you are on the next bar you may need to use 1 BarsAgo for prices or other values in case you wanted the Closed bar price.

      I look forward to being of further assistance.

      Comment


        #4
        thanks a lot
        so if currently i have this

        if (DM1.DiPlus[0] > DM1.DiMinus[0])

        EnterLongStopMarket(0, true, Convert.ToInt32(ContractSize), LongEntry, "Long");

        with the is first tick it should be

        if (DM1.DiPlus[1] > DM1.DiMinus[1]) && (IsFirstTickOfBar)

        EnterLongStopMarket(0, true, Convert.ToInt32(ContractSize), LongEntry, "Long");


        would that be the correct logic?

        Comment


          #5
          Hello babouin77,

          That would be correct if you only wanted to check the condition on OnBarUpdate, you would still need a bool variable and another condition if you wanted to have part of it checked intrabar and the other part OnBarUpdate.


          Code:
          private bool myBool;
          protected override void OnBarUpdate()
          {
          
             if(myBool == true && IsFirstTickOfBar)
             {
                 EnterLongStopMarket(0, true, Convert.ToInt32(ContractSize), LongEntry, "Long");
                 myBool = false;
             }
          
              if (DM1.DiPlus[0] > DM1.DiMinus[0])
                  myBool = true;
          
          
          }
          I look forward to being of further assistance.

          Comment


            #6
            oh i see. thanks a lot

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            52 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            130 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            70 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            43 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            48 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X