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

Using MAX() for defining entry levels in previous range

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

  • ExNihilon
    replied
    Thank you Jim for your advice, I solved my problem thanks to it.

    Take care.

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • ExNihilon
    replied
    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.

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • 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

Latest Posts

Collapse

Topics Statistics Last Post
Started by andrewtrades, Today, 04:57 PM
1 response
5 views
0 likes
Last Post NinjaTrader_Manfred  
Started by chbruno, Today, 04:10 PM
0 responses
3 views
0 likes
Last Post chbruno
by chbruno
 
Started by josh18955, 03-25-2023, 11:16 AM
6 responses
436 views
0 likes
Last Post Delerium  
Started by FAQtrader, Today, 03:35 PM
0 responses
6 views
0 likes
Last Post FAQtrader  
Started by rocketman7, Today, 09:41 AM
5 responses
19 views
0 likes
Last Post NinjaTrader_Jesse  
Working...
X