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

Bar Since entry issue

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

    Bar Since entry issue

    I've been trying to implement something in my strategy, using the BarSinceEntry in strategy builder I want my trade to be closed at the end of the candle (or the open of the next one) If the Target profit or the stop loss haven't been reached. Here's a photo of my setting as of right now, its not working at all, no difference from before and after I added this section !
    really appreciate the help for that, seem like an easy fix as I guess its just an execution issue

    Set 1 and 2 are my entries (long and short) parameters, set 3 and 4 are my section for the BarSinceExecution

    Thanks !
    Attached Files

    #2
    Hello RebelRoby,

    Thanks for your post.

    When using BarsSinceEntryExecution in a NinjaScript, you need to create a condition group that uses two BarsSinceEntryExecution conditions.

    To create a group condition, you would select 'group' under the Conditions section of the Strategy Builder.

    Name the group condition and set the drop-down box to 'If Any'. This would be equivalent to checking if condition 1 happens OR if condition 2 happens.

    Next, you would create your conditions for the group condition. The first condition would check if the BarsSinceEntryExecution is > 1. The second condition would check if BarsSinceEntryExecution is Equal to (==) -1.

    See this help guide page for more information about BarsSinceEntryExecution and sample code: https://ninjatrader.com/support/help...yexecution.htm

    Let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi ! I've made what you suggested and researched and it still doesn't work, here are screenshot of the setup right now, if you don't mind helping me troubleshoot it. I feel its something stupid but I can't see it hahaha

      Thanks a lot for your time !
      Attached Files

      Comment


        #4
        Hello RebelRoby,

        Thanks for your note.

        If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

        To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.

        https://ninjatrader.com/support/foru...121#post791121

        See the attached example script demonstrating the use of BarsSinceEntryExecution.

        Let us know if we may assist further.
        Attached Files
        Last edited by NinjaTrader_BrandonH; 09-06-2022, 03:13 PM.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hi ! thanks for all the information, but even your demonstration isn't working like I need to. Basically I need the trade to get closed at the end of the current candle it has been open on, win loose or draw, if the TP or SL hasn't been reached. On your demonstration its closing at the end of the next candle. My Idea was to use BarsSinceEntryExecution but it may not be the best way to do so, Im open to any suggestion !

          thanks again !

          Comment


            #6
            Hello RebelRoby,

            Thanks for your note.

            I understand that you would like to exit an order at the end of the current candle that the order was opened on.

            This could be accomplished by creating a condition that checks if IsFirstTickOfBar = True (Misc > IsFirstTickOfBar) and calling your Exit order method, such as ExitLong().

            IsFirstTickOfBar lets us know that the current bar is closed and the current tick is the first tick of a new bar.

            See this help guide page for more information about IsFirstTickOfBar: https://ninjatrader.com/support/help...ttickofbar.htm

            Let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Perfect ! Exactly what I was looking for, appreciate the help !

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by burtoninlondon, Today, 12:38 AM
              0 responses
              5 views
              0 likes
              Last Post burtoninlondon  
              Started by AaronKoRn, Yesterday, 09:49 PM
              0 responses
              12 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Yesterday, 08:42 PM
              0 responses
              11 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Yesterday, 07:51 PM
              0 responses
              13 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,982 views
              3 likes
              Last Post jhudas88  
              Working...
              X