• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 alfonso, Today, 10:21 AM
        0 responses
        1 view
        0 likes
        Last Post alfonso
        by alfonso
         
        Started by saeed, Today, 10:20 AM
        1 response
        3 views
        0 likes
        Last Post saeed
        by saeed
         
        Started by ntbone, Yesterday, 05:21 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by ntbone, Yesterday, 04:05 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by tonynt, Today, 09:35 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Working...
        X