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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    68 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X