Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variable for different price levels

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

    Variable for different price levels

    Lets say I have 4 different price levels that I want in my strategy.

    The 4 prices are

    4400
    4300
    4200
    4100

    The strategy would take a long position when price crosses the level. What's an easier way to write this out in Ninjascript instead of

    Code:
    (CrossBelow(Close, 4400, 1)
    ||
    (CrossBelow(Close, 4300, 1)
    ||
    (CrossBelow(Close, 4200, 1)
    ||
    (CrossBelow(Close, 4100, 1)

    #2
    Hello Ousher,

    Thanks for your post.

    This would be a personal coding preference but you could consider using a loop and a List.

    You would store the prices in your List and then loop through the list.

    See the attached example script demonstrating this. In the example script, the 4 prices are stored in a List. Then, we loop through that List and check if a CrossBelow condition occurred for an item in that list. When the condition is true, the strategy calls EnterShort() and prints out "CrossBelow condition true", the Close price, and the price from the List to a NinjaScript Output window (New > NinjaScript Outpput).

    Let us know if we may further assist.
    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

    Latest Posts

    Collapse

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