Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              576 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              553 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X