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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X