Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 philmg, Today, 01:17 PM
        0 responses
        4 views
        0 likes
        Last Post philmg
        by philmg
         
        Started by cre8able, Today, 01:01 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by manitshah915, Today, 12:59 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by ursavent, Today, 12:54 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Mizzouman1, Today, 07:35 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X