Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to use offset to subtract user variable

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

    How to use offset to subtract user variable

    I am working on a sell short strategy where I need to set my profit target to the current low minus the price defined by a multiplier of ATR(20) (user defined variable I call ATRFactor).

    What this means is that I would set my profit target at the following:
    Low(0) - ATR(20) * (1 + ATRFactor).

    I have struggle with this for a while as I don't know how to "subtract" in the wizard.

    I know I an use the Offset type to add or subtract a fixed number in the Condition Builder, and I know I can use the same to add a variable or indicator

    How do I subtract it?

    It must be simple but I cannot find it

    Thanks for your help

    #2
    Originally posted by agosinv View Post
    I am working on a sell short strategy where I need to set my profit target to the current low minus the price defined by a multiplier of ATR(20) (user defined variable I call ATRFactor).

    What this means is that I would set my profit target at the following:
    Low(0) - ATR(20) * (1 + ATRFactor).

    I have struggle with this for a while as I don't know how to "subtract" in the wizard.

    I know I an use the Offset type to add or subtract a fixed number in the Condition Builder, and I know I can use the same to add a variable or indicator

    How do I subtract it?

    It must be simple but I cannot find it

    Thanks for your help
    I just tried to do as you are trying to do, and I couldn't figure it out either. It doesn't look possible.

    I tried to research it, and couldn't find anything about it.

    Comment


      #3
      Do I have to create an "indicator" or a function that inverts a number in a variable?
      It seems easy from a programming point of view.
      Thanks

      Comment


        #4
        agosinv, yes for realized those arithmetic operations please create an indicator / function performing this task which you could in turn then call in your wizard script. Extending this area in the wizard interface is on our feedback list for future consideration, I will make sure your vote is noted here as well.

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          agosinv, yes for realized those arithmetic operations please create an indicator / function performing this task which you could in turn then call in your wizard script. Extending this area in the wizard interface is on our feedback list for future consideration, I will make sure your vote is noted here as well.
          Bertrand

          I tried creating the function using the wizard. I could not find how.

          Do you have some sample code I can use?

          The trick is passing the variable as input when I call the function.

          Thanks a lot

          Comment


            #6
            I would just create an indicator displaying / calculating those ATR stop values, then the ATRFactor you have could be a user input that would be callable / optimizable in your strategy from the wizard interface then as well.



            Two of such stop variants are also offered in our user sharing section here, you might be able to use them as 'base' to further develop on -

            Comment


              #7
              I was thinking about a simple function that will return the opposite (or negative value) of a variable. Let's call it NEG(x)

              I would use in the following way
              Variable0=ATR(20) * (1 + ATRFactor)
              Variable1=Low(0) + NEG(Variable0)

              I believe I can use the standard Offset Type in the Condition Builder to set the formulas above

              Then if I am correct this would return the same value as
              Variable1=Low(0) - ATR(20) * (1+ATRFactor)

              So I need to create the NEG indicator that takes an input (Variable0) and return the opposite (negative) of that variable.

              What I don't understand is how to create this function that uses a variable as input and returns the variable into its negative value.

              Hope this makes sense.

              Thanks

              Comment


                #8
                agosinv, that would unfortunately not be an option to create as the indicator you would create for providing this functionality would expect a series as input, a format your custom user variable could not provide. I think best would be creating / calculating the complete needed value in a custom indicator and then referencing in your wizard script.

                Comment


                  #9
                  Originally posted by agosinv View Post
                  I was thinking about a simple function that will return the opposite (or negative value) of a variable. Let's call it NEG(x)

                  I would use in the following way
                  Variable0=ATR(20) * (1 + ATRFactor)
                  Variable1=Low(0) + NEG(Variable0)

                  I believe I can use the standard Offset Type in the Condition Builder to set the formulas above

                  Then if I am correct this would return the same value as
                  Variable1=Low(0) - ATR(20) * (1+ATRFactor)

                  So I need to create the NEG indicator that takes an input (Variable0) and return the opposite (negative) of that variable.

                  What I don't understand is how to create this function that uses a variable as input and returns the variable into its negative value.

                  Hope this makes sense.

                  Thanks
                  Sounds like a "Rube Goldberg Machine". If you want to subtract a value, why not just subtract a value? Coding an indicator to negate a value, while doable, seems like using a sledge-hammer to kill a mosquito.

                  Comment


                    #10
                    Originally posted by koganam View Post
                    Sounds like a "Rube Goldberg Machine". If you want to subtract a value, why not just subtract a value? Coding an indicator to negate a value, while doable, seems like using a sledge-hammer to kill a mosquito.
                    I agree but I did not find a way to perform a simple subtraction using the wizard. However I was able to "trick" the system using a negative ATRFactor.

                    If I set my ATRFactor user variable to be be less than -2 and I use the percent Offset Type in the Condition Builder this will allow me to perform a "simple" subtraction.

                    Just a very complicated way just because I am still tied to the wizard in my strategy development.

                    Sooner or later I will unlock the code and ..... fly

                    Thanks

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    673 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    379 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    111 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    577 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    582 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X