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

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.

    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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 helpwanted, Today, 03:06 AM
          1 response
          7 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          7 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
          385 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X