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

set the relative indicator plot value according to user choice

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

    set the relative indicator plot value according to user choice

    Hi all,

    I am still using strategy builder with the current strategy I'm trying to build but I want to add that I have nothing against using the unlocked code in NinjascriptEditor.
    I am using the Exit methods in the order management of my strategy for submitting a Stop-Loss and Take-Profit price level. Those levels both are set according to a plot value of a custom indicator.

    In my strategy set, when the condition "Position.MarketPosition=MarketPosition.Long" is true I am executing those actions to fulfill this task:

    ExitLongStopMarket(DefaultQuantity, myIndicator(Close, Convert.ToString(end.TimeOfDay)).MyLow-One[0], stoploss, "");
    ExitLongLimit(DefaultQuantity, myIndicator(Close, Convert.ToString(end.TimeOfDay)).MyHigh-One[0], @"TakeProfit", "");
    As you see this rule has a fixed StopLoss defined, it is the plot value of MyIndicator called "MyLow". The same is true for the take profit rule. Well, I have other plot values in my indicator as well. They are called "MyLow-Two", "MyLow-Three" and "MyHigh-Two" and "MyHigh-Three".

    The particular unlocked code for that set is:

    Code:
    // Set 3
    if (Position.MarketPosition == MarketPosition.Long)
     {
       ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), myIndicator.MyLow-One[0], @"StopLoss", "");
       ExitLongLimit(Convert.ToInt32(DefaultQuantity), myIndicator.MyHigh-One[0], @"TakeProfit", "");
     }
    My goal:
    is that the user should be able to choose as user input which low and high level he likes to use. For example, if the user makes the choice "Level 3" than the condition rule for the action should be:

    ExitLongStopMarket(DefaultQuantity, myIndicator(Close, Convert.ToString(end.TimeOfDay)).MyLow-Three[0], stoploss, "");
    ExitLongLimit(DefaultQuantity, myIndicator(Close, Convert.ToString(end.TimeOfDay)).MyHigh-Three[0], @"TakeProfit", "");
    how can I do this? If I *have* to unlock the code, please give me a hint where to search for for the suitable command set. Any help appreciated.

    Thank you.
    Patricia.

    Last edited by patricia70; 12-22-2020, 10:44 AM.

    #2
    Hello patricia70,

    Thanks for your post.

    A simple means in the Strategy Builder would be to create a set for each set of exits and create a user-selectable bool to which can then be used as an entry condition for the sets.


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Good idea, thank you. But when I create three bool user inputs
      UseTP1
      UseTP2
      UseTP3

      and I create a condition per each set, how can I be sure that not all selections can be active at once? There should be only TP1, TP2 or TP3 allowed to be selected. Of course I could do a condition like "If UseTP1=true and not (UseTP2=true || UseTP3)true) then ..." but I mean the user should not be able to check all those three selections in the strategy menu.

      Another additional question:

      The indicator this strategy uses, has already three booleans called
      ShowTP1
      ShowTP2
      ShowTP3
      with default set to true, so their plots are displayed.

      Is it possible somehow to pass the user selection of the strategy (UseTP1 or UseTP2 or UseTP3) to set the boolean in the according indicator? Example: When user in strategy sets UseTP2=true than this choice should be also passed to the indicator and set ShowTP1=false, ShowTP2=true and ShowTP3=false.
      Last edited by patricia70; 12-22-2020, 11:49 AM.

      Comment


        #4
        Hello patricia70,

        Thanks for your reply.

        Regarding the bools, yes that would be a limitation of the Strategy Builder. Alternately, rather than bools, you could use an int input and have the user enter a value where you can define the mIn value and the default value and use the value of int as an entry point to the sets, where 1 goes to this set, 2 goes to that set and 3 or greater go to the final set.

        A more elegant solution, in Ninjscript, would be the use of an Enum for the selection where they can only choose one. Here is a link to an example of using an enum: https://ninjatrader.com/support/help...ned_parame.htm

        Yes, you can create logic based on the user input to establish the indicator parameters.

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thank you. I will try and see how I can get this to work as desired.
          Is it possible somehow to pass the user selection of the strategy (UseTP1 or UseTP2 or UseTP3) to set the boolean in the according indicator? Example: When user in strategy sets UseTP2=true than this choice should be also passed to the indicator and set ShowTP1=false, ShowTP2=true and ShowTP3=false.
          Originally posted by NinjaTrader_PaulH View Post
          Yes, you can create logic based on the user input to establish the indicator parameters.
          how does this approach looks like?

          Comment


            #6
            Hello patricia70,

            Thanks for your reply.

            As an example, let's say the strategy wants to add an SMA() to the chart and the period is determined by the user based on some value 2 or greater and that you want to multiply that times 5.
            The times 5 occurs after the user has completed their input selection.

            IsInstantiatedOnEachOptimizationIteration = true;
            Selector = 2;
            }
            else if (State == State.DataLoaded)
            {
            AddChartIndicator(SMA(Selector * 5)); // apply SMA at 5 * selector value
            }
            }

            protected override void OnBarUpdate()
            {
            }

            #region Properties
            [NinjaScriptProperty]
            [Range(2, int.MaxValue)]
            [Display(Name="Selector", Description="This value times 3 creates period for SMA", Order=1, GroupName="Parameters")]
            public int Selector
            { get; set; }
            #endregion


            The property "Selector" will contain the user selection (or 2 if they do not select anything)
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi Paul. So far understood, thank you. Certainly I asked wrong, I actually wanted to know: staying in your example, if I already use the "indicator" SMA and use 25 as a value in my chart, can I somehow make the strategy read out the SMA value from the indicator and use it? without the need to ask the user again which value to use. Simply said: I want to use the value of the indicator in use. Or is that not supported at all?

              Comment


                #8
                Hello patricia70,

                Thanks for your reply.

                If I understand correctly, the situation you are looking for is the user has an existing indicator on the chart and when you apply your strategy to the chart you want it (the strategy) to adopt the indicator and its settings?

                If my understanding is correct, the answer would be no.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for clarification Paul.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Javierw.ok  
                  Started by timmbbo, Today, 08:59 AM
                  2 responses
                  10 views
                  0 likes
                  Last Post bltdavid  
                  Started by alifarahani, Today, 09:40 AM
                  6 responses
                  41 views
                  0 likes
                  Last Post alifarahani  
                  Started by Waxavi, Today, 02:10 AM
                  1 response
                  19 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Working...
                  X