• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 stefanjagger, Today, 07:47 AM
              0 responses
              1 view
              0 likes
              Last Post stefanjagger  
              Started by tonynt, Today, 07:07 AM
              1 response
              4 views
              0 likes
              Last Post tonynt
              by tonynt
               
              Started by Marklhc1988, Today, 06:53 AM
              3 responses
              10 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Started by ntbone, Today, 12:05 AM
              0 responses
              10 views
              0 likes
              Last Post ntbone
              by ntbone
               
              Started by cutzpr, Yesterday, 09:33 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X