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

New to NinjaScript, input welcome

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

    New to NinjaScript, input welcome

    Hi,

    I'm new to Ninja Script and would like to program a very simple first strategy. I would like to be able to draw a trend line by hand and whenever the price comes close to this line I would like to take certain actions. For example, if the price breaches the line (price going up) I would like to submit a long order with trailing stop.

    My first question would be: how can I access the data of my hand drawn line? I would obviously need two points to make it a line.

    Thanks for any help!
    kf

    #2
    Hello kf,

    There is an indicator on the forums called LineAlert (alerts for manually drawn lines) that would be a great example for detecting lines.

    LineAlert - http://ninjatrader.com/support/forum...php?linkid=472

    In your strategy, once the price crossing the line is detected, you can submit an order instead of triggering an alert.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hey Chelsea,

      thank you so much! I will have a look into it.

      kf

      Comment


        #4
        Okay, so far I understand the code. Now, when I'm adding code like this
        Code:
        EnterLong(1)
        the compiler tells me that this method is not known in the current context. Can't I submit orders out of an indicator? Or do I need to include something else? I tried
        Code:
        using NinjaTrader.Strategy;
        which doesn't change anything.

        Comment


          #5
          Hello kf1234,

          No, indicators are not designed to place orders. You will need to make a strategy.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Okay, I understand.
            But how do I access the indicator that I've drawn by hand in my strategy code?
            I've had a look at the MACrossOver example. In this example two indicators are added programatically and thus easy to access. In my case I don't think I could just define a variable like this
            Code:
            LineAlert la1;
            , configure it and later do
            Code:
            Add(sa1);
            . Or can I? I'm missing the connection to my hand drawn line here.

            Comment


              #7
              Hello kf1234,

              If you want the strategy to detect the line and place the order, the code should be added to the strategy directly instead of to an indicator that is called from the strategy.

              That said, to directly answer your question, you can use a variable if you want.

              In #region Variables
              private SMA mySMA;

              In Initialize():
              mySMA = SMA(14);
              Add(mySMA);

              In OnBarUpdate:
              Print(mySMA[0]);

              That said, this would add a layer of complexity to your script that is not necessary. This would require that the indicator detect the cross, set a plot once the cross is detected, then the next time the strategy updates it reads the value of the plot and then places an order.

              Instead I would be simpler to add the code that detects the cross directly to the strategy.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,605 views
              0 likes
              Last Post aligator  
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              8 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              4 views
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              13 views
              0 likes
              Last Post Javierw.ok  
              Working...
              X