Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Expression As Variable

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

    Expression As Variable

    Is it possible to define a variable with an expression containing Ninja Trader Indicators such as

    SMA(10)[0] < SMA(20)[0]

    where the expression can now be used as any other variable??

    In other words, can I use the above expression as a bool type variable and if so how would the syntax read? Thanks for any input.

    JT454

    #2
    Make it a Method

    You could store it like this and just pass around the variable isLess:

    Code:
    bool isLess = SMA(10)[0] <  SMA(20)[0];
    But if you want to re-calculate the expression every time you use the variable you're probably better off putting it in its own method and using the method wherever you want that expression:

    Code:
    bool IsLess() 
    {
    return SMA(10)[0] < SMA(20)[0];
    }

    Comment


      #3
      Because of precedence of operators, I would add parentheses to avoid ambigious statements. Like this:

      bool isLess = (SMA(10)[0] < SMA(20)[0]);

      But bool has only two values, true and false, hardly a real variable; so for readibility concerns, the conditional statement would commonly be part of an if statement. Like this:

      if ( SMA(10) < SMA(20))
      {
      // set bool variable to true or false, or do something else
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Stanfillirenfro, Today, 05:31 AM
      0 responses
      1 view
      0 likes
      Last Post Stanfillirenfro  
      Started by sidlercom80, Today, 04:45 AM
      0 responses
      3 views
      0 likes
      Last Post sidlercom80  
      Started by NT-Roland, Today, 04:44 AM
      0 responses
      4 views
      0 likes
      Last Post NT-Roland  
      Started by knarfoe, Today, 04:26 AM
      0 responses
      2 views
      0 likes
      Last Post knarfoe
      by knarfoe
       
      Started by manueldecastro, Yesterday, 10:59 PM
      2 responses
      9 views
      0 likes
      Last Post manueldecastro  
      Working...
      X