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