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 pibrew, Today, 06:37 AM
    0 responses
    1 view
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    13 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    11 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    15 views
    0 likes
    Last Post AaronKoRn  
    Working...
    X