Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help plotting

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

    Need help plotting

    I'm developing a simple variation / function for the MACD. I'd like it to place a hash mark on the current bar where price would need to be for the MACD to start falling or rising. I call it the MACD breaking point.

    I'm fairly new to this but I've narrowed the problem down to the line of code in the OnBarUpdate section that is unique to this indicator. (The main formula) I know everything else in the indicator is working properly. Is there something simple I'm overlooking or is there something inherently wrong with what I'm trying to do in the formula?

    Thanks!!
    Attached Files

    #2
    Hello BReal,

    Thank you for your post.

    When I apply your indicator I get the following message in the Log:
    • Error on setting indicator plot for indicator 'MACDBP'. Value outside of valid range.

    I changed your code a bit to try to see what the issue was. I used the following code:
    Code:
            protected override void OnBarUpdate()
            {
    			if (CurrentBar == 0)
    			{
    				fastEma[0] = Close[0];
    				slowEma[0] = Close[0];
    			}
    				fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
    				slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);
    			
    			Print("");
    			Print(Time[0]);
    			Print(fastEma[0]);
    			Print(slowEma[0]);
    			
    				double alpha	= 2/(1+fast);
    				double beta		= 2/(1+slow);
    			
    			Print(alpha);
    			Print(beta);
    				
    				double ma = ((fastEma[1]-slowEma[1])+((1-beta)*slowEma[1])-((1-alpha)*fastEma[1]))/(alpha-beta);
    			
    			Print(ma);
    				
    				//Value.Set(ma);
            }
    The output that I see in the Output window (Tools > Output) is the following:
    2/12/2016 10:26:00 AM
    1851.61620727342
    1851.53162761705
    0
    0
    NaN
    So the value of alpha and beta is returning 0. Is the intent to divide 2 by the Period?

    Comment


      #3
      Hey Patrick!

      Thanks for the response! I was able to figure it out from there. I changed alpha and beta to look more like the code from the MACD. Instead of what I had I now have (2.0 / (1 + Fast)) and the same for Slow. That did the trick! Just out of curiosity, why did that work? Why does "2" need to be "2.0" in this case?

      Comment


        #4
        Hello BReal,

        I think you just ran into a quirk of C# here with doubles.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        581 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        338 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X