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 fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,406 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        98 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        9 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X