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

Paintbar - Doji Star

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

    Paintbar - Doji Star

    Hi there:

    This is my first post to this forum. I am a previous TradeStation user and am now looking to get back into trading.

    I just want to write a very simple script that will turn the bar a different color if it is a Doji Star, which is where the open is equal to the close.

    I am a bit unfamilar with the programming language of this program, so could someone assist in getting me started?

    Thank you in advance, and Merry Christmas to everyone.

    Michael

    #2
    Hello McClellan,

    Thank you for your post and welcome to the NinjaTrader Support Forum.

    NinjaScript is based on the modern C# programming language. For information on programming in NinjaScript please visit the following link: http://www.ninjatrader.com/support/h..._resources.htm

    For getting started with NinjaScript I recommend our Tutorials available in our Help Guide: http://www.ninjatrader.com/support/h...?tutorials.htm

    For painting a bar if the open of the current bar is equal to the close of the current bar you could use the following code:

    if (Close[0] == Open[0])
    {
    BarColor = Color.Blue;
    }

    Please let me know if I may be of further assistance.

    Comment


      #3
      I used this code:

      if (Close[0] == Open[0])
      {ISDojiStar =
      true;}
      else {ISDojiStar = false;}

      if (ISDojiStar == true);
      {BarColor = Color.Blue;}

      And unforunately it is turning ALL bars blue. Any idea why?

      Comment


        #4
        Hi McClellan,

        You terminated the second if statement with a semi colon ; which means the next statement is not connected to it. The bools aren't needed here, and you could use the snippet from Patrick's last post as a simpler way to do this.

        if (Close[0] == Open[0])
        {ISDojiStar = true;}
        else {ISDojiStar = false;}

        if (ISDojiStar == true);
        {BarColor = Color.Blue;}
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thank you.

          You are correct, but I felt I needed the booleans if am going to apply this to a system.

          Comment


            #6
            Hi there. I am having trouble again.

            I am trying to write a system that goes something like this:

            If DojiStar == true AND stochastics > 80 then
            enter long

            If DojiStar == true AND stochastics < 20 then
            enter short

            Can you assist?

            I tried to put this into the builder and it is not working at all. No trades exist.

            Here is some code I ATTEMPTED:

            // Condition set 1
            if (DojiStar() = true
            && Stochastics(7, 14, 3).D[0] >= 80)
            {
            EnterLong(DefaultQuantity, "");
            }

            // Condition set 2
            if (DojiStar() = true
            && Stochastics(7, 14, 3).D[0] <= 20)
            {
            EnterShort(DefaultQuantity, "");

            Comment


              #7
              Code:
              // Condition set 1
              if (DojiStar() = true
              && Stochastics(7, 14, 3).D[0] >= 80)
              {
              EnterLong(DefaultQuantity, "");
              }
              
              // Condition set 2
              if (DojiStar() = true
              && Stochastics(7, 14, 3).D[0] <= 20)
              {
              EnterShort(DefaultQuantity, "");
              '

              Please ensure you have DojiStart==true, not DojiStar=true; Also, you could simply just put DojiStar() there. When its true the statement will be true.

              Does this DojiStar() function return a true when a doji star is present? Have you tested its working correctly?

              Please let me know if I may assist further.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Here is some code for the DojiStar indicator:

                protected override void OnBarUpdate()
                {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                ISDojiStar = false;
                if (Close[0] == Open[0] || (Close[0] >= Open[0] && Close[0] <= Open[0] + TickSize) || (Close[0] <= Open[0] && Close[0] >= Open[0] - TickSize))///(Close[0] == Open[0])
                {ISDojiStar = true;}
                else {ISDojiStar = false;}

                if (ISDojiStar == true)
                {BarColor = Color.Blue;}

                Comment


                  #9
                  The default value of an indicator would always be a number(a plot), and not a bool true/false expression like it looks like you're trying to expose from it.

                  If you want to expose the value of a bool flag from one script to another, there needs to be additional code and structure added. The technique for this is shown in this sample:


                  I don't recommend that you follow this sample yet. As you're just getting started, it's best to keep things simple and get things working within only one script. Once you get more familiar with the basics, then start working on the more advance concepts like exposing non plot values.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    It would be really nice if this forum was searchable. I did not see a search box anywhere to search the threads by subject.

                    Comment


                      #11
                      There is search available. You can use the Search button on the forum toolbar. It is hard to beat google search though.



                      How to search a site with google.
                      Attached Files
                      Last edited by NinjaTrader_RyanM1; 12-29-2011, 01:03 PM.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        Great. Thank you.

                        So I am having trouble with the following code in a SYSTEM:

                        protectedoverridevoid Initialize()
                        {
                        Add(CandleStickPatternAll());

                        SetProfitTarget(
                        "", CalculationMode.Percent, 500);
                        SetStopLoss(
                        "", CalculationMode.Percent, 100, false);
                        SetTrailStop(
                        "", CalculationMode.Percent, 0, false);
                        CalculateOnBarClose =
                        true;
                        }
                        ///<summary>
                        /// Called on each bar update event (incoming tick)
                        ///</summary>
                        protectedoverridevoid OnBarUpdate()
                        {
                        if (CandleStickPatternAll().BullishEngulfingFound[0])
                        EnterLong();
                        if (CandleStickPatternAll().BearishEngulfingFound[0])
                        EnterShort();
                        Print(CandleStickPatternAll().ExposedVariable);
                        }
                        #region Properties
                        #endregion
                        }
                        }


                        I have compile errors at the red lines. It says "The name CandlestickPatternAll is not valid in this context."
                        Any idea what could be going on?

                        Comment


                          #13
                          Hmm. I saved my work, then exited the NinjaScript. Then restarted it and now I only have 4 errors. They all say "No overload method for 'CandleStickPatternAll' takes '0' arguments."

                          Any clue?

                          Comment


                            #14
                            Originally posted by McClellan View Post
                            Hmm. I saved my work, then exited the NinjaScript. Then restarted it and now I only have 4 errors. They all say "No overload method for 'CandleStickPatternAll' takes '0' arguments."

                            Any clue?
                            You must specify all the input parameters when you call an indicator. Intellisense can help, but you may have to look at the code in the indicator. You must specify everything the is in a GridCategory or a Parameters Category.

                            If you really just want to use the defaults, you can always create a named instance of the indicator using the new keyword and then call/query the named instance. Creating an instance with the new keyword, you should not have to specify any parameters.

                            This has the considerable side benefit of bypassing all the NT magic code that is used to iterate through all running instances to determine the correct one to call on each event. It becomes especially useful if you are processing every tick with COBC = false.

                            Comment


                              #15
                              That makes sense, but there are no inputs. The code for the indicator is attached.



                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Yesterday, 06:40 PM
                              2 responses
                              19 views
                              0 likes
                              Last Post algospoke  
                              Started by ghoul, Today, 06:02 PM
                              3 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              45 views
                              0 likes
                              Last Post jeronymite  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              7 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              10 responses
                              181 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X