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.


    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.


    For orders to be placed intra-bar in historical, intra-bar granularity and TickReplay is needed.



    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)[INDENT]{
      if(CurrentBar != lastBar)[/INDENT][INDENT=2]{[/INDENT][INDENT=2]lastBar = CurrentBar;[/INDENT][INDENT=2]flag = false;[/INDENT][INDENT=2]}[/INDENT][INDENT]}[/INDENT]
       
      
      if(BarsInProgress == 1)
      {[INDENT]// Something like this, Bars.PercentComplete returns a double so just set your threshold[/INDENT][INDENT]if( flag == false && Bars.PercentComplete > .95 )
      {[/INDENT][INDENT]BuildSignals();[/INDENT][INDENT]OrderPlacement();[/INDENT][INDENT]flag = true;[/INDENT][INDENT]}[/INDENT]
       
      
      //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))[INDENT]{[/INDENT][INDENT]BuildSignals();[/INDENT][INDENT]OrderPlacement();[/INDENT][INDENT]flag = true;[/INDENT][INDENT]}[/INDENT]
       
       }
      Last edited by cutzpr; 10-01-2019, 09: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.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          938 views
          0 likes
          Last Post spwizard  
          Started by Max238, Today, 01:28 AM
          0 responses
          3 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by rocketman7, Today, 01:00 AM
          0 responses
          2 views
          0 likes
          Last Post rocketman7  
          Started by wzgy0920, 04-20-2024, 06:09 PM
          2 responses
          27 views
          0 likes
          Last Post wzgy0920  
          Started by wzgy0920, 02-22-2024, 01:11 AM
          5 responses
          32 views
          0 likes
          Last Post wzgy0920  
          Working...
          X