Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Check if price drop condition

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

    Check if price drop condition

    Hi everyone

    I want to have a condition that checks last before if there was a huge Drop or Pump in price.
    So I would have a double that gives me an input that I can specify in strategy parameters .
    Let's say my double is PriceChangeLastBar: 20
    So my condition will check at the beginning of each bar if the price has dropped or pumped by 20 in the last bar

    is there anyway to make this code?
    Thanks

    #2
    Hello onlinebusiness,

    Thanks for your post.

    To clarify, you want to check if the current Open price (Open[0]) is greater than or less than the previous Close price +/- 20 Ticks. Is that correct?

    Something you could do is create a condition that checks if the current Open price (Open[0]) is Greater than or Less than the previous close price (Close[1]) +/- a tick offset (PriceChangeLastBar).

    For example, say PriceChangeLastBar is equal to 20 and you want to check if the current Open price is Greater than the previous Close price + 20 ticks. See the attached screenshot showing what this condition would look like in the Strategy Builder.

    You could set up a similar condition on your end using the Strategy Builder and click the 'View code' button to see the generated syntax.

    See the help guide documentation below for more information.

    Working with the Strategy Builder: https://ninjatrader.com/support/help...gy_builder.htm

    Please let me know if I may assist you further.
    Attached Files
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Click image for larger version

Name:	
Views:	0
Size:	57.7 KB
ID:	1229087 Hi Brandon, thanks for the help, it worked somehow

      I put it something like this:

      Code:
      protected override void OnBarUpdate()
              {
      
                  /// LONG Trades
                  if ( (Open[2] + (PriceUp * TickSize) > Open[0])
                      // Trading Hours Before 15 PM and After 17 PM
                      && ((Times[0][0].TimeOfDay >= new TimeSpan(17, 10, 0))
                      || (Times[0][0].TimeOfDay < new TimeSpan(14, 00, 0)))
                      )
                  {    
                      EnterLong(Contracts, "Long");
                      justEntered = true;​​
      PriceUp == 100

      Issue whenever I enable the strategy, it get disabled instantly on the chart.
      On The logs I get this error in the screenshot attached

      And if I remove the condition:

      if ( (Open[2] + (PriceUp * TickSize) > Open[0])

      The strategy work just fine.

      how can I make it work while I keep this condition? I must use that condition​
      Last edited by onlinebusiness; 12-28-2022, 12:13 AM.

      Comment


        #4
        Hello onlinebusiness,

        Thanks for your note.

        This error message indicates that you are trying to access a BarsAgo value in your script that has not yet been processed.

        As one example, calling Close[1] when CurrentBar is 0 (the very first bar) will cause this error. The reason for this is because there will not be a bar ago; essentially there is not enough data at bar 0 to look back one bar.

        A CurrentBar check should be added to your script to ensure that there are enough bars processed for the BarsAgo value you are accessing. If you have multiple data series added to your script, you would need to use a CurrentBars check.

        See the example of a CurrentBar check below.

        Code:
        if (CurrentBar < 10)
            return;
        This would check to make sure that 10 bars have been processed before the script begins its calculations.

        See the help guide documentation below for more information.

        CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
        CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
        Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

        Let us know if we may assist further.​
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        53 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        70 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X