Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variable0 = SMA

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

    Variable0 = SMA

    Hi everyone,

    When a set of conditions is true (already programmed) I would like to set a Variable0 equal to the value of a moving average and then use that value as profit target.

    Is it possible to do that with the Strategy Wizard?

    So far, I have set:

    Variable0 = SMA in Set1

    and then, in the Profit Target & Stoploss section:

    Profit Target Mode = price
    Value = Variable0

    but it doesn't work,

    thank you for your help,

    John.

    #2
    Hello John,
    Thanks for writing in and I am happy to assist you.

    You can set the value of the Variable0 to the SMA value but you cannot set it to SetStopLoss as it is defined in the Initialize region of the strategy.

    You have to unlock the code and do it via the NinjaScript editor.

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply,

      at the moment I have in the Condition Set 1:

      Variable0 = SMA(800)[0]; this is ok, if I have understood.

      While in the Initialize () section I have:

      SetProfitTarget("", CalculationMode.Ticks, Variable0); How this line should be modified to make sure that the profit target is equal to the SMA?

      thank you,

      John.

      Comment


        #4
        Hello John,
        SetProfitTarget and the SetStopLoss are put in the initialize region of the code. At that time the value of Variable0 is 0 (zero). When the orders are placed then you have to reassign the Set() methods with the updated price. Unfortunately you cannot do that via the Strategy Wized.
        You have to unlock the code and code it via the NinjaScript editor.
        You can modify your code after placing the entry order as:
        Code:
        Variable0 = SMA(800);
        SetProfitTarget("", CalculationMode.Price, Variable0);
        The above will put an appropriate profit target.

        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Hi,

          thank you for your reply,

          I have put the following code:

          Variable0 = SMA(800);
          SetProfitTarget("", CalculationMode.Price, Variable0);

          in the conditions sets (I have 4 conditions sets, so I put it in each of them). When I run the simulation what happens is that the positions are immediately closed after being opened.
          So the profit target is not appropriately set.

          What could be missed?

          thank you,

          John.

          Comment


            #6
            Hello John,
            Variable0 is a double while SMA(800) is a data series. You need to write the code as
            Code:
            Variable0 = SMA(800)[B][COLOR="Blue"][0][/COLOR][/B];
            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Hi Joydeep,

              here is the code I have inserted in the condition set:

              {
              EnterLong(DefaultQuantity, "Trend LE");
              Variable0 = SMA(800)[0];
              SetProfitTarget("", CalculationMode.Price, Variable0);
              }

              but still no success,

              what could be missing?

              thank you,

              John.

              Comment


                #8
                Hello John,
                Your fromEntrySignal name varaiable is not set accordingly in the Set() method.

                Please use this code
                Code:
                EnterLong(DefaultQuantity, "Trend LE"); 
                Variable0 = SMA(80)[0]; 
                SetProfitTarget("Trend LE", CalculationMode.Price, Variable0);
                Please let me know if I can assist you any further.
                JoydeepNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                637 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                366 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                571 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X