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

Rectangle drawing with extended line on right and Price level

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

    #31
    Hello asmmbillah,

    If you are using NinjaTrader.Core.Globals.UserDataDir, this would be the Documents\NinjaTrader 8\ folder.

    If that folder doesn't already exist then NinjaTrader 8 should not be able to launch at all.

    Is NinjaTrader able to launch?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #32
      thanks following your suggstion, I have fixed it.

      the issue now, is I want the indicator to read the file written only when it loads. but now it is trying to write and read at the same time and giving error. Any suggestion on that?

      For plotting after indicator load, should it read each line or each words saved in the file to properly plot multiple recatngles. an example will be really very helpful.

      thanks in advance.

      Comment


        #33
        Hello asmmbillah,

        NinjaTrader triggers OnStateChange with State.DataLoaded once when the script loads.

        Unfortunately, I don't have any examples of this kind of advanced custom logic for the custom actions you are wanting.
        Indicators are meant to draw objects based on data and are not meant to be drawn based on what was previously drawn..

        We do have examples of writing to file and reading from file. However, saving drawing objects drawn by an indicator is outside of the design scope of what indicators are meant to do.

        This is going to need custom developed logic to achieve.

        The read from file example demonstrates reading from a file, and looping over each line in the file. On each line I'm expecting you've saved the information for each drawing object. My suggestion would be to wait for the last historical bar, then draw all the objects based on the bars ago value saved with the price of each anchor.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #34
          Thanks a lot.

          is it possible to identify a bar plotted time ie, time stamp of a bar on chart with barindex number?

          and if I want to draw a rectangle with below syntex:

          Draw.Rectangle(NinjaScriptBase owner, string tag, bool isAutoScale, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, Brush areaBrush, int areaOpacity)

          what shoud be the format of startTime please? do I need to use date and time? please advise. thanks
          Last edited by asmmbillah; 09-10-2019, 11:27 AM.

          Comment


            #35
            Hello asmmbillah,

            Yes (and thinking about it, that would be necessary).

            The drawing object anchors will already have a bar time which should be what is saved.
            (Just a heads up, the .barsAgo property is the original value supplied to the Draw method and does not continue to update to a current barsago value. This can't be used for finding the original bar an object was drawn on)

            The time from a barsAgo value would be Time[barsAgo]
            The time from a barIndex would be Time[CurrentBar - barIndex]
            The barIndex from a time would be Bars.GetBar(time)
            The barsAgo from a time would be CurrentBar - Bars.GetBar(time)
            Last edited by NinjaTrader_ChelseaB; 09-11-2019, 07:22 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #36
              Hi Thanks for your reply and info. That's what I needed.

              But if I wanted to draw Rectangle on historical data where end and start time is in 18/07/2019 10:00:00 and 16/07/2019 04:17:17 format for endTime and startTime. is it possible to draw in NT8?

              if yes, any suggestion?
              if no, any alternative?

              thanks in advance.

              Comment


                #37
                Hello asmmbillah,

                You would need to take those values and make them DateTime objects to supply to the Draw method.

                Below is a public link to a 3rd party educational site on DateTime.Parse().
                Handle strings containing dates with DateTime.Parse. Convert a string to a DateTime.


                As well as a public link to the Microsoft documentation.


                Then supply those as the startTime and endTime parameters to Draw.Rectangle().

                Draw.Rectangle(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush)
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #38
                  Thanks a lot.

                  I am trying to call SreamReader() method within state.Tranistion and calling to write within OnMarketData() method. I am getting the error message that it is trying to read and write the same file at the same time. I do get it. But so far I read in ref guide for NT8 that state.Transition will execute before the market data starts executing (so far I remember, I may be wrong). I have tried several sets of combination of sr.Close() and sw.Close(); it is not working. Any suggestion on how to tackle this problem. I just want to script to read it first, then close reading and write if needed.

                  thanks in advance.

                  Comment


                    #39
                    Hello asmmbillah,

                    Transition occurs as the script is transitioning from historical to real-time. There is very little time to open a file read it and close it before real-time data begins processing to re-open it and begin writing.

                    If you are planning to do it then, you are going to have to miss some of the market updates. You will need to wait until the file is closed.

                    Use a try and catch to prevent an error so the script continues working.

                    Code:
                    try
                    {
                        sw = File.AppendText(path);
                        sw.WriteLine(text);
                        sw.Dispose();
                        sw = null;
                    }
                    // if you cannot, then set noWrite to true and log the error
                    catch (Exception e)
                    {
                    Print("cannot write");
                    }
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #40
                      Thanks. That was very helpful.

                      If I run an indicator which renders customer shapes and if I use it on two different intruments on different tabs of a chart, will it continue executing rendering as per the logic of the indicator?

                      Comment


                        #41
                        Hello asmmbillah,

                        If IsSuspendedWhileInactive is true, the indicator will not continue processing data or rendering if the tab is not visible.

                        When false, it will.

                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by cre8able, Today, 01:01 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post cre8able  
                        Started by manitshah915, Today, 12:59 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post manitshah915  
                        Started by ursavent, Today, 12:54 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post ursavent  
                        Started by Mizzouman1, Today, 07:35 AM
                        3 responses
                        17 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by RubenCazorla, Today, 09:07 AM
                        2 responses
                        13 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X