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

MACD cross above indicator with Draw.Arrow - need some help!

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

    MACD cross above indicator with Draw.Arrow - need some help!

    Hi guys

    I'm hoping to code up a strategy to test based around MACD crosses.

    I'm not a developer so am finding my way through as best as I can. I'm editing the C# code using visual studio, all going ok.

    I've had a skim through the forum & found something similar to what I was looking to do, looking to build an indicator first before then creating a strategy so that I can test it.

    I wanted to create the indicator myself from scratch which I've done, but for some reason it is not adding the arrows to the chart in the same way, which I can't understand now sorry, the code looks the same to me & everything compiles no problem

    Please see an snippet below, but I've attached the 2 indi files as well

    Code:
    protected override void OnBarUpdate()
    		{
                //Add your custom indicator logic here.
                if (CurrentBars[0] < 1)
                    return;
    
                // Up Arrows
                if (CrossAbove(MACD1.Avg, 0, 1))
                {
                    Draw.ArrowUp(this, "above1" +CurrentBar, false, 1, Low[1], Brushes.LimeGreen);
                }
                // Down Arrows
                if (CrossBelow(MACD1.Default, MACD1.Avg, 1))
                {
                    Draw.ArrowDown(this, "below1" +CurrentBar, false, 1, High[1] + TickSize * 5, Brushes.Red);
                }
            }
    If you could let me know where I'm going wrong I'd be super grateful as I think it is something to do with when I'm creating the new indi from scratch

    Cheers
    Gav
    Attached Files

    #2
    Hello Gav_G,

    Thanks for your post.

    In your code section, you have a crossabove and a crossbelow.

    The cross above condition is using the cross of the Macd average line above the value of 0 (zero) so basically, it provides an up arrow when the Macd average line crosses the zero line. The arrow is plotted at the previous bars Low.

    The cross below condition is using the cross of the MACD line over the MACD average line so when the MACD line crosses below the MACD average line, it provides a down arrow 5 ticks above the High of the previous bar.

    In looking at the two files I am guessing that you want the MACD average line crossing zero for both conditions and not just the crossabove, so you would need to change:

    if (CrossBelow(MACD1.Default, MACD1.Avg, 1))

    to

    if (CrossBelow(MACD1.Avg, 0, 1))
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul, thanks for the response matey

      I actually want the arrow to be placed when the default crosses the avg but I was messing around with both.

      I have literally just got it working & was about to update this thread.

      Basically on the startup or State.Dataloaded bit I was basically missing the below

      else if (State == State.DataLoaded)
      {
      MACD1 = MACD(FastPeriod, SlowPeriod, Smooth);
      }

      I did have this in previously, but as you can see in the working version, where this is defined, it actually uses a convert to INT32 as part of the statement, it wasn't working in mine when I had this set

      Anyway I've got this working ok for now, so on to the next hurdle

      Thanks as ever for the reponse

      Gav

      Comment


        #4
        Maybe you can use some of the coding from here... or just use the indicator.
        Attached Files

        Comment


          #5
          Hello,

          I have searched the internet high and low for a modification to the below indicator, one that has the option to only show buy arrows above the zero line and only sell arrows below the zero line, would it be possible for someone here to make this modification for me, it would greatly be appreciated.

          Thank You !!!
          Attached Files

          Comment


            #6
            Hello forextrader2003,

            Thanks for your post.

            If no one provides the modification you requested we can provide links to 3rd party coder who could provide this modification service.

            If you want to change it, I suspect all you need to change is the lines

            From: if(CrossAbove(myMACD.Default, myMACD.Avg,1))
            To: if(CrossAbove(myMACD.Default, myMACD.Avg,1) && my.MACD.Default[0] > 0 && myMACD.Avg[0] > 0 )

            also
            From: if(CrossBelow(myMACD.Default, myMACD.Avg,1))
            To: if(CrossBelow(myMACD.Default, myMACD.Avg,1) && my.MACD.Default[0] < 0 && myMACD.Avg[0] < 0)

            and then compile the indicator.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thank You very much PaulH !!!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Barry Milan, Yesterday, 10:35 PM
              7 responses
              19 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by AttiM, 02-14-2024, 05:20 PM
              10 responses
              179 views
              0 likes
              Last Post jeronymite  
              Started by ghoul, Today, 06:02 PM
              0 responses
              9 views
              0 likes
              Last Post ghoul
              by ghoul
               
              Started by DanielSanMartin, Yesterday, 02:37 PM
              2 responses
              13 views
              0 likes
              Last Post DanielSanMartin  
              Started by DJ888, 04-16-2024, 06:09 PM
              4 responses
              13 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Working...
              X