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 samish18, 04-17-2024, 08:57 AM
    22 responses
    107 views
    0 likes
    Last Post samish18  
    Started by Ashkam, 04-29-2024, 09:28 AM
    2 responses
    26 views
    0 likes
    Last Post Ashkam
    by Ashkam
     
    Started by Felix Reichert, 04-26-2024, 02:12 PM
    6 responses
    41 views
    0 likes
    Last Post Felix Reichert  
    Started by MrForgetful, Today, 01:28 AM
    3 responses
    21 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
    16 responses
    51 views
    0 likes
    Last Post cmtjoancolmenero  
    Working...
    X