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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 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