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

Enter and Exit a strategy on a timely manner

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

    Enter and Exit a strategy on a timely manner

    Hi There,

    I have a strategy that it's based on UniRenko (default) + 15-min bar chart (as secondary series). How do I include the following conditions in my strategy?

    1- Wait till the first 5-min passes. If my conditions are not met, don't take any positions till the next new 15-min bar comes in
    2- If a position is taken, then don't take another one till the next new 15-min bar comes in

    Thank you..



    #2
    Hello Abdullah_KSA,

    In this situation you could use DateTimes to do this or you could add another series of 5 minutes to delegate the logic based on 5 minutes.

    One way to go about this would be to use OnEachTick processing, on the first tick of the 15 minute bar you can store the Time[0]. After that for each new tick you can subtract the stored time from now and that will give a TimeSpan difference where you could check if it has been more than 5 minutes to further control the logic.

    Another way to do this would be to add a 5 minute series. You could reset a variable when the 15 minute bar closes and then in the 5 minute series after 1 bar set the variable if it was not set. You could use the 5 minute series to toggle the variable after the close of each 15 minute bar.

    Are you currently using the builder or manually coding this? The builder would only allow for adding of a 5 minute series however you could not utilize that series for setting the variable so this would need to be manually coded.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello Abdullah_KSA,

      In this situation you could use DateTimes to do this or you could add another series of 5 minutes to delegate the logic based on 5 minutes.

      One way to go about this would be to use OnEachTick processing, on the first tick of the 15 minute bar you can store the Time[0]. After that for each new tick you can subtract the stored time from now and that will give a TimeSpan difference where you could check if it has been more than 5 minutes to further control the logic.

      Another way to do this would be to add a 5 minute series. You could reset a variable when the 15 minute bar closes and then in the 5 minute series after 1 bar set the variable if it was not set. You could use the 5 minute series to toggle the variable after the close of each 15 minute bar.

      Are you currently using the builder or manually coding this? The builder would only allow for adding of a 5 minute series however you could not utilize that series for setting the variable so this would need to be manually coded.

      I look forward to being of further assistance.
      Thank you.. I'm coding this manually (not using Strategy Builder). Would you kindly write a quick script for that? My coding knowledge is limited. I don't know which command to use. Happy to share my current code if needed

      Comment


        #4
        Hello Abdullah_KSA,

        Thank you for the reply.

        I would be happy to walk through either of the items I had described. To get started here is a quick sample of using a secondary series. This is with Calculate OnBarClose.


        Code:
        else if (State == State.Configure)
        {
                 AddDataSeries(BarsPeriodType.Minute, 15);
                 AddDataSeries(BarsPeriodType.Minute, 5);
        }
        
        
        
        
        private bool canTrade;
        
        protected override void OnBarUpdate()
        {
            if(BarsInProgress == 0) return; //ignore the primary for the purpose of this sample
            Print(BarsInProgress + " " + Time[0] + " " + canTrade);
            if(BarsInProgress == 1)
            {
                canTrade = true; // 15 minute bar close, reset the can trade     
            }
            if(BarsInProgress == 2)
            {
                if(canTrade == true)
                {
                    //the first 5 minutes has elapsed, set the variable to false
                    // here is where you can do logic also if you wanted to execute it on the first 5 minute bar of the 15 minute span
                    canTrade = false; 
                }
            }
        }
        That would produce a sequence like the following. On the 15 minute series, the lines starting with 1 the variable gets reset to true. On the first 5 minute bar close the following line starting with 2 we can see the variable was true. Each 5 minute bar after that for the 15 minutes is false.


        1 7/7/2020 12:00:00 PM False
        2 7/7/2020 12:00:00 PM True
        2 7/7/2020 12:05:00 PM False
        2 7/7/2020 12:10:00 PM False
        1 7/7/2020 12:15:00 PM False
        2 7/7/2020 12:15:00 PM True
        2 7/7/2020 12:20:00 PM False
        2 7/7/2020 12:25:00 PM False


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks a lot Jesse. I appreciate the thoughtful input here. I will certainly give it a shot
          However, given my limited background in coding, is there a 3rd party that you may recommend here, where I can use a quick hand on this? (with a full legal disclaimer from your side, and no liabilities of course). I would appreciate sharing few contacts (if any)

          Comment


            #6
            Hello Abdullah_KSA,

            Thanks for the reply.

            I would not be able to recommend a third party personally but I will have our sales team provide some information on finding third parties in a follow up post so that you can research them.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello Abdullah_KSA,

              This is Chris following up on behalf of Jesse.

              You can search our list of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more:You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third-party services for NinjaTrader, all pricing and support information will need to be obtained through the consultant.

              The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem, LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

              Let me know if I may be of further assistance.

              Comment


                #8
                Thank you Chris.. this is what I'm looking for exactly

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ghoul, Today, 06:02 PM
                3 responses
                14 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                44 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                20 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                180 views
                0 likes
                Last Post jeronymite  
                Started by DanielSanMartin, Yesterday, 02:37 PM
                2 responses
                13 views
                0 likes
                Last Post DanielSanMartin  
                Working...
                X