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

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 andrewtrades, Today, 04:57 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by chbruno, Today, 04:10 PM
                0 responses
                3 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by josh18955, 03-25-2023, 11:16 AM
                6 responses
                436 views
                0 likes
                Last Post Delerium  
                Started by FAQtrader, Today, 03:35 PM
                0 responses
                7 views
                0 likes
                Last Post FAQtrader  
                Started by rocketman7, Today, 09:41 AM
                5 responses
                19 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X