Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Keeping track of BE levels per trade

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

    Keeping track of BE levels per trade

    I am trying to set up unique BE trigger levels that, once hit, move a specific amount of ticks from that trades entry point up or down depending on direction. Once the entry and stop loss has been calculated, I can then calculate where the BE trigger price level would be, and where the SL would be moved once that price is hit.

    I current have 5 double variables, BELevel1, Level2, etc and 5 double BEPriceLevel1, PriceLevel2 etc. Once the trade is entered, I check if BELevel1 is 0, if not, I use that variable. If it is already used, I move on to BELevel2, etc. Once price moves to or beyond my Level, I reset that level back to 0. Also, if at anytime my position becomes flat, then I reset all the levels and start fresh.

    I feel there should be a better way to keep track of this? maybe using a list, array or dictionary of some sort?

    I have int counters, longEntryCount and shortEntryCount to keep track of unique entries in both directions, and am using them as apart of the long and short entry signals, but am unsure of a good way to use this together with my levels.

    I want to be able to keep track of these in case I happen to take multiple trades in the same direction without the first hitting the trigger level.

    Am I just overthinking this? What do most people do? I can't imagine everyone would only use I variable and only reuse it once the original trade has been closed.

    #2
    Hello rockmanx00,

    How you design the code is ultimately up to you.

    Using lists may be helpful to organize your code.

    Below is a link to a User App Share script that utilizes different collection types you may get some ideas from.
    This indicator serves to provide labels for Atm strategies that are present on your chart. Each new Atm strategy will rotate through the colors defined in your Brush Collection. Simply add to a chart, select the data series you want to have labels added to, choose your font and add all the brushes/colors you want […]


    This thread will remain open for any community members that would like to provide advice and experience.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea

      Comment


        #4
        Ok. So I have decided to use Dictionaries, for now. I am currently using them to store the double that is my BE level, as well as the signal name. I have tried to create a BELevels Dictionary variable along with the rest of my private variables within the public Class level. However, when I try to access this, it creates an error saying " Object reference not set to an instance of an object.". If I add Dictionary <double, string> BELevels = new Dictionary<double, string>(); then the BELevels will work and add and all that, but it only works within that section of code. If I'm in State.Configure, I can put that in but it won't use the dictionary in OnBarUpdate. I want to understand how to use the dictionary in a way that I can reference it within all sections of my code, but I can't find any general c# examples for my problem. Having an example in Ninjascript would give me better context and understanding of why this isn't working and how to get it to work.

        Comment


          #5
          Hello rockmanx00,

          Is the BELevels variable declared in the scope of the class and a new object instantiated and assigned to the variable in State.DataLoaded of OnStateChange()?

          If you are unfamiliar with scope, see the section on scope in the support article linked below.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            I'm pretty familiar with scope. I'm taking courses as well to really familiarize myself with c# in general, but I am trying to declare and instantiate it with the rest of my private variables. And within OnBarUpdate I am simply trying to check the count using a print statement and BELevels.Count. when I do this it makes an error. When I hover above BELevels in this case it says that's it's a Dictionary type. If I instantiate it again within OnBarUpdate, it no longer makes the error, but BELevels is now a local variable. Does that make it clear what I'm doing and trying to do? Or do you need further explanation?

            Comment


              #7
              Hello rockmanx00,

              I wasn't able to confirm, is the BELevels variable declared in the scope of the class and a new object instantiated and assigned to the variable in State.DataLoaded of OnStateChange()?

              "If I instantiate it again within OnBarUpdate, it no longer makes the error, but BELevels is now a local variable."

              A class level variable cannot become local.
              You are 100% certain you are not declaring a second variable with the same name in OnBarUpdate() correct? (Ambiguous)
              The variable is declared in the scope of the class?

              Once declared, a new object is instantiated in OnStateChange() and assigned to the variable?

              "Does that make it clear what I'm doing and trying to do? Or do you need further explanation?"

              Unfortunately no, this does not make clear what is in the script.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Ok. I think I figured out where I went wrong.
                Within the scope of the class I am adding this to where all my private variables are:
                private Dictionary<double,string> BELevels;

                So, I was declaring it, but had not yet instantiated it yet. So I changed it to

                private Dictionary<double, string> BELevels = new Dictionary<double, string>();

                I thought I had done that before but I must have been only trying to instantiate it within OnStateChange.

                Thank you so much for your help and insight Chelsea

                Comment


                  #9
                  Hello rockmanx00,

                  I'm suggesting you declare the variable in the scope of the class and instantiate a new object and assign this to the variable in State.DataLoaded of OnStateChange(). This will prevent issues when optimizing.

                  In the scope of the class:
                  private Dictionary<double,string> BELevels;

                  In OnStateChange():
                  BELevels = new Dictionary<double, string>();
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    I'll give that a try.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by davider97, Yesterday, 09:42 AM
                    11 responses
                    65 views
                    0 likes
                    Last Post davider97  
                    Started by XanderT, Today, 03:47 AM
                    9 responses
                    29 views
                    0 likes
                    Last Post XanderT
                    by XanderT
                     
                    Started by totalnewbie, Today, 10:03 AM
                    3 responses
                    6 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by sgordet, Today, 10:34 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_ChristopherJ  
                    Started by DanielRaz, 05-06-2024, 12:54 PM
                    3 responses
                    47 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X