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

Paintbars based on 4 indicators all agreeing

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

    Paintbars based on 4 indicators all agreeing

    My next project is a paintbar I wrote for my tradestation charts.
    When 3 indicators are all above their midline and MACD is greater than its Avg, the bars are blue.
    If the 3 are below the midline and mACD is under its Avg the bars are pink.
    If at least one is different the bars are gray.
    All are available on Ninja.
    Here is a screenshot of the ES 6/24.
    Any takers?
    Attached Thumbnails

    #2
    Hi simpletrades, thanks for the post. What do you mean by "any takers?" Are you trying to sell an indicator?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      Hi simpletrades, thanks for the post. What do you mean by "any takers?" Are you trying to sell an indicator?
      just the opposite-trying to get one written.

      Comment


        #4
        Use the condition builder then just copy the code to a new indicator. Piece of cake. Then just use BarColor, you can get the syntax for any indicator that already supports paint bars...

        Good luck.

        Comment


          #5
          Originally posted by Elliott Wave View Post
          Use the condition builder then just copy the code to a new indicator. Piece of cake. Then just use BarColor, you can get the syntax for any indicator that already supports paint bars...

          Good luck.
          This as far as I got--trying the first part for upcolor, but I get an error that Operator '>' cannot be applied to operands of type 'method group' and 'int'. The error is for && Momentum>0

          Here's what I have so far:
          PHP Code:
          /// <summary>
          /// MFI RSI MACD MOM paintbar
          /// </summary>
          [Description("MFI RSI MACD MOM paintbar")]
          public class 
          FourIndicatorPaintbar Strategy
          {
          #region Variables
          // Wizard generated variables
          private int myMFI 14// Default setting for MyMFI
          private int myRSI 21// Default setting for MyRSI
          private int myMOM 9// Default setting for MyMOM
          private int fMACD 8// Default setting for FMACD
          private int sMACD 18// Default setting for SMACD
          private int avgMACD 9// Default setting for AvgMACD
          // User defined variables (add any user defined variables below)
          #endregion
          /// <summary>
          /// This method is used to configure the strategy and is called once before any strategy method is called.
          /// </summary>
          protected override void Initialize()
          {
          CalculateOnBarClose false;
          }
          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()

          // Condition set 1 
          if (MyMFI50
          && RSImine(21).Plot0[0] > 50
          && Momentum 0
          && MACD(8189)[0] > MACD(8189).Avg[0] )
          BarColor=Color.Blue;
          {
          }

          Comment


            #6
            simpletrades, I'm not sure how you've defined Momentum and MyMFI and what they return, but you want to make sure they return a double value to be compared to your numerical value.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              simpletrades, I'm not sure how you've defined Momentum and MyMFI and what they return, but you want to make sure they return a double value to be compared to your numerical value.
              i just assumed whatever ninja came up with was ok since ninja's MFI and Momentum indicators when used on charts are fine.

              Comment


                #8
                Hi simpletrades, an easy way to get the exact code you need is to build the condition in the strategy wizard and then hit "view code" then copy + paste that code into your new indicator.

                The conditions for Momentum, for example, would look like this:
                Code:
                Momentum(14)[0] > 0
                I've also attached a picture that shows how to build a condition in the wizard.
                Attached Files
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Austin View Post
                  Hi simpletrades, an easy way to get the exact code you need is to build the condition in the strategy wizard and then hit "view code" then copy + paste that code into your new indicator.

                  The conditions for Momentum, for example, would look like this:
                  Code:
                  Momentum(14)[0] > 0
                  I've also attached a picture that shows how to build a condition in the wizard.
                  Thanks recoding Momentum showed me how to fix MFI also.

                  Then I pasted condition 1 in again and changed it to condition 2 and made all the '>' read '< 'and changed the color.
                  I think it works. I'll compare it to a tradestation chart to see if the coloring matches each bar.
                  The only thing I couldnt do was a third condition stating that if any 1 of the indicators was the opposite way, it would color black instead of blue or magenta. I had to go into chart properties and change the color for downbars and for upbars to black.

                  I made it as a strategy although it isnt meant for entry and exit automation.
                  Since I made it a strategy, is there any way to still be able to have the chart point out my actual trades with the arrows again?
                  Last edited by simpletrades; 08-04-2009, 09:10 AM.

                  Comment


                    #10
                    Originally posted by simpletrades View Post
                    The only thing I couldnt do was a third condition stating that if any 1 of the indicators was the opposite way, it would color black instead of red or green. I had to go into chart properties and change the color for downbars and for upbars to black.
                    To do a third condition, you'd have to include every possible state in the if-statement--this could quickly become messy. Another possibility would be to program each indicator individually and have each indicator return either -1, 0, or 1 to some summing function and plot only if the sum is correct. Just as the first method could get messy, this second method could get complicated.

                    Originally posted by simpletrades View Post
                    I made it as a strategy although it isnt meant for entry and exit automation. Every time I wanted to change the code to see a different color for example, the chart bars didnt change to the new color. I had to delete the chart then load a new template chart and add the paintbar strategy which now showed the newer colors.
                    Instead of creating a new template and everything every time, you can just hit the F5 key, which is the hotkey for the command "Reload NinjaScripts" (also accessable by right-clicking on the chart and selecting Reload NinjaScript).

                    Originally posted by simpletrades View Post
                    Since I made it a strategy, is there any way to still be able to have the chart point out my actual trades with the arrows again?
                    Sure, double-click on the chart to bring up chart properties -> Trade Visualization -> Plot Executions -> set to TextAndMarker.
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Austin View Post
                      To do a third condition, you'd have to include every possible state in the if-statement--this could quickly become messy. Another possibility would be to program each indicator individually and have each indicator return either -1, 0, or 1 to some summing function and plot only if the sum is correct. Just as the first method could get messy, this second method could get complicated.


                      Instead of creating a new template and everything every time, you can just hit the F5 key, which is the hotkey for the command "Reload NinjaScripts" (also accessable by right-clicking on the chart and selecting Reload NinjaScript).


                      Sure, double-click on the chart to bring up chart properties -> Trade Visualization -> Plot Executions -> set to TextAndMarker.
                      Trade visualization still only works if I delete my paintbar strategy.

                      For that third condition to get gray or black bars, tradestation lets me say that if condition1=false and condition2=false that I can color it gray.I was hoping I could do that here, but it still works fr me by making up or down bars black on chart properties.

                      I found out after posting earlier that by going back to my strategy in the chart and clicking apply, the newer compiled color shows up so I dont need to delete charts anymore, but thanks.

                      Comment


                        #12
                        Originally posted by simpletrades View Post
                        Trade visualization still only works if I delete my paintbar strategy.
                        Yes, that is correct, sorry. That is because when you add a strategy to a chart it "takes the spotlight". Thus, it would mask all your other trades while applied. If you took the strategy off the chart, all your other trades would become visible again.

                        While applied, the only trades on the chart would be the ones generated by the strategy.
                        AustinNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Austin View Post
                          Yes, that is correct, sorry. That is because when you add a strategy to a chart it "takes the spotlight". Thus, it would mask all your other trades while applied. If you took the strategy off the chart, all your other trades would become visible again.

                          While applied, the only trades on the chart would be the ones generated by the strategy.
                          Here's a screenshot. I left the RSI and Mom on to show how they all need to come together. MACD and MFI are always loaded on my chart and Stoch isnt part of the paintbar.
                          Attached Files

                          Comment


                            #14
                            Originally posted by NinjaTrader_Bertrand View Post
                            simpletrades, I'm not sure how you've defined Momentum and MyMFI and what they return, but you want to make sure they return a double value to be compared to your numerical value.
                            I dont think its doubled--at least i didnt do anything to add to it to make it that way. It seems to work OK, but i guess i wouldnt know what doubling would look like on it. Why is that necessary on just those 2 indicators as opposed to MACD and RSI?

                            Also, I copied and pasted my strategy code into a new indicator window as an indicator so now the trade visualization woks.

                            Comment


                              #15
                              simpletrades, a double value is simply a number with a decimal. It doesn't have anything to do with multiplying a value by two. It is necessary for certain indicators because they return decimal values. A few other data types include:
                              • Int - an integer value (1, 2, 3, -1, -7)
                              • Long - an integer value with a wider range of values than Int
                              • Float, double, decimal (from least possible precision to most possible precision, NOT accuracy) - make it possible to include decimal values (100.23, .94, 103838.3983932, etc).
                              If you'd like to review the variable types in C#, this page is a good place to get started.
                              Last edited by NinjaTrader_Austin; 08-05-2009, 08:46 AM.
                              AustinNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by PaulMohn, Today, 03:49 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post PaulMohn  
                              Started by inanazsocial, Today, 01:15 AM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by rocketman7, Today, 02:12 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post rocketman7  
                              Started by dustydbayer, Today, 01:59 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post dustydbayer  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              5 responses
                              23 views
                              0 likes
                              Last Post trilliantrader  
                              Working...
                              X