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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X