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

Plot Marker based on Woodies

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

    Plot Marker based on Woodies

    I decided to try Ninja Script again and over the weekend I found out some key information that I needed just to begin the basics. I am trying to build a simple indicator that will plot a marker over price when ever Woodies CCI is at the 100 or -100 line. This is what i have:


    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    ///<summary>
    /// Plot up/down marker at CCI -100 and 100
    ///</summary>
    [Description("Paint up/down marker at CCI -100 and 100")]
    publicclass CCI100Marker : Indicator
    {
    #region Variables
    // Wizard generated variables
    privatebool inputdownt0 = true; // Default setting for Inputdownt0
    privatebool inputup1 = true; // Default setting for Inputup1
    // User defined variables (add any user defined variables below)
    #endregion

    ///<summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    ///</summary>
    protectedoverridevoid Initialize()
    {
    Add (new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line,"Plotdown0"));
    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = false;
    Add (new Plot(Color.FromKnownColor(KnownColor.Lime), PlotStyle.Line,"Plotup1"));
    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = false;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Plotdown0.Set(Close[0]);
    Plotup1.Set(Close[0]);
    }
    if (WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[0] >= 100)
    {
    DrawTriangleDown("My triangle down" + CurrentBar, true, 0, 0, Color.Red);
    }

    // Condition set 2
    if (WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[0] <= -100)
    {
    DrawTriangleUp("My triangle up" + CurrentBar, true, 0, 0, Color.Lime);
    }
    PriceTypeSupported = false;


    I am stuck. Please help!
    Thanks!
    J

    #2
    Joshua, your Y axis values for the DrawTriangle calls all have 0 value, this is why you can't see them - please try inputting for example the bar high / low + / - a tick size offset for the Y values.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello there, I just received your email, but we like to keep all replies on the forum if possible so that other users can browse through and see what all the possible resolutions are for their issues. In your code, I see this line:
      Code:
      if (WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[0] > 100)
      {
          DrawTriangleDown("My triangle down" + CurrentBar, true, 0, High [0] + 1 * TickSize, Color.Red);
      }
      First of all, please remove the space between High and [0] and see if that helps out. Next, is your WoodiesCCI's ChopZone actually going above 100? You can verify that by adding a Print() statement that puts whatever you want to print to the Output Window (Tools -> Output Window), like this:
      Code:
      if (WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2).ChopZone[0] > 100)
      {
          Print("woodie's chop is greater than 100 at bar: " + Time[0].ToString());
          DrawTriangleDown("My triangle down" + CurrentBar, true, 0, High [0] + 1 * TickSize, Color.Red);
      }
      If nothing is printed to the output window, then the if statement is not evaluating to true. Are there any errors in the logs (right-most tab of Control Center)?
      AustinNinjaTrader Customer Service

      Comment


        #4
        Hi NT Austin,

        I tried posing in the forum, but limited me on characters.
        I'm not sure about chop zone sutff. All i want to do is the the 14CCI line is above 100 to draw a triangle. When the 14 period CCI line is below -100 to draw a up triangle. I think the chop stuff is not what i want. So if i use:

        if (CCI (14) [0] > 100

        if (CCI (14) [0] < -100 would that be easier? however, I tried using that and it still does not draw anything on my charts.

        So as not to confuse mysef further, I will use regular CCI.
        Everything compiles correct but nothing is drawn on charts.

        J

        Comment


          #5
          J, I'm guessing the chop stuff isn't what you're looking for as well. To find out all available plots to check, you can go to Tools -> New NinjaScript -> Strategy, and then use the condition builder to figure out which plot you want to use.

          I've attached a screenshot of this concept with the CurrentDayOHL indicator, because there are three different plots you can choose from. I've also attached another screenshot (with code) of a CCI check indicator, along with the chart it is applied to.
          Code:
          double currentCCIValue = CCI(14)[0];
          
          if (currentCCIValue > 100)
              DrawArrowDown("down arrow" + CurrentBar, false, 0, High[0] + 2 * TickSize, Color.Red);
          else if (currentCCIValue < -100)
              DrawArrowUp("up arrow" + CurrentBar, false, 0, Low[0] - 2 * TickSize, Color.Green);
          Attached Files
          AustinNinjaTrader Customer Service

          Comment


            #6
            dosent work.
            I give up. All i am trying to do is draw a down triangle once when the CCI line is above the 100 level. Draw one up triangle when cci line is below -100 level. Thats all. I give up on ninjascript. Leave it for the programmers and the teenagers.
            Too bad coding is as easy as Trade Navigtor or even Omnitrader.

            Thanks for your help.
            J

            Comment


              #7
              Joshua 1:8, sorry to hear about your frustration getting this to work for you - if you post the latest code revision you were working we can take another look - did you try just Austin's latest code suggestion producing the triangles in his first screenshot? That seems to be doing exactly what you're after highlighting periods where the CCI travels outside the 100 / -100 levels.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Plot Marker using CCI

                NT Bertrand,

                Thanks for your reply. I acutally deleted my original script. I think that may have helped! LOL I rebuilt the following Indicator Script that works! However, I have questions, How do you move drawing objects away from price? (too close to candle). Also, while building this script i managed to include plotting of dots!! LOL I have selected to transparent them as a temporary fix. Somehow I constructed a "plot dots" command. Thanks again.


                // This namespace holds all indicators and is required. Do not change it.
                namespace NinjaTrader.Indicator
                {
                ///<summary>
                /// Draw a down triangle when CCI crosses above 100 level. Draw a up triangle when CCI crosses below -100 level.
                ///</summary>
                [Description("Draw a down triangle when CCI crosses above 100 level. Draw a up triangle when CCI crosses below -100 level.")]
                publicclass CCICheckEngineLight : Indicator
                {
                #region Variables
                // Wizard generated variables
                privateint cCIDown0 = 100; // Default setting for CCIDown0
                privateint cCIUP1 = -100; // Default setting for CCIUP1
                // User defined variables (add any user defined variables below)
                #endregion

                ///<summary>
                /// This method is used to configure the indicator and is called once before any bar data is loaded.
                ///</summary>
                protectedoverridevoid Initialize()
                {
                Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Dot, "PlotDown0"));
                Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Dot, "PlotUp1"));
                CalculateOnBarClose = true;
                Overlay = true;
                PriceTypeSupported = false;
                }

                ///<summary>
                /// Called on each bar update event (incoming tick)
                ///</summary>
                protectedoverridevoid OnBarUpdate()
                {
                if (CrossAbove(CCI(14), 100, 1))
                {
                DrawTriangleDown("My triangle down" + CurrentBar, false, 0, High[0] + 2 * TickSize, Color.Red);
                }
                if (CrossBelow(CCI(14), -100, 1))
                {
                DrawTriangleUp("My triangle up" + CurrentBar, false, 0, Low[0] + 2 * TickSize, Color.Lime);
                }

                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                PlotDown0.Set(Close[0]);
                PlotUp1.Set(Close[0]);

                Comment


                  #9
                  Great progress J - I would suggest you move your core script to a complete new indicator with no plots defined (or you remove the part of the OnBarUpdate() method where you .Set your plot values).

                  For the distance to the price bar, please use a high tick size multiplier, you currently use 2 here in your code.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by Joshua 1:8 View Post
                    I have questions, How do you move drawing objects away from price? (too close to candle).

                    To move the drawing objects further away from the price bars, you can change the multiplier value in front of the TickSize property. In the example I gave you, the objects are drawn two ticks away from price, but you could change that to 5, like this:
                    Code:
                    DrawTriangleDown("My triangle down" + CurrentBar, false, 0, High[0] + 5 * TickSize, Color.Red);
                    Also, while building this script i managed to include plotting of dots!! LOL I have selected to transparent them as a temporary fix. Somehow I constructed a "plot dots" command.
                    If you don't want the dots to be drawn, you can comment out the PlotDown0.Set() and PlotUp1.Set() lines, like this:
                    Code:
                    //PlotDown0.Set(Close[0]);
                    //PlotUp1.Set(Close[0]);
                    Please let us know if you have any other questions.
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Great!! works! ( I know... It should) Just one more Question... if u don't mind. How do I increase the siz of the triangle up/down?

                      Thank you very much!

                      Comment


                        #12
                        Great to hear, unfortunately you can't control the size from within the code, you could for example just draw two on top of each other with different ticksize settings to create a larger visible signal.
                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          Ok. Thanks again for your help.

                          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