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 find the Low of the Highest Bar since Entry?

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

    How to find the Low of the Highest Bar since Entry?

    Hi Team,
    Could you please help me with this query on how to trail my stop to the low of the highest bar since my long entry? I am not able to overcome this step since there can be multiple inside bars, so High[0] > High[1] and so on will not let me pinpoint the bar with the highest high after the entry. Please help. Thanks.

    PS: Apologies if this topic already exists, if someone can share the link for references. thanks. ​

    #2
    Hello deepakoberoi,

    Thanks for your post.

    HighestBar could be used to get the number of bars ago the highest price value occurred within a specified period. That bars ago value could then be used to get the High price or Low price from highest bars ago value.

    See the sample code in the help guide documentation linked below demonstrating this.
    HighestBar: https://ninjatrader.com/support/help...highestbar.htm
    High: https://ninjatrader.com/support/helpGuides/nt8/high.htm
    Low: https://ninjatrader.com/support/helpGuides/nt8/low.htm

    Please let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon,

      Thanks for your prompt response.
      Could you please review this part, I am not getting any compiling error but it's not entering any trades. Please help. Thanks.

      if ((Low[1] < Low[2]) && (Low[1] <= Low[0]) && (High[0] > High[1])) //2-2 or 2-3 scenario
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), @"longentry");
      // CurrentEntryPrice = Close[0];
      StopPrice = Low[1] - TickSize;
      ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), StopPrice, @"exit", @"longentry");
      }


      if (Position.MarketPosition == MarketPosition.Long))
      {
      // store the highest bars ago value
      int HighestBarsAgo = HighestBar(High, Bars.BarsSinceNewTradingDay); //not sure if this part is correct, as I am not sure if i can ask code to count bars after entry only
      // Low price of HighestBarsAgo bars ago
      double barLowPrice = Low[HighestBarsAgo];
      StopPrice = barLowPrice - TickSize;
      }​​

      Comment


        #4
        Hello deepakoberoi,

        Thanks for your note.

        Entry methods and Exit methods should not be called in the same condition in a script. You should separate the Entry method and Exit method in your condition.

        Generally, if the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

        It seems that you do not have prints added to your script in the code you shared to confirm if the condition is becoming true or not. Have you added prints to the script?

        To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.

        https://ninjatrader.com/support/foru...121#post791121

        Let us know if we may assist further.​​
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,404 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        95 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        9 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X