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

Bools and strategy builder.

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

    Bools and strategy builder.

    Hello All, hope your Sunday is going well.

    I have a question on bools. I am using the strategy builder and trying to prevent multiple trades per direction.

    Example. Say I have a simple Psar strategy that shoots a signal once the Psar plots the first dot either above or below. As it stands right now, if the signal is still valid after my initial TP or SL it takes another trade. I am wanting to stop this from happening. Only one trade per signal. Take the first buy, get the TP or SL and then wait until the next signal. First one is a buy, gets TP and doesn't fire again until there is a sell, and then repeats that process. I use the strategy builder right now and have had some suggestions of using bools but am unsure how to use this in the conditions and trigger's part. Any help or insight would be mucho appreciated.

    Thanks

    #2
    Default properties screen there's an option on the second page to limit entries. See pic below. That will put this statement in your State.SetDefaults section:

    Code:
    EntriesPerDirection = 1;
    Besides that, I put this in my code to take only 1 entry per bar:

    Right at the top:
    Code:
    private bool thisBarLongTraded = false;
    private bool thisBarShortTraded = false;
    Then in onBarUpdate()

    Code:
    if (IsFirstTickOfBar)
    {
    thisBarLongTraded = false;
    thisBarShortTraded = false;
    }
    And finally when taking the trade:
    Code:
    if (whatever signal)
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"LE");
    thisBarLongTraded = true;
    }​


    Comment


      #3
      markdshark - Thanks for the reply, however I'm not sure that is what I am looking for. I have attached "hopefully" 2 screenshots showing my concern. The first shows the analyzer summary. The number of traded for one day is nauseous. 800+. The second shows the chart that has multiple entries per direction. I would like to try to limit one entry per "signal". I also have the #of entries per direction set to 1. Not sure where Im going wrong. I use the builder as I am not very well versed in C# so right now the editor doesnt make sense to me. Thanks
      Attached Files

      Comment


        #4
        Sorry.. read too quickly. One trade per direction, got it. If I understand correctly, then still easy just switch the code to this:

        when taking the trade:
        Code:
        if (whatever signal && !long traded) { EnterLong(Convert.ToInt32(DefaultQuantity), @"LE"); LongTraded = true; ShortTraded = false;}​
        then flip the boolean flags when you take a short trade. This way you'll never take 2 in the same direction.

        Best

        Comment


          #5
          Thanks for the reply, it looks like the code should do what I want, however, not being a coder, when I try to add it to the unlocked code, I get errors like "the name "X" does not exist in current context. Im probably not declaring something. Is this possible to do in the builder. I tried to set some bools but don't think it's going right. Thanks for the help and sorry for my lack of knowledge. lol

          Comment


            #6
            Sounds like you don't have the variables declared. You'd need to declare them up top kinda like this:

            Code:
            private bool thisBarLongTraded = false;
            private bool thisBarShortTraded = false;​
            Setting them to false will ensure your first trade gets executed whether long or short

            Comment


              #7
              Hello sprks7979,

              I've got an example using bools in the Strategy Builder you may find helpful.
              Hi, To improve a strategy, I would like the condition to enter a trade to be triggered only after a second crossing happens. Meaning, for instance we have a sthocastics crossing, but the strategy would only trigger when a crossing between 2 emas happen. Would the looking back N bars work? Can it be done within the builder


              In the Strategy Builder, bools and other variables are declared on the Inputs and variables page.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by futtrader, 04-21-2024, 01:50 AM
              4 responses
              41 views
              0 likes
              Last Post futtrader  
              Started by Option Whisperer, Today, 09:55 AM
              1 response
              11 views
              0 likes
              Last Post bltdavid  
              Started by port119, Today, 02:43 PM
              0 responses
              7 views
              0 likes
              Last Post port119
              by port119
               
              Started by Philippe56140, Today, 02:35 PM
              0 responses
              7 views
              0 likes
              Last Post Philippe56140  
              Started by 00nevest, Today, 02:27 PM
              0 responses
              7 views
              0 likes
              Last Post 00nevest  
              Working...
              X