• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using MAX() for defining entry levels in previous range

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

    Using MAX() for defining entry levels in previous range

    Hello,

    I am trying to do a strategy when you enter the position when the price is at certain % level of the price range of given previous period. - Near highs and lows of the period.
    I thought the function MAX() would do that, but the script doesnt work and opens random trades on every bar

    the code is as follows:


    if (BarsInProgress != 0)

    return;

    if (CurrentBars[0] < 12)

    return;

    // Set 1

    double value = MAX(High, 10)[0];

    if (Close[0] >=( value *0.9))

    {

    EnterShort(Convert.ToInt32(DefaultQuantity), "");

    }

    .
    .
    The variable value is defined like this:

    private double value;


    It should open the trade when the price is in the range of 10% near the high of previous 10 bars.

    Thanks for any advice

    #2
    Hello ExNihilon,

    Thanks for your post.

    Your logic does not look like there would be any issues, but I may suggest the following:
    1. When testing strategy logic, use prints to show you exactly how your conditions are evaluating and if the order methods are getting reached
    2. MAX(High, 10)[0] will return the highest high from the current bar and going 9 bars back. If you would like the highest high of the 10 bars before the current bar, you will want to use a BarsAgo reference of 1 with MAX i.e. MAX(High, 10)[1]
    Another common issue seen is when a strategy is enabled with Wait Until Flat, and the strategy calculates a virtual position from processing historical data. The strategy must become flat before it is allowed to trade live. You can observe if a strategy enabled with Wait Until Flat is in a historical position that it first needs to close if the strategy has a yellow color in the Strategies tab of the Control Center.

    It is important to understand the difference between Strategy Positions and Account Positions and the Start Behaviors used with NinjaScript Strategies. Please see the documentation below for more details.

    Strategy vs. Account Position - https://ninjatrader.com/support/help..._account_p.htm

    Start Behaviors - https://ninjatrader.com/support/help..._positions.htm

    Debugging tips are also linked below.

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

    Let us know if you have any questions interpreting the debug output.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello ExNihilon,

      Thanks for your post.

      Your logic does not look like there would be any issues, but I may suggest the following:
      1. When testing strategy logic, use prints to show you exactly how your conditions are evaluating and if the order methods are getting reached
      2. MAX(High, 10)[0] will return the highest high from the current bar and going 9 bars back. If you would like the highest high of the 10 bars before the current bar, you will want to use a BarsAgo reference of 1 with MAX i.e. MAX(High, 10)[1]
      Another common issue seen is when a strategy is enabled with Wait Until Flat, and the strategy calculates a virtual position from processing historical data. The strategy must become flat before it is allowed to trade live. You can observe if a strategy enabled with Wait Until Flat is in a historical position that it first needs to close if the strategy has a yellow color in the Strategies tab of the Control Center.

      It is important to understand the difference between Strategy Positions and Account Positions and the Start Behaviors used with NinjaScript Strategies. Please see the documentation below for more details.

      Strategy vs. Account Position - https://ninjatrader.com/support/help..._account_p.htm

      Start Behaviors - https://ninjatrader.com/support/help..._positions.htm

      Debugging tips are also linked below.

      Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

      Let us know if you have any questions interpreting the debug output.

      Thank you Jim,

      I did the debug and found the mistake. Unfortunately it is in the logic of my strategy. What I want to do is open a trade if the current price is in the lower or upper 10% of PRICE RANGE (highest price vs lowest price)in defined previous period - 5days,10 days or 20days..

      What my previous code did instead was that it took the HIGHEST PRICE in the period and multiplied it by 0,9 which meant the triggering price was immediately 10% lower and so it triggered trades constantly.

      So it did not work with the price range but with the highest price.

      Now,would you have any advice how to achieve what I want? Is there any function of computing price range, so that I could maybe multiply and get the to the point where the current price is in the upper 10% of the previous price range to go short?

      Thank you again.

      Comment


        #4
        You would have to calculate the range on your own, but it sounds like you are most of the way there.

        You have the Highest High for the range found using MAX and the High Price Series. You could use MIN and the Low Price Series to get the minimum value for the range.

        MIN - https://ninjatrader.com/support/help...inimum_min.htm

        You can subtract the low from high to get the difference, and then that difference would represent your range. You can then take multiples of that range and use it with your logic as needed.

        We would not be able to provide assistance in giving you exact logic to accomplish your goal, but this direction and should be able to get you started.

        Let us know if there is anything else we can do to help.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thank you Jim for your advice, I solved my problem thanks to it.

          Take care.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by mpower, 05-27-2011, 01:16 PM
          4 responses
          2,586 views
          0 likes
          Last Post nkhoi
          by nkhoi
           
          Started by brucerobinson, Today, 02:43 AM
          5 responses
          31 views
          0 likes
          Last Post brucerobinson  
          Started by 2Look4me, Today, 09:33 AM
          6 responses
          39 views
          0 likes
          Last Post NinjaTrader_PatrickH  
          Started by calebsandfort, Today, 02:11 PM
          2 responses
          10 views
          0 likes
          Last Post calebsandfort  
          Started by traderpards, Today, 02:16 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jim  
          Working...
          X