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

Prroblem with DrawObjects

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

    Prroblem with DrawObjects

    Helllo,

    I have an indicator that write some number near a specially pattern found. (it is a 123 joe ross indicator). when using this indicator alone it works with no problem.
    When I call this indicator in a strategy I found problem with DrawObjects.

    for example: (this is a part of the indicator with problem)
    // recolor markers if its failed target
    if (upMarkers[pos].lock123 == 2)
    {
    Text text;
    //Print("before");
    text = (Text)DrawObjects["123Up1," +upMarkers[pos].dateTime[0]];

    if ( text == null) Print("text null 123Up1 upMarkers[pos].dateTime[0] =" +upMarkers[pos].dateTime[0]);
    text.TextBrush = failUpColor;
    ...

    text is always null in strategy.

    this is another part using DrawObjects:

    IDrawingTool drawObject;
    int pos;

    DateTime obTime = DateTime.Parse(obName.Substring(7));
    pos = CurrentBar - Bars.GetBar(obTime);

    if (obInSet(obName, "B"))
    {
    /// move markers in bottom pos
    yp = Low[pos] - textOffset;

    tstr = "123Dp2," + obName.Substring(7);
    drawObject = DrawObjects[tstr];
    i]f (drawObject != null && drawObject is DrawingTools.Text)[/B]
    {

    Text text = (Text)drawObject;
    text.YPixelOffset = (int)yp;
    yp -= textOffset;
    }

    How can I resolve?
    Thanks.

    #2
    Hello,

    Thank you for the post.

    If I have understood correctly you are checking the DrawObjects collection from an indicator, and are checking for a second indicators objects. Is this correct?

    If so I would think this would be expected if called from a strategy as the strategy is Hosting the indicator. In this case the indicator does not have a chart associated with it and is just calculating data. I will need to verify if this would be expected that the collection is empty in this case so I will reply back once I have clarified that further.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello,

      I am using the indicator in a strategy. The indicator have not a chart associated with it but calculate data. I would like to display also the text of the indicator in the strategy. (text is output of the indicator)
      If can be useful I can send to you the file as example.

      Thanks for your time.

      Comment


        #4
        Hello,

        You can add indicators from a strategy to be visual using AddChartIndicator(), http://ninjatrader.com/support/helpG...chartindicator

        Are you still seeing problems after adding this syntax?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello,

          Adding the indicator with AddChartIndicator() in State Configure, the strategy can be compiled without error, but after using it, in the ninjascript output window there is the following error:

          Strategy 'Ross123HSrat': Error on calling 'OnStateChange' method: 'AddChartIndicator' cannot be called from this state. Please see the Help Guide article on 'AddChartIndicator' for more information.

          Comment


            #6
            Hello,

            Are you certain you have added it to State.Configure and not just the OnStateChange method? The error message would only be displayed if that method was called when the state was not State.Configure. Can you confirm your script looks like the sample in the help guide article?

            Also had you removed the strategy from where you had it applied after compiling and re added it? Potentially just reloading the script would fail because it was not re added after a change to OnStateChange.

            If you are still having trouble, could you provide the script for me to review? I can see using the help guide sample that does work on my end.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello,

              Yes, I added it in State.Configure. This is the only indicator that create problem.
              I send to you the full version of the indicator and a strategy using it.
              The indicator is RossHook123 (this is my conversion to ninja 8 from ninja 7 with some bug fixes. It uses MAXEG, MINEG porting of MIN MAX indicator for compatibility ninja 7).
              Ross123HSrat is a starting point of the strategy using the indicator, but with problem discussed before.

              Thanks
              Attached Files

              Comment


                #8
                Hello,

                Thank you for the script.

                As a test please try using the SMA in the strategy and remove/add the script to the chart. You should see that the error resolves, this would indicate a problem in your indicator.

                In the log I see in addition to the error you had provided the following:

                Indicator 'RossHook123': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
                Some object being used is null at the time of it being accessed in the script and preventing it from loading.

                I would suggest to also remove the try/catch statements you are using in the indicator and address any exceptions the indicator is having. I do see that when I run the indicator by its self it generated a memory leak and I had to terminate the instance of the platform. Before addressing this I would not suggest to continue testing it with the strategy as it will likely cause problems in the current state.

                Because the file is quite large, I would suggest to debug/reduce the code in the indicator to locate the problems. The extra error in the log seems to be a consequence of the indicator failing when it is being added by the strategy.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello,

                  Thanks for you answer. Using the indicator alone in my computer there isn't any memory leak and the indicator work fine. Also there isn't any error in output window.
                  I will do other extra debug.
                  For the first question about DrawObjects have you found something?

                  Thanks

                  Comment


                    #10
                    Hello,

                    Thank you for the reply.

                    In regard to the original question, I am unable to test the indicator further as it will not run for me but the resolution to finding the objects is AddChartIndicator. The roadblock is that the indicator being called would also need to not throw an exception when run.

                    If the indicator is added to the chart it would have access to the chart and its objects, if it is not added to the chart it would only be able to calculate data based on its input series. AddChartIndicator() would add an instance of the object to the chart to be visible and it would also see drawing objects in the collection.

                    To address the code you had provided. I would suggest to create a new indicator and place only the drawing object code in that indicator. You could use that empty indicator to isolate the code and figure out what may be happening in more detail. You would need to update the strategy to call the testing indicator instead but then you could see a result and work from there.

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Hello,

                      I found the problem with the indicator. The problem is this line called in OnStateChange() State.Configure).
                      textOffset = offset * Instrument.MasterInstrument.TickSize;
                      Instrument.MasterInstrument.TickSize works with indicator alone, but when the indicator is used in a strategy return null causing exception.
                      Actually this is not so important for me, now I replaced TickSize by a costant and works well.
                      In converting the indicator from Ninja 7 to 8 I noticed that using the same instrument and same indicator sometime the value of Open Low High Close can be read a bit differently. Probably is not a problem, but can be produced a diffferent output
                      for example:
                      Ninja 7: Low read 5.33
                      Ninja 8: Low read 5.325
                      I tried to use math.round function to but with no success.
                      Thanks

                      Comment


                        #12
                        Hello,

                        Can you tell me, when you see this difference are you simply printing the Series value or is this a calculated value you are setting in the script?

                        for example, can you see printing just the series the same result? :

                        Print(High[0]);

                        If so, can you provide information on the instrument used, dataseries settings and what connection you are using? I would like to see this as well to understand if this would be expected.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Hello,

                          Yes the difference can be verified just printing High[position], Low[position]....
                          I used Yahoo connection with unicredit bank as instrument.
                          In the attachment you can find setting of the instrument used.

                          Thanks
                          Attached Files

                          Comment


                            #14
                            Hello,

                            Thank you for that detail.

                            I am able to see this as well, I see the same TickSize being used on my end and see this difference. I am not certain if this would be expected so I will need to research this further.

                            Once I have further details I will reply back.

                            I look forward to being of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Perr0Grande, Today, 08:16 PM
                            0 responses
                            2 views
                            0 likes
                            Last Post Perr0Grande  
                            Started by elderan, Today, 08:03 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post elderan
                            by elderan
                             
                            Started by algospoke, Today, 06:40 PM
                            0 responses
                            10 views
                            0 likes
                            Last Post algospoke  
                            Started by maybeimnotrader, Today, 05:46 PM
                            0 responses
                            12 views
                            0 likes
                            Last Post maybeimnotrader  
                            Started by quantismo, Today, 05:13 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post quantismo  
                            Working...
                            X