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

Lines are listed in Drawing Objects list but not showing on chart

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

    Lines are listed in Drawing Objects list but not showing on chart

    I making an indicator that draws lines at swing highs. If it finds equal highs, the lines are drawn in a different color to show that there is more than 1 high at that point

    I find a swing high
    I check to see if it is the first swing high at that price
    If it is, I look back to see if there is an equal high that isn't a swing high. If I find one, I draw a line from the equal high to the swing high. Then start a new line at that price that is a different color

    if it's not the first swing high at that level, I draw a line from the last swing high to the current one, then start a new line at that price that is a different color

    In the top image you can see that there are 2 lines that are in the Drawing Object list that didn't draw on the chart. But when I click on a line to bring up the Drawing Object list, then close the box, the lines show up. That's the bottom image

    My code is below
    What am I doing wrong?


    Click image for larger version

Name:	image.png
Views:	53
Size:	193.5 KB
ID:	1296976

    Click image for larger version

Name:	image.png
Views:	36
Size:	176.1 KB
ID:	1296977

    PHP Code:
            protected override void OnBarUpdate()
            {
                if (
    CurrentBar 2)    return;        
                
                if(
    CurrentBar == 3)
                    
    startTime DateTime.Now.Ticks;
                                        
                if ((
    High[1] >= High[0]) && (High[1] >= High[2]))                        //    FOUND SWING HIGH
                
    {
                    
    AddSwingHigh();
                }

                if (
    swingHighs.Count 0)                                                //    GO THRU LIST AND DRAW ANY OPEN SWING HIGH LINES
                    
    for (swingHighs.Count 1>= x--)                        
                    {
                                            
                        
    DrawSwingHighs(
                            
    swingHighs[x].swingHLValue,
                            
    swingHighs[x].swingHLStartTime,
                            
    Time[0],
                            
    swingHighs[x].eqhlCount);

                        if(
    High[0] > swingHighs[x].swingHLValue)                        //    CHECK FOR END OF SWING HIGH
                        
    {                                    
                            
    swingHighs.RemoveAt(x);                                         // REMOVE SWING HIGH FROM LIST
                        
    }    
                    }

                if (
    Count == CurrentBar)
                {
                    
    DrawTextBox1();
                    Print(
    "IFVGComboTest  " + (DateTime.Now.Ticks startTime)/10000);    //    PRINT INDICATOR LOAD TIME
                
    }
            }
    //==================================================================================================    
    //==================================================================================================
            

    //==================================================================================================    
            
    private void AddSwingHigh()
            {
                    if (
    swingHighs.Count(=> a.swingHLValue == High[1]) == 0)        //    FOUND NEW SWING HIGH
                    
    {

                        
    CheckBackForEqualHigh();                                    //    CHECK BACK TO SEE IF PRIOR EQUAL HIGHS

                        
    swingHL v = new swingHL();
                        
    v.eqhlCount eqhlCount 1;    
                        
    v.swingHLStartTime Time[1];
                        
    v.swingHLEndTime Time[0];
                        
    v.swingHLValue High[1];
                        
    swingHighs.Add(v);                                            //    ADD NEW SWING HIGH TO LIST

                        
    swingHighs.Sort((yx) => x.swingHLStartTime.CompareTo(y.swingHLStartTime));            
                    }
                    else                                                            
    //    FOUND ADDITIONAL SWING HIGH
                    
    {
                        
    int x swingHighs.FindIndex(=> a.swingHLValue == High[1]);    
                                            
                        
    DrawSwingHighs(swingHighs[x].swingHLValue,                    //    DRAW SWING HIGH FROM PRIOR SWING HIGH TO CURRENT SWING HIGH
                            
    swingHighs[x].swingHLStartTime,
                            
    Time[1],
                            
    swingHighs[x].eqhlCount);            

                        
    swingHighs[x].swingHLStartTime Time[1];
                        
    swingHighs[x].swingHLEndTime Time[1];
                        
    swingHighs[x].eqhlCount swingHighs[x].eqhlCount 1;    
                        
                    }
            }
                    
            
    //==================================================================================================    
            
    private void CheckBackForEqualHigh()
            {
                
    eqhlCount 0;
                for ( 
    int i <= CurrentBar i++)
                {    
                    if(
    High[i] > High[1])                                            //    STOP CHECKING BACK
                    
    {
                        break;
                    }
                    else if(
    High[i] == High[1])                                        //    FOUND PRIOR EQUAL HIGH
                    
    {
                        
    DrawSwingHighs(                                                //    DRAW SWING HIGH LINE FROM PRIOR EQUAL HIGH TO CURRENT SWING HIGH
                            
    High[i],
                            
    Time[i],
                            
    Time[1],
                            
    1);
                        
    eqhlCount 1;
                    }
                }
            }

    //==================================================================================================    
            
    private void DrawSwingHighs(double priceDateTime startDateTime endint strength)
            {
                
    Draw.Line(this"swingHigh-" startfalse,
                
    start,
                
    price,
                
    end,
                
    price,
                
    strength == ?  Brushes.Green strength == ?  Brushes.Lime Brushes.Cyan,
                
    strength == DashStyleHelper.Dash DashStyleHelper.Solid,
                
    strength == swingHLLineThickness,
                
    true);
            }
    &
    #8203; 

    #2
    Hello cre8able,

    Thank you for your post.

    It's possible that if no data was coming in, the chart may not have refreshed until you clicked on the line.

    Could you please create a simple reduced test script without the excess logic just draws a line every 10 bars (or something similar) and see if this reproduces the issue?

    I look forward to assisting further.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      thanks Gaby
      I found a different way to program it and it works fine now

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by tsantospinto, 04-12-2024, 07:04 PM
      7 responses
      126 views
      0 likes
      Last Post aligator  
      Started by futtrader, 04-21-2024, 01:50 AM
      5 responses
      56 views
      0 likes
      Last Post NinjaTrader_Eduardo  
      Started by PeakTry, Today, 10:49 AM
      0 responses
      2 views
      0 likes
      Last Post PeakTry
      by PeakTry
       
      Started by llanqui, Today, 10:32 AM
      0 responses
      5 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by StockTrader88, 03-06-2021, 08:58 AM
      45 responses
      3,994 views
      3 likes
      Last Post johntraderuser2  
      Working...
      X