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

unexpected outcome in market analyzer

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

    unexpected outcome in market analyzer

    Hi Ninjas

    Market analyzer outputs 1 when I don't want.
    I have identified 2 high swings on MACD line, if the last swing is smaller in value then the previous one, then market analyzer returns 1, which is what I want. First I thought it works perfect, but soon realized that 1 is also returned when last swing is higher in value than the previou one, which is what I don't want.

    Here's the code:

    Code:
    protected override void Initialize()     
            {
            Add(new Plot(Color.Green, PlotStyle.Line, "Plot0"));
            CalculateOnBarClose = true;
            }
    
     protected override void OnBarUpdate()
            {
                
    
    //Last swing:
      int prevMacdHighBar = Swing(MACD(12, 25, 9).Avg, 2).SwingHighBar(0,1,150);           
      double prevMacdHigh = Swing(MACD(12, 25, 9).Avg, 2).SwingHigh[prevMacdHighBar]; 
    
    //Previous swing:
      int prevMacdHighBar2 = Swing(MACD(12, 25, 9).Avg, 2).SwingHighBar(0,2,150);
      double prevMacdHigh2 = Swing(MACD(12, 25, 9).Avg, 2).SwingHigh[prevMacdHighBar2]; 
    
    if    (prevMacdHigh2 > prevMacdHigh)            
            
                    {
                    Plot0.Set(1);
                    }
             }
    I guess I need to make the if() part more precise maybe, but then it's all integrated... and I don't know if I this is the right way to go.
    This test is carried out on each bar and even if in the past the "prevMacdHigh2 > prevMacdHigh" was true, but it's not true on the last 2 swings then I don't want 1 in the market analyzer.

    Please advise
    Last edited by ionaz; 06-24-2013, 03:39 AM.

    #2
    Hello ionaz,

    Thank you for your post.

    How are you setting the Plot to 2? What conditions are used to set the value to 2? Can you provide this code so I may investigate this matter further?

    Comment


      #3
      Hi Patrick

      Thanks for your post.
      I have provided all the code already; Also, I don't set the plot to 2, I set it to 1.

      Comment


        #4
        Hello ionaz,

        Thank you for your response.

        My mistake on that last part, but you will need to ensure the value is set to something else if the prevMacdHigh2 is not greater than the prevMacdHigh.
        Code:
        if(prevMacdHigh2 < prevMacdHigh)
        {
        Plot0.Set(0);
        }
        Please let me know if you have any questions.

        Comment


          #5
          Hi Patrick

          Thanks for this. So what I have now:

          Code:
          		if	(prevMacdHigh2 > prevMacdHigh)			
          		
          				{
          				Plot0.Set(1);
          				}
          			
          		if        (prevMacdHigh2 < prevMacdHigh)
          				{
          				Plot0.Set(0);
          				}
          And it still doesn't work

          OK, market analizer returns 1 and 0 nicely. When I go check all the 1, I realize that 1 is returned in both cases:
          prevMacdHigh2 > prevMacdHigh
          prevMacdHigh2 < prevMacdHigh
          Which means it doesn't work.

          Comment


            #6
            Hello ionaz,

            Thank you for your response.

            Please attach your full code to your response so I may investigate this matter further. If you prefer you can send the code to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 869087' in the subject line with a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=58650

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Today, 06:40 PM
            0 responses
            10 views
            0 likes
            Last Post algospoke  
            Started by maybeimnotrader, Today, 05:46 PM
            0 responses
            7 views
            0 likes
            Last Post maybeimnotrader  
            Started by quantismo, Today, 05:13 PM
            0 responses
            7 views
            0 likes
            Last Post quantismo  
            Started by AttiM, 02-14-2024, 05:20 PM
            8 responses
            168 views
            0 likes
            Last Post jeronymite  
            Started by cre8able, Today, 04:22 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X