Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with coding

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

    Help with coding

    Could someone let me know how I would code or where I would look to code the following:

    I'm trying to code an indicator that I will later use inside a strategy and not sure how to do the following:

    For example:
    Condition:
    If the MACD crosses up x bars back,

    Entry into position
    Then place an arrow when the small trigger lines cross up.

    I believe if I understand how to code this, then I would be able to use the same methodology to use the same code for some other conditions inside my code.

    Any help would be greatly appreciated. Thanks.

    Ryan

    #2
    Hello gretzkyless,

    Thanks for your post.

    What are you trying to find the MACD crossing above? I'm assuming you are looking for the MACD to cross the close price?

    To find a cross use CrossAbove().

    For example:

    if (CrossAbove(MACD(12, 26, 9), Close, X))
    {
    EnterLong();
    }


    Also, I am not understanding the second part of this inquiry. "Then place an arrow when the small trigger lines cross up". Which small trigger line are you referring to?

    What is this small trigger line crossing above?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea for the quick reply. I have already coded the code you sent, and also coded the small triggers crossing.

      if (CrossAbove(MACD(12, 26, 9), Close, X))

      DrawArrowUp("UpAarrow" + CurrentBar, true, 0, Low[0] - (offset * TickSize), Color.Lime);

      if (CrossAbove(RyanTriggerLinesSmall(20, 5).Plot1_Up, RyanTriggerLinesSmall(20, 5).Plot2_Up, 1)

      DrawArrowUp("UpAarrow" + CurrentBar, true, 0, Low[0] - (offset * TickSize), Color.Green);

      If I code the 2 pieces separately, I get arrows for both, but if I code together, I don't get any arrows

      if ((CrossAbove(MACD(12, 26, 9), Close, X))
      &&
      (CrossAbove(RyanTriggerLinesSmall(20, 5).Plot1_Up, RyanTriggerLinesSmall(20, 5).Plot2_Up, 1))

      DrawArrowUp("UpAarrow" + CurrentBar, true, 0, Low[0] - (offset * TickSize), Color.Cyan);

      because the MACD crosses on the prior bar BEFORE the small trigger lines cross.

      Hopefully, this helps you understand what I'm trying to do. Thanks again for your help.

      Ryan

      Comment


        #4
        Hello gretzkyless,

        Are you not wanting arrows for both?

        You want the MACD to cross first, after this happens if the second condition is triggered then draw a single arrow correct?

        If so, when the MACD crosses set a bool to true. Require this bool to be true for the second condition to trigger. When the second condition triggers, set the bool back to false.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your help, but could you please let me know where I should look to find out how to code this?

          Ultimately, I would only like the small trigger indicator to plot on the chart and not have both since in the indicator I'm coding, I only want arrows after x, y, and z, conditions are met.

          Comment


            #6
            I was able to find this example that I'm sure will be very helpful. Thought I would post here in case someone takes a look for how to code boolean language. Have a good week-end.
            Attached Files

            Comment


              #7
              Hello gretzkyless,

              For example:

              In Intialize():
              private bool condition1true = false;

              In OnBarUpdate():

              if (CrossAbove(MACD(12, 26, 9), Close, X))
              {
              condition1true = true;
              }

              if (condition1true == true && CrossAbove(RyanTriggerLinesSmall(20, 5).Plot1_Up, RyanTriggerLinesSmall(20, 5).Plot2_Up, 1))
              {
              DrawArrowUp("UpAarrow" + CurrentBar, true, 0, Low[0] - (offset * TickSize), Color.Lime);
              condition1true = false;
              }
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thank you for the help. This definitely will help me figure out what I'm trying to do. Have a good week-end.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                576 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                334 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                553 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                551 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X