Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

break out

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

    break out

    Hello,

    I am trying to write a very simple breakout strategy but I don't know why I am having so much difficulty. All I want to do is lokk at first 60 bars on any chart and store Highest high and the lowest Low of the first 60 bars. Then, go long if price moves 1 tick above highestHigh or go short if price move below lowestLow by 1 tick. Profit target and stoploss are 30 ticks and I want to do this trade only once per trading session. attached is my Ninjascript .txt file which I think is very close but it is not working as outlined above objective. It is ignoring to not trade until after 60 bars and starts to go long or short from second bar. Also, it trades multiple times a day ignoring the tradecounter. Can someone please help me what I need to change?

    Thanks.
    Attached Files

    #2
    Hello questforconsistency,

    One issue is this section:
    if (Bars.FirstBarOfSession)
    highestHigh = High[0];
    lowestLow = Low[0];
    tradecounter = 0;


    If you don't use brackets, only the first line after an if statement is executed. You need brackets { } enclosing those statements if you would like for them to execute on the first bar of session. Without the brackets they are executed with every OnBarUpdate() call.

    You'll also want to use plenty of Print() statements to verify values of all your variables. Print BarsSinceSession, tradecoutner, highestHigh, etc. Additional debugging help is available here:
    Debugging your NinjaScript Code
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      breakout

      Hello Ryan,

      Thanks for your reply.

      I used the brackets as you suggested and also added the print statements. But after making these changes, it is still not working.

      Prtogram does store the high and low of the first bar but instead of waiting for 60 bars to go long or short, it goes long right at the second bar. Also, instead of taking only one trade per day, it goes long multiple times in one day (session). I guess trade counter is not working. I have attached my updated Ninjascript. Can you please help me?

      Thanks.
      Attached Files

      Comment


        #4
        Thanks for the reply. I'm looking into a related issue here. I will update this thread once I learn more.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          The issue with your code is the semi-colons at the end of your if statements. It should evaluate properly with these removed.

          if (Bars.BarsSinceSession > 60 && tradecounter < 1);
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Hello Ryan,

            Thanks for your reply but No luck. In my previous version of the script, it was going long on second bar unlike after 60 bars as it was suppose to. Also it was taking more than one trade per session. So you suggested that I remove the semicolons. Once I removed the semicolons, now the script is not taking any trades at all !!!!!! Attached is the script with semi colons removed.

            I have been very frustrated for past few days and I desperately need this program to work as I think it is preety staright forward program. This time, I would sincerely appreciate it if you can thoroughly check my script and tell me what is wrong and what needs to be fixed in this script.

            Thank you very much.
            Attached Files

            Comment


              #7
              questforconsistency, sorry to hear the frustration, but unfortunately we do not offer code developing nor code debugging services, I suggest you strip down your strategy to the bare essentials and confirm with prints the values you expect get calculated as needed to trigger your trade taking conditions. Only then add complexity to it and confirm again with prints on each step that you're on track. Running in Market Replay might prove to be a valuable debugging tool as well as certain conditions can be redone over and over again until they 'hit' they way you need them.
              BertrandNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cls71, Today, 04:45 AM
              0 responses
              1 view
              0 likes
              Last Post cls71
              by cls71
               
              Started by mjairg, 07-20-2023, 11:57 PM
              3 responses
              213 views
              1 like
              Last Post PaulMohn  
              Started by TheWhiteDragon, 01-21-2019, 12:44 PM
              4 responses
              544 views
              0 likes
              Last Post PaulMohn  
              Started by GLFX005, Today, 03:23 AM
              0 responses
              3 views
              0 likes
              Last Post GLFX005
              by GLFX005
               
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              12 views
              0 likes
              Last Post XXtrader  
              Working...
              X