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

How to check the highest bar since entry

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

    How to check the highest bar since entry

    Hello!

    How comes in NT scripting language what follows?

    - "if the current bar's high is higher than all the previous bars since entry, do something"

    Thanks anyone will support.

    #2
    Hello Quikito,

    Thanks for writing in to our Support team.

    To see if the current bar's high is higher than any of the previous bar's high since entry, you would need to perform this check:

    Code:
    if(High[0] > High[HighestBar(High, BarsSinceEntry())])
    {
    //do something
    }
    You can find more information on the BarsSinceEntry() method and the HighestBar() method and the High property in our help guide here:

    BarsSinceEntry() -http://ninjatrader.com/support/helpG...sinceentry.htm

    HighestBar() - http://ninjatrader.com/support/helpG...highestbar.htm

    High - http://ninjatrader.com/support/helpGuides/nt7/high.htm

    Please let me know if I may be of any further assistance.
    Alan S.NinjaTrader Customer Service

    Comment


      #3
      It works! Great!!!

      Thanks a lot!

      Using that formula for each bar on OnBarUpdate() method to trail a stoploss, I noticed it takes a lot of time to backtest a strategy and I'm looking for an improvement in backtesting performaces.

      I am actually using this code:

      Code:
      		if 	(High[0] >= target1 
      			&& High[0] > High[HighestBar(High, BarsSinceEntry())])
      			{
      			SetStopLoss("", CalculationMode.Percent, trailing_stop_percentage, false);
      			}
      Why backtest bacame so slow? Is there any option to make it faster without using the SetTrailingStop() method?

      Regards
      Last edited by Quikito; 03-31-2017, 06:49 AM.

      Comment


        #4
        Hello Quikito,

        Thanks for your reply.

        Running the logic to determine the highest bar since entry can be improved by saving the bar result to a variable instead of running the HighestBar() logic each time in your if() check.

        For example:
        Code:
        // set this variable after entering a trade
        tradeHighBar = CurrentBar;
        if(High[0] > High[tradeHighBar - CurrentBar])
             {
              tradeHighBar = CurrentBar;
             // do something
             }
        Please let me know if I may be of any further assistance.
        Alan S.NinjaTrader Customer Service

        Comment


          #5
          Great idea!
          AlanS you are the best!

          The code I am actually using is:

          Code:
          // set this variable after entering a trade
          tradeHighBar = CurrentBar;
          if(High[0] > High[CurrentBar - tradeHighBar])
               {
                tradeHighBar = CurrentBar;
               // do something
               }
          As you can see I changed the index value [int barsAgo] of High from High[tradeHighBar - CurrentBar] to High[CurrentBar - tradeHighBar]

          Does it make sense?

          Comment


            #6
            Hello Quikito,

            Thanks for your reply.

            Yes the changes you made to the code do make sense, please let me know if you do not see the expected results when testing.

            If you have any further NinjaTrader inquiries, please do not hesitate to ask.
            Alan S.NinjaTrader Customer Service

            Comment


              #7
              It seems to work very good and very fast, thanks!
              Last edited by Quikito; 04-01-2017, 01:54 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by algospoke, 04-17-2024, 06:40 PM
              3 responses
              26 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by bmartz, 03-12-2024, 06:12 AM
              3 responses
              29 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by Aviram Y, Today, 05:29 AM
              2 responses
              10 views
              0 likes
              Last Post Aviram Y  
              Started by gentlebenthebear, Today, 01:30 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by cls71, Today, 04:45 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X