Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Q: How do I save and use code later in script?

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

    Q: How do I save and use code later in script?

    Hi NT8 support,

    I'd like to do the following; save a code snippet so I can use it in multiple spaces later in the script so I don't have to copy and paste it into all subsequent if statements:


    (Save Code [how do I do this]):
    {
    Condition 1
    && Condition 2
    }



    if ( Condition 3
    && Condition 4
    && (Saved Script)

    )
    {
    //do something
    }

    if ( Condition 5
    && Condition 6
    && (Saved Script)
    )
    {
    //do something
    }



    Thank you!

    #2
    Hello Austiner87,

    Thank you for the post.

    That is a good use case for a bool or a bool method:

    Code:
    bool myBool = condition1 && condition2;
    bool myBool = ( (Close[0] > Open[0]) && (High[0] > Open[0]) )
    
    if(condition3 && myBool)

    You can also make a return method:

    Code:
    private bool MyMethod()
    {
        return (Close[0] > Open[0]) && (High[0] > Open[0]);
    }
    
    protected override void OnBarUpdate()
    {
        if(condition3 && MyMethod())
    }

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X