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

Deep understanding of BarsSinceEntry/Exit

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

    Deep understanding of BarsSinceEntry/Exit

    Hi Support

    I would like to set my initial stop loss for long entries at the lowest low that occurred during my last short trade. I think the way to go is using BarsSinceEntry() and BarsSinceExit(), please correct me if wrong. Would the code below be the correct solution to my problem:

    Code:
    private double stop = 0;
    
    stop = MIN(Low,BarsSinceEntry(Short))[BarsSinceExit(Short)];

    #2
    Hello sburtt,

    I think you want:
    MIN(Low, BarsSinceEntry(short)-BarsSinceExit(short))[BarsSinceExit(short)]

    This would use a period of number of bars the order was in a position for, with an offset of the exit bar.

    This is assuming that the short variable is a string that is the entry orders entry signal.
    I do not recommend using short as a variable name as short is used as an identifier (object type) for a type of number (a 16-bit integer from -32,768 to 32,767).
    Last edited by NinjaTrader_ChelseaB; 11-13-2013, 10:11 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello sburtt,

      I think you want:
      MIN(Low, BarsSinceEntry(short)-BarsSinceExit(short))[BarsSinceExit(short)]

      This would use a period of number of bars the order was in a position for, with an offset of the exit bar.

      This is assuming that the short variable is a string that is the entry orders entry signal.
      I do not recommend using short as a variable name as short is used as an identifier (object type) for a type of number (a 16-bit integer from -32,768 to 32,767).
      yes that should work. but at this point I have a few things I still don't fully understand and I would appreciate your advise:

      1. I will change the variable name, but for simplicity lets use "short" in this example. When I am in a short position I can exit in multiple ways, each exit type has a different name (e.i. short exit 1, short exit 2). When referring to the BarsSinceExit() method and the string signalName it calls, should this signalName be the fromEntrySignal ("short")used in the stoploss I use or the signalName used for the stop loss ("short stop 1")?

      2. How can I check that I had at least 1 short prior using this code to avoid having an error message?

      Thanks for your assistance

      Comment


        #4
        Hello sburtt,
        1. In the BarsSinceExit you will need to use the signalName (fromEntrySignal) used on the entry order.
        2. You can check that there is at least 1 short trade with the following:
          if (Performance.ShortTrades.Count > 0)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello sburtt,
          1. In the BarsSinceExit you will need to use the signalName (fromEntrySignal) used on the entry order.
          2. You can check that there is at least 1 short trade with the following:
            if (Performance.ShortTrades.Count > 0)
          very helpful. thanks

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello sburtt,
            1. In the BarsSinceExit you will need to use the signalName (fromEntrySignal) used on the entry order.
            2. You can check that there is at least 1 short trade with the following:
              if (Performance.ShortTrades.Count > 0)
            Chelsea, I've a last thing I want to ask you as I am not 100% sure.

            assuming my primary time frame is 60 minutes (BarsArray[0]) and my secondary time frame is 1 minute (BarsArray[1]). Am I right in thinking that this code below will return the the entry bar of the last Short position taken counting on 60 min bars?

            BarsSinceEntry(0,"Short",0)

            and what exactly is the "entriesAgo" (Number of entries ago. Pass in 0 for the number of bars since the last entry)? what I mean is, if I enter 1 rather than 0 what outcome should I expect?

            Thanks, thats all

            Comment


              #7
              Hi sburtt,

              Your usage of BarsSinceEntry is correct for the entry time and info of an order placed on the primary (60 minute) time frame, with an entry signalName of "Short", and the most recent exit.

              The entriesAgo is the offset of how many orders back you are looking. For example if you've made 5 orders and you are wanting to know how many bars were between the previous entry and the exit of the entry before it you would find the barsAgo value of the previous entry using the "Short" signalName with BarsSinceEntry(0, "Short", 1). Then you would find the barsAgo value of the exit of the entry before it with BarsSinceExit(0, "Short", 2). With this information you can do simple subtraction to know how many bars passed between the exit of 2 orders ago and the entry of the previous order.
              barsBetweenLastOrder = BarsSinceExit(0, "Short", 2) - BarsSinceEntry(0, "Short", 1);

              Btw, here is a link to BarsSinceEntry() in the help guide in case you need it.
              http://www.ninjatrader.com/support/h...ssinceexit.htm
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Touch-Ups, Today, 10:36 AM
              0 responses
              5 views
              0 likes
              Last Post Touch-Ups  
              Started by geddyisodin, 04-25-2024, 05:20 AM
              8 responses
              61 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by jxs_xrj, 01-12-2020, 09:49 AM
              4 responses
              3,289 views
              1 like
              Last Post jgualdronc  
              Started by Option Whisperer, Today, 09:55 AM
              0 responses
              5 views
              0 likes
              Last Post Option Whisperer  
              Started by halgo_boulder, 04-20-2024, 08:44 AM
              2 responses
              24 views
              0 likes
              Last Post halgo_boulder  
              Working...
              X