• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Catch close of a candle

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

    Catch close of a candle

    Hello, how to enter trades precisionly by close of a candle?

    #2
    Hello U0000999,

    If this is to be automatic, this would need to written into a NinjaScript Strategy.

    Below is a link to a forum thread with helpful information about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040

    Trades appear at the open of a bar because they are submitted after a bar has closed. This means the order, submitted just after a bar is closed and the logic of OnBarUpdate is checked, is submitted just as a new bar is opening.

    Using Calculate as .OnBarClose this is true in historical data as well as real-time.
    Setting Calculate to .OnEachTick, or .OnPriceChange would allow orders to be placed intra-bar in real-time, however this would be when the condition is true and not specifically to when the bar is just about to close. This means conditions are checked during each tick or price change while that bar is still building before it closes.
    https://ninjatrader.com/support/help.../calculate.htm

    For orders to be placed intra-bar in historical, intra-bar granularity and TickReplay is needed.
    https://ninjatrader.com/support/foru...377#post773377


    To have market orders specifically filling at the close of the bar (), you would need intelligent custom written logic to predict when the bar is closed and submit the order a few seconds before the close of the bar. This may be fairly simple when using a time based bar like Minute bars. But this could prove extremely difficult for movement based bars that are not based on time or ticks like range and renko.

    The Strategy Builder is limited and capable of simple left and right comparisons. The script would need to be unlocked and this advanced logic would need to be coded by hand.

    This thread will remain open for any community members that would like to assist with custom logic.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I prefer to set my strategies to Calculate to .OnEachTick but use code like the one below to control the logic of signal creation and order placement only to once when a new bar is created (close of current bar). This way I can separate my protective stops and take profit orders and they can trigger exactly when they reach the threshold and not on the next bar. This also saves you the hassle of having to add a secondary data series just to get that intrabar granularity.



      Code:
      int last bar = 0;
      
      if(CurrentBar != lastBar)
          {
          lastBar = CurrentBar;
          BuildSignals();
          OrderPlacement();  
          }

      If you would like your code to execute right before the close of the bar, you can predict the close using "Bars.PercentComplete" or using a time threshold. Like I stated before, you need intrabar granulairy, so you either use OnEachTick or add an additional 1 tick dataseries and calculate it during BarsInProgress == 1. You will need some sort of flag so that you do not put in multiple orders on that same bar (primary data series). I have not tested this code, just wrote it quickly to give you an idea.

      Code:
      int lastbar = 0;
      int flag = false;
      
      if(BarsInProgress == 0)
      { if(CurrentBar != lastBar)
      {
      lastBar = CurrentBar;
      flag = false;
      }
      }
      if(BarsInProgress == 1) {
      // Something like this, Bars.PercentComplete returns a double so just set your threshold
      if( flag == false && Bars.PercentComplete > .95 ) {
      BuildSignals();
      OrderPlacement();
      flag = true;
      }
      //or something like this int minutes = 4; int seconds = 50; //Assuming you are using a 5 minute bar, it will execute 10 seconds before the close of that bar. if(flag == false && DateTime.Now > Bars.GetTime(CurrentBar).AddMinutes(minutes).AddSeconds(seconds))
      {
      BuildSignals();
      OrderPlacement();
      flag = true;
      }
      }
      Last edited by cutzpr; 10-01-2019, 08:54 PM.

      Comment


        #4
        I would be happy your assistants to help me add code, which executes my strategy precisionly on close of a candle.

        Thanks

        Comment


          #5
          Hello U0000999,

          This is Chris following up on behalf of Chelsea.

          You can search our extensive library 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.
          Christopher D.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by avrege, Today, 01:48 AM
          2 responses
          8 views
          0 likes
          Last Post avrege
          by avrege
           
          Started by markbb10, Today, 07:14 AM
          0 responses
          6 views
          0 likes
          Last Post markbb10  
          Started by leodrz, Today, 05:09 AM
          0 responses
          9 views
          0 likes
          Last Post leodrz
          by leodrz
           
          Started by yourlactures, Today, 02:23 AM
          0 responses
          2 views
          0 likes
          Last Post yourlactures  
          Started by bortz, 02-18-2020, 05:51 AM
          9 responses
          44 views
          0 likes
          Last Post -=Edge=-  
          Working...
          X