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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    110 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    156 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    74 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    125 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    79 views
    0 likes
    Last Post PaulMohn  
    Working...
    X