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 wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    26 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, Yesterday, 09:53 PM
    2 responses
    49 views
    0 likes
    Last Post wzgy0920  
    Started by Kensonprib, 04-28-2021, 10:11 AM
    5 responses
    191 views
    0 likes
    Last Post Hasadafa  
    Started by GussJ, 03-04-2020, 03:11 PM
    11 responses
    3,231 views
    0 likes
    Last Post xiinteractive  
    Working...
    X