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

Calling strategy from indicator

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

    Calling strategy from indicator

    Hi all,

    I'd like to know if there is a chance to pass information from an indicator to a strategy.
    Let's say I've an indicator where an entry level is calculated or showed (e.g. a drawing horizontal line on the chart) and I want to translate this in an order (clicking a button or clicking the mouse) on a strategy that has been previously created to be called from the indicator itself.

    Is that possible?

    If yes could you please provide me an example?

    Thanks.

    #2
    MAX,

    Strategies can already use indicators. The only thing it sounds like you would need to change is to create a public dataseries in your indicator that the strategy can access, and assign the entry level calculation to this data series.

    Thankfully we have a handy reference sample to show you how to do that here : http://www.ninjatrader.com/support/f...ead.php?t=4991
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks.

      I know this.

      What I need is something like having an indicator where, for example, I draw a parallel line on the chart, corresponding to a particular price, and send an order (stop, limit, whatever), through a strategy.

      I cannot use directly a strategy because I cannot draw objects. Is something to use discretionary and not automated, but I need indicator to draw and strategy to send orders.

      The alternative could be to use ATM with an indicator, but I think this can't be done.

      Hope this clarifiy.

      Comment


        #4
        Originally posted by MAX View Post
        Hi all,

        I'd like to know if there is a chance to pass information from an indicator to a strategy.
        Let's say I've an indicator where an entry level is calculated or showed (e.g. a drawing horizontal line on the chart) and I want to translate this in an order (clicking a button or clicking the mouse) on a strategy that has been previously created to be called from the indicator itself.

        Is that possible?

        If yes could you please provide me an example?

        Thanks.
        In your Strategy put this code:

        public class TradeManagerGlobal {
        public static string command = "";
        }
        ...
        if ( TradeManagerGlobal.command.Contains("BuyLimit")) ) {
        ... Parse the string
        ... Execute commands
        TradeManagerGlobal.command=""; // Clear the command
        }

        In your Indicator put this code:

        TradeManagerGlobal.command = "BuyLimit 92.40 ";

        Comment


          #5
          Thanks monpere, I will look over your code.

          Comment


            #6
            Hi monpere,

            which code must be inserted when you write:

            ...Parse the string
            ... Execute commands

            ?

            Thanks.

            Comment


              #7
              Originally posted by MAX View Post
              Hi monpere,

              which code must be inserted when you write:

              ...Parse the string
              ... Execute commands

              ?

              Thanks.
              'Parse the string', would be your customized code to get the limit price of '92.40' into a variable 'entryPrice' for instance.

              'Execute commands' would be your entry order code like: EnterLongLimit (entryPrice);

              etc.

              Comment


                #8
                You mean you need to "unpack" the string from the command in order to get the entry price 92.40?

                Comment


                  #9
                  That was just an example, you can put anything you want in the string from the indicator side, and parse that data out from the strategy side. If you don't want to do string parsing, just change the structure to what you want, for example:

                  public class TradeManagerGlobal {
                  public static string orderCommand;
                  public static int quantity;
                  public static double limitPrice;
                  public static double stopPrice;
                  public static double trailPrice;
                  //...etc.
                  }

                  Comment


                    #10
                    Thanks.

                    So, in this last example you shouldn't use a string command in the indicator but, instead, split each information as variable and match those variables in the strategy?

                    Is that correct?

                    Comment


                      #11
                      Originally posted by MAX View Post
                      Thanks.

                      So, in this last example you shouldn't use a string command in the indicator but, instead, split each information as variable and match those variables in the strategy?

                      Is that correct?
                      That is correct.

                      Comment


                        #12
                        monpere, I put the code
                        Code:
                        if ( TradeManagerGlobal.command.Contains("BuyLimit")) ) {
                        ... Parse the string
                        ... Execute commands
                        TradeManagerGlobal.command=""; // Clear the command
                        }
                        in the strategy on the OnBarUpdate.

                        Order is submitted, but is cancelled as soon as the next bar comes out.

                        Am I missing something?

                        Thanks

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by George21, Today, 10:07 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post George21  
                        Started by Stanfillirenfro, Today, 07:23 AM
                        8 responses
                        23 views
                        0 likes
                        Last Post Stanfillirenfro  
                        Started by DayTradingDEMON, Today, 09:28 AM
                        2 responses
                        16 views
                        0 likes
                        Last Post DayTradingDEMON  
                        Started by navyguy06, Today, 09:28 AM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by cmtjoancolmenero, Yesterday, 03:58 PM
                        8 responses
                        32 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X