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

issue with Andrew Pitchfork indicator when drawn from an indicator

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

    issue with Andrew Pitchfork indicator when drawn from an indicator

    Hello,

    There is an issue with the Andrew Pitchfork indicator when drawn from an indicator:
    when the Graphic object is manually modified by the user, the start point of the pitchfork gets wrong coordinates.

    I created a demo indicator and a video showing this behavior.
    The object is re-drawn by the indicator every 20 bars, with new anchors.
    After the user interferes, and modifies the start point of the pitchfork, the start point gets totally wrong values (both bar# and timestamp).
    Please find the code and the video at


    Thank you.

    #2
    Hello utilizator,

    I took a look at the script however there are quite a few undocumented concepts here so the outcome being observed may be expected.

    The main issue I see is that you are setting DrawnOnBar, this is reserved for script drawn objects and is documented that it cannot be used with manually modified objects. Although you initially submit the object with NinjaScript, you then manually modify it which is not expected for a script drawn object. You could try using the help guides suggestion there and use SlotIndex for this use however I am unsure if that will be part of the solution, this is something you can test.

    What specifically is the goal of this sample, are you trying to allow a user to modify script drawn objects and then read the values?

    Generally a NinjaScript initialed drawing object would not be expected to be manually modified after they had been drawn, instead the script would control it further by calling its Draw. syntax again to update it. You can technically use the exposed drawing object properties from this context to read its values, however this is not a documented use to set them like this. You may be able to instead detect changes in the values of the existing object and then call Draw.AndrewsPitchfork again with new values to redraw it.

    I look forward to being of further assistance.






    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,
      Thank you for your reply.

      Q1: What specifically is the goal of this sample, are you trying to allow a user to modify script drawn objects and then read the values?
      A1: Correct. However, they have unexpected values after the user manually modified the object, as we can see from the output text. How can I get the correct ones, those actually present on chart?

      Q2: You may be able to instead detect changes in the values of the existing object and then call Draw.AndrewsPitchfork again with new values to redraw it.
      A:2 I am detecting the changes, but they are erroneous, they cannot be used to correctly redraw the object. The script actually re-draws the object, with all new values for anchors, every 20 bars. Despite the fact the anchors are new (different from those manually modified), the object is still using wrong anchors. This beaviour can be observed when running the script (on a 1-tick chart).

      Q3: DrawnOnBar is reserved for script drawn objects and is documented that it cannot be used with manually modified objects.
      A3: What other property can I use? The property .Time is not accurate enough, as several bars have the same timestamp...

      Any further assistance would be much appreciated. Thank you.

      Comment


        #4
        Hello utilizator,

        Q1: What specifically is the goal of this sample, are you trying to allow a user to modify script drawn objects and then read the values?
        A1: Correct. However, they have unexpected values after the user manually modified the object, as we can see from the output text. How can I get the correct ones, those actually present on chart?
        From the property used, you likely won't be able to. The comment in the help guide applies to this situation as well, so you will need to use the SlotIndex as noted in the help guide if it will be manually modified at any point. I can see that the SlotIndex does retain a value after being moved so you an experiment there. The other items you have displayed in the sample like setting the properties directly also would not be suggested, if you need to redraw the object you should instead just call Draw method again with new values. Additionally creating the new instance as a default for your variable or creating the object outside of OnBarUpdate would not be recommended. You can just check if the object variable is null and create it if so on the first run of your code.



        Q3: DrawnOnBar is reserved for script drawn objects and is documented that it cannot be used with manually modified objects.
        A3: What other property can I use? The property .Time is not accurate enough, as several bars have the same timestamp...
        The help guide shows to use SlotIndex in the comment from that page:
        Note: This value will NOT work on manually drawn objects. This property is reserved for chart anchors which were drawn by another NinjaScript object (e.g, using a Draw method in an indicator). For manually drawn objects, please see the SlotIndex property
        Very likely the solution is to just use SlotIndex, however as I already noted you are showing quite a few items that may not work as expected, I would suggest to make a much more simple test using a Dot and remove all the other calculations/setting specific properties that you have. Here is a very simple example of a good way to test this further and also the correct way to re draw the object later:

        Code:
        Dot dot;
        protected override void OnBarUpdate()
        {
        
            if (State == State.Realtime && dot == null)
            {
                dot = Draw.Dot(this, "test", true, 0, Close[0], Brushes.Red);
                dot.IsLocked = false;
            } else if(State == State.Realtime && dot != null)
            {
                Print("Start Bar:" + dot.Anchor.SlotIndex + " CurrentBar " + CurrentBar);
            }
        
            // or later
            if(someCondition)
            {
                dot = Draw.Dot(this, "test", true, 5, Close[5], Brushes.Blue); // just call the Draw. syntax again with the newer values, this is the only way we suggest modifying an object to update it.
                dot.IsLocked = false;
            }
        }


        I look forward to being of further assistance.
        Last edited by NinjaTrader_Jesse; 09-18-2019, 07:25 AM. Reason: updated after getting clarification of help guide note
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Max238, Today, 01:28 AM
        5 responses
        42 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by giulyko00, Yesterday, 12:03 PM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by habeebft, Today, 07:27 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by AveryFlynn, Today, 04:57 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by r68cervera, Today, 05:29 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X