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

Using 'price' and borrowing existing code

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

    Using 'price' and borrowing existing code

    1) I would like to use price in a custom indicator.
    When I write 'price' under the editor and compile I get this error: " The name 'price' does not exist in the current context ".
    Knowing that NT6 comes with a "PriceAlert" indicator, I replace 'price' with 'PriceAlert.Price' which yieds to that error: " 'NinjaTrader.Indicator.Indicator.PriceAlert(double , bool)' is a 'method', which is not valid in the given context ".
    So what should I do to use 'price' ?

    2) Are properties, methods and classes embedded in provided NinjaScripts available to end users ? If yes, how can I copy a chunk of that code and insert it in my custom indicators ?

    #2
    1) What do you mean by use 'price'? Do you mean accessing OHLC data?

    2) Open any script, highlight a selection of code, right click copy, then paste it into any script you are working on. Keep in mind, direct copy of code may not always be copied in a compileable state. You need to make sure you copy all required code or ammend variables that may be used in the copied code that is local to the file it was copied from.
    RayNinjaTrader Customer Service

    Comment


      #3
      No, I mean tick price at the time alert condition is fullfilled
      Here is my custom indicator :
      protected override void OnBarUpdate()
      {
      if (High[0] == MAX(High, 34)[0])
      Alert("Up"...);
      else if (Low[0] == MIN(Low, 34)[0])
      Alert("Dn"...);
      }

      In the AlertPrice NT indicator, I found this code :
      Alert(DateTime.Now.Millisecond.ToString(), NinjaTrader.Cbi.Priority.Medium, "Price level '" + Price + "' hit!", Cbi.Core.InstallDir + @"\sounds\Alert4.wav", 0, Color.Yellow, Color.Black);

      and I want to use it instead of my 'Up & Dn Alerts' but when I paste it over my own lines of code, the 'Price' name begets compilation errors.

      Comment


        #4
        Thanks for the clarification.

        This is because "Price" refers to a property/variable that is local to that indicator. Its not an available property of the indicator class itself.

        Since you only want the price, do this:

        Alert(DateTime.Now.Millisecond.ToString(), NinjaTrader.Cbi.Priority.Medium, "Price level '" + Close[0] + "' hit!", Cbi.Core.InstallDir + @"\sounds\Alert4.wav", 0, Color.Yellow, Color.Black);
        RayNinjaTrader Customer Service

        Comment


          #5
          I am not sure I was crystal clear; what I am looking for is the Last Price which would appear in a Market Analyzer window.
          How can I use that Last Price in my custom indicator ?

          Comment


            #6
            Yes you were crystal clear.

            Close[0] is the the most recent price provide you have the indicator's CalculateOnBarClose property set to false so it updated on each incoming tick.
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            238 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            383 views
            1 like
            Last Post Gavini
            by Gavini
             
            Started by oviejo, Today, 12:28 AM
            0 responses
            1 view
            0 likes
            Last Post oviejo
            by oviejo
             
            Started by pechtri, 06-22-2023, 02:31 AM
            10 responses
            125 views
            0 likes
            Last Post Leeroy_Jenkins  
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Working...
            X