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

How to do variable assignment in StrategyBuilder and Use it in Condition

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

    How to do variable assignment in StrategyBuilder and Use it in Condition

    I am trying to do something like below in Strategybuilder.

    User Inputs:
    FastEMA = 5
    SlowEMA = 10
    Multipler = 1.25

    User Variables:
    EMA1
    EMA2
    BuyCondition


    I want to do the assignment like

    EMA1 = EMA(FastEMA)
    EMA2 = EMA(SlowEMA)
    BuyCondition = EMA > EMA2 && ATR * Multipler


    In Condition Wizard

    I just want to use

    if All:


    BuyCondition
    SMA(50) > Close



    I know I can handle the buy condition without declaring as Variable inside the condition wizard but I specially want to do as the Variable assignment so better code management.

    Attached is the snapshot






    Attached Files

    #2
    Hello futtrader,

    In order to use a variable as part of the condition you would need to use a second set. A first set could set the variable to the value you wanted and then a second set could check for that variables value and then reset the vraile to toggle it back off.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello futtrader,

      In order to use a variable as part of the condition you would need to use a second set. A first set could set the variable to the value you wanted and then a second set could check for that variables value and then reset the vraile to toggle it back off.
      Sorry I did not get this

      that variables value and then reset the vraile to toggle it back off.

      Can you give small example video/snapshot to understand this.

      Comment


        #4
        Originally posted by futtrader View Post

        Sorry I did not get this

        that variables value and then reset the vraile to toggle it back off.

        Can you give small example video/snapshot to understand this.
        The Strategy Builder only allows for the following variable types: Bool, Double, String, Int, and Time. This means you would not be able to create variables for EMA1 and EMA2, though you could certainly still use FastEMA and SlowEMA as user inputs for the periods similar to this tutorial example:


        Since a bool variable is an option, you could set up a variable for BuyCondition that toggles to true when the condition is met and false when the condition is not met. Here are some screenshot examples of how you would set up the Conditions and Actions set to set BuyCondition to true, a set to toggle it to false, and a way to check in a separate set if it is true as part of the conditions:I have also exported and attached the example to this post, which you could use as a shell for your strategy or copy the ideas into your own strategy. The example may be imported at Control Center > Tools > Import > NinjaScript AddOn and then you may view it in the Strategy Builder and click through the screens or open up each condition to see further how they are configured.

        Please let us know if we may be of further assistance.
        Attached Files
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Thanks this is good to start. So for EMA I can see code is creating EMA1 and EMA2 variable.

          is it possible to use EMA1 and EMA2 variable directly in strategy builder - if I decide to use it in 10 different place .

          or evertime when I need to use EMA for fast and slow I must have to use it through Indictor EMA set fast/slow ?

          Basically question is, can we Re-Utilize variables created by Strategy Builder ?


          Also this code was created using Strategy Builder
          ​-I want to understand why same period Strategy Builder ​is creating new Variable
          See line # 69 and 70.

          Also Strategy Builder ​is not recognizing that variable
          HTML Code:
          Fast = 5
          and EMA1 is created using fast Period ; but still it's creating EMA4 when I supply numeric value 5 to EMA Indicator in Strategy builder.​
          Attached Files
          Last edited by futtrader; 12-25-2023, 04:38 PM.

          Comment


            #6
            Hello futtrader,

            The variables that are auto created for strategy builder scripts for indicators are just for the builders use in code, you wouldn't reference that directly. To use the ema you would need to select Indicators -> EMA in the condition and select fast or slow for the period. When you use the builder you don't use the code at all, everything is done by using the menus in the condition builder. Each time you use a numeric value that will generate a new variable even if one of your user inputs uses the same value. You can ignore the code completely while using the builder, that would only be relevant if you wanted to unlock the code and manually code it.


            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by SnailHorn, Today, 10:49 PM
            0 responses
            7 views
            0 likes
            Last Post SnailHorn  
            Started by naanku, Today, 07:25 PM
            0 responses
            8 views
            0 likes
            Last Post naanku
            by naanku
             
            Started by milfocs, Today, 07:23 PM
            0 responses
            6 views
            0 likes
            Last Post milfocs
            by milfocs
             
            Started by PaulMohn, Today, 06:59 PM
            0 responses
            8 views
            0 likes
            Last Post PaulMohn  
            Started by bortz, 11-06-2023, 08:04 AM
            48 responses
            1,756 views
            0 likes
            Last Post carnitron  
            Working...
            X