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

trying to compare two lines and delete one of them

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

    trying to compare two lines and delete one of them

    I'm trying to translate some code from NT7 to NT8. The NT7 codes works flawless deleting lines with same origin and price on two successive bars. The NT8 code doesn't.
    Any ideas?

    NT7
    Code:
                if (FirstTickOfBar)
                {
                    if (DrawObjects["BT_Swing_High"+(CurrentBar-2)] != null && DrawObjects["BT_Swing_High"+(CurrentBar-1)] != null)
                    {
                        ILine BT_Swing_High1 = (ILine)DrawObjects["BT_Swing_High"+(CurrentBar-1)];
                        ILine BT_Swing_High2 = (ILine)DrawObjects["BT_Swing_High"+(CurrentBar-2)];
    
                        if (BT_Swing_High1 != null && BT_Swing_High2 != null &&
                            BT_Swing_High1.StartBarsAgo == BT_Swing_High2.StartBarsAgo && BT_Swing_High1.EndY == BT_Swing_High2.EndY)
                            RemoveDrawObject("BT_Swing_High"+(CurrentBar-2));
                    }

    NT8
    Code:
                if (IsFirstTickOfBar)
                {
                    if (DrawObjects["BT_Swing_High"+(CurrentBar-2)] != null && DrawObjects["BT_Swing_High"+(CurrentBar-1)] != null)
                    {
                        NinjaTrader.NinjaScript.DrawingTools.Line BT_Swing_High1 = (NinjaTrader.NinjaScript.DrawingTools.Line)DrawObjects["BT_Swing_High"+(CurrentBar-1)];
                        NinjaTrader.NinjaScript.DrawingTools.Line BT_Swing_High2 = (NinjaTrader.NinjaScript.DrawingTools.Line)DrawObjects["BT_Swing_High"+(CurrentBar-2)];
    
                        if (BT_Swing_High1 != null && BT_Swing_High2 != null &&
                            BT_Swing_High1.StartAnchor.BarsAgo == BT_Swing_High2.StartAnchor.BarsAgo &&
                            BT_Swing_High1.StartAnchor.Price   == BT_Swing_High2.StartAnchor.Price)
                            RemoveDrawObject("BT_Swing_High"+(CurrentBar-2));
                    }
    Last edited by td_910; 03-11-2019, 02:16 PM.

    #2
    Hello td_910,

    Thank you for your question.

    Just looking at the syntax it seems you have done a good job of making the conversion I can't see any notable differences here.

    Have you at this point tried using a Print in both the NT7 and NT8 scripts for this region of syntax and then compared the output? That may give some insight about what is different here.

    I would likely suggest starting off with the outer conditions to make sure they are happening the same, for example:

    Code:
    Print(Time[0] + " " + FirstTickOfBar);
    if (FirstTickOfBar)
    {
    compared against:

    Code:
    Print(Time[0] + " " + IsFirstTickOfBar);
    if (IsFirstTickOfBar)
    {
    You could do this for each condition or value used to see where they begin to deviate. Printing the time lets you compare 1:1 with the other script to see on each bar how it evaluated. This test will help point a better direction for troubleshooting this further.



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

    Comment


      #3
      I added a couple of prints:

      Code:
                  if (IsFirstTickOfBar)
                  {
                      if (DrawObjects["BT_Swing_High"+(CurrentBar-2)] != null && DrawObjects["BT_Swing_High"+(CurrentBar-1)] != null)
                      {
      Print(Time[0] + " " + IsFirstTickOfBar);
      
                          NinjaTrader.NinjaScript.DrawingTools.Line BT_Swing_High1 = (NinjaTrader.NinjaScript.DrawingTools.Line)DrawObjects["BT_Swing_High"+(CurrentBar-1)];
                          NinjaTrader.NinjaScript.DrawingTools.Line BT_Swing_High2 = (NinjaTrader.NinjaScript.DrawingTools.Line)DrawObjects["BT_Swing_High"+(CurrentBar-2)];
      
      Print(Time[0] + " " + BT_Swing_High1.StartAnchor.BarsAgo + " " + BT_Swing_High1.StartAnchor.Price);
      Print(Time[0] + " " + BT_Swing_High2.StartAnchor.BarsAgo + " " + BT_Swing_High2.StartAnchor.Price);
      
                          if (BT_Swing_High1 != null && BT_Swing_High2 != null &&
                              BT_Swing_High1.StartAnchor.BarsAgo == BT_Swing_High2.StartAnchor.BarsAgo &&
                              BT_Swing_High1.StartAnchor.Price   == BT_Swing_High2.StartAnchor.Price)
                              RemoveDrawObject("BT_Swing_High"+(CurrentBar-2));
                      }
      this is the output:

      11/03/2019 18:35:00 True
      11/03/2019 18:35:00 16 2782.75
      11/03/2019 18:35:00 15 2782.75
      11/03/2019 19:00:00 True
      11/03/2019 19:00:00 21 2782.75
      11/03/2019 19:00:00 20 2782.75
      11/03/2019 19:25:00 True
      11/03/2019 19:25:00 26 2782.75
      11/03/2019 19:25:00 25 2782.75

      It seems, that BarsAgo is calculated from the end of the actual line that was drawn to the startpoint!!!
      and not like in NT7 from the current bar to the startpoint

      I don't know, if that is a feature or a bug, as there is no property of a chart anchor holding that value
      in my case the workaround is easy, as I enumerate the chart objects myself, but in other cases...

      Comment


        #4
        Hello td_910,

        Thank you for your reply.

        Yes, in this case, it looks like this is likely a difference between the drawing objects and how they work between platforms. The drawing objects were rebuilt in NT8 so we will see some differences surrounding the tools.

        One specific difference here would be that the Anchors BarsAgo property is not expected to contain a value in all use cases. Manually drawn objects will not contain a value here. The BarsAgo reported is also static for programmatically drawn objects, this will stay the value it was defined as originally. If you used 10 BarsAgo, it would report 10.

        You may be able to use something like the following to get the moving BarsAgo from the current bar instead of the static BarsAgo:

        Code:
        Print(Count - (Calculate == Calculate.OnBarClose ? 2 : 1) - ChartBars.GetBarIdxByTime(ChartControl, test.StartAnchor.Time));
        or
        Print(CurrentBar - ChartBars.GetBarIdxByTime(ChartControl, rec.StartAnchor.Time));



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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        3 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        6 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Working...
        X