Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

on each tick variable time since triggered method

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

    on each tick variable time since triggered method

    I have a variable that I use for entering order on each tick. It tends to give a mixed profit result as sometimes it will give a false trigger as the market conditions are changing. It will trigger and then not fully develop and go back in original state, but the order is sent.

    I could put this order in on first tick of bar, but then the order tends to be late entry and less profitable or unprofitable. Any ideas how to get some middle ground on this trade? Is there a way to count ticks since the variable change and subtract from my required amount of ticks.

    I use DateTime.Now.ToString ("hh:mm:ss.fff") to print my order times and troubleshoot I could possibly use this and subtract the minimum time before submitting the order, but maybe there is an easier way.​

    #2
    Hello metical1,

    If you are using OnEachTick you could count a number of ticks by using an int variable. The variable needs to be reset when you submit the entry. You would then use OnBarUpdate to increment the variable for each OnBarUpdate event to count a tick.

    Comment


      #3
      I think I understand. What code could I use to count say 10 ticks since my bool = true?

      Comment


        #4
        Hello metical1,

        an int variable can be defined like the following:

        private myIntVarriable = 0;

        To increment a varriable you can use ++ or:

        myIntVariable++;


        Code:
        private myIntVarriable = 0;
        protected override void OnBarUpdate()
        {
            if(Position.MarketPosition != MarketPosition.Flat)
            {
                myIntVariable++;
            }
        
            if(EntryCondition)
            {
                //entry logic
                myIntVariable = 0;
            }
        
            if(myIntVariable >= 10)
            {
                 //10 ticks elapsed since entry submitted
                myIntVariable = 0; // reset
            }
        }
        Last edited by NinjaTrader_Jesse; 12-12-2022, 01:33 PM.

        Comment


          #5
          Thanks Jesse. I have this working now it is a good solution and also give me some more ideas .

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          557 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X