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

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 love2code2trade, Yesterday, 01:45 PM
                4 responses
                28 views
                0 likes
                Last Post love2code2trade  
                Started by funk10101, Today, 09:43 PM
                0 responses
                7 views
                0 likes
                Last Post funk10101  
                Started by pkefal, 04-11-2024, 07:39 AM
                11 responses
                37 views
                0 likes
                Last Post jeronymite  
                Started by bill2023, Yesterday, 08:51 AM
                8 responses
                44 views
                0 likes
                Last Post bill2023  
                Started by yertle, Today, 08:38 AM
                6 responses
                26 views
                0 likes
                Last Post ryjoga
                by ryjoga
                 
                Working...
                X