Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by AaronKoRn, Today, 09:49 PM
    0 responses
    11 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    10 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    11 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,980 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X