Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawLine Help

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

    DrawLine Help

    I'm trying to Draw a line every time Macd cross 0 , the code is:

    protected override void OnBarUpdate()
    {

    if(MACD(12,26,9)[0] > 0 && MACD(12,26,9)[1] < 0)
    {
    updotbar=CurrentBar;
    updot=High[0];
    }

    if(MACD(12,26,9)[0] > 0 && MACD(12,26,9)[1] < 0)
    {
    dndotbar=CurrentBar;
    dndot=Low[0];
    }

    if (updotbar !=0 && updot !=0 && dndotbar!=0 && dndot!=0 )
    {
    DrawLine("MyLine1"+CurrentBar, updotbar, updot, dndotbar, dndot, Color.Blue);
    DrawDiamond("MyDiamond1"+CurrentBar,true,dndotbar, dndot, Color.Red);
    DrawDiamond("MyDiamond2"+CurrentBar, true,updotbar, updot, Color.Blue);
    }

    }

    Any Idea of what I'm doing wrong will be appreciated.

    Regards
    Attached Files

    #2
    You never reset your updotbar, updot, dndotbar, dndot variables back to zero so after it evaluates to true once it will stay true for your whole chart. Also, your two if statement conditions are exactly the same. I am not sure if that was what you intended. If so you can merge the two together and maybe even share the same variables.
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    85 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    48 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    29 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    32 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    67 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X