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

Problems learning to change line plot color & draw arrows once only

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

    Problems learning to change line plot color & draw arrows once only

    Albeit very slowly am learning to code a little in Ninja Script. In order to find good parameters for an indicator for discretionary day trading, I finally managed to write a Strategy that works (to my amazement!), but still run into simple things that I just can't figure out nor phrase/reference the issue to find answers in the Help menus.

    For example am trying to customize an indicator method that uses two plots so that
    a) when there is a trend change according to rules an arrow is plotted just once when that trend change occurs, not every time the condition is true
    b) have (the slower) line change color in accordance with trend, i.e. uptrend color and downtrend color put on that line.

    Believe it or not I have spent many hours trying to figure out how to do it, but have got absolutely nowhere although I can plot arrows in accordance with the trend rules but not just once. Cannot figure out at all how to change the line color and everything I have tried, although it compiles, just results in no line at all being plotted.

    I understand Ninja trader staff are not allowed to help with custom or '3rd Party' indicators but am hoping that someone experienced could show me how to do this since I have drawn a blank thus far and yet am sure what I am trying to do is extremely basic 101 stuff.

    Thanks in advance.
    Attached Files

    #2
    a. Use a flag variable.

    Code:
    if (condition && flag == true)
    {
         DrawArrowUp(...);
         flag = false;
    }
    b. To do a multi color plot you will need to review this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=3227
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      a. Use a flag variable.

      Code:
      if (condition && flag == true)
      {
           DrawArrowUp(...);
           flag = false;
      }
      b. To do a multi color plot you will need to review this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=3227
      Josh, thank you.

      Could you explain in what way I have not already coded that in the snippet below in this case with the uptrend/downtrend booleans which I believe are equivalent to your 'flag'? As soon as the DrawArrow line is issued the 'flag' is turned to false. But then the condition repeats itself and a new arrow is generated because the 'uptrend/flag' is turned back on. Admittedly, I have the Arrow command predicated simply by the Uptrend = true only, but I cannot see any difference between what I have done and what you are suggesting.

      Or put another way: how do you turn the flag back onto true after you have turned it to false by drawing the arrow without having a repeat during the same swing series (since the condition can go true and false within the same swing)?

      (The waslong and wasshort booleans below made no difference and are not being used any more although I tried many different ways to get them to work. They work nicely this way in a Strategy to prevent multiple entries in same swing - albeit with a much simpler crossover only condition - but not with the indicator with these more complex conditions which require both a cross and both lines having the same up or down slope.)

      I shall look at the example for the color change. Thanks.

      if ((TenkanSen[0] > TenkanSen[1]) & (Kijunsen[0] > Kijunsen[1]) /*&& wasshort*/ ) // inserting wasshort makes no diff with indicator problem
      uptrend = true; waslong = true; wasshort = false; // all of these useless
      if ((TenkanSen[0] < TenkanSen[1]) & (Kijunsen[0] < Kijunsen[1]) /*&& waslong*/ )
      downtrend = true; waslong = false; wasshort = true; // all of these useless

      if (Showarrows)
      {
      if (uptrend /* && uptrend[1] = false*/ ) // cannot do [0] and [1] with booleans
      DrawArrowUp(CurrentBar.ToString(), true, 0, Low[0] - TickSize*3, Color.DarkGoldenrod); uptrend = false; // this works until condition regenerated from code above = multiple arrows
      if (downtrend)
      DrawArrowDown(CurrentBar.ToString(), false, 0, High[0] + TickSize*3, Color.SteelBlue); downtrend = false;

      Comment


        #4
        line color II

        I have the multi-colored plot example but am unable to transliterate it into my code below. This one restates the condition with the EMA etc. each time whereas mine starts with defining the lines. Is there no simple way to
        a) define up and down trend as I have done with the arrow coding below so that
        b) you can apply an up or down color to one particular plot?

        I find the plotting instructions essentially impossible to understand for some reason and unless I can find an example of someone doing basically exactly what I am trying to do have been unable to code color conditions myself. Again, in your example the conditions are nested within the plot instructions in a way that I would have no idea how to duplicate in the code submitted below. Unfortunately.

        Comment


          #5
          If you are using multiple statements to follow your if-statement you will want to use { } brackets.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Thank you Josh!

            {}s fixed the problem.

            I thought if it compiled it must be correct but obviously that is wrong. Now I have just one arrow per trend change.

            Next challenge: the line changing color!
            Last edited by cclsys; 03-19-2009, 12:48 PM.

            Comment


              #7
              I have managed to introduce BackColor which works fine for the trend change condition but cannot find any references as to how to control the opacity. How can I get it to be only like 30% strong (or whatever)?

              In the Variables section I put in:
              private Color backcolorup = Color.LightYellow;
              private Color backcolordown = Color.Azure;

              And then later on down I added in:

              if (wasshort) BackColorAll = backcolordown;
              if (waslong) BackColorAll = backcolorup;

              and it works fine, just that I would prefer semi-transparent colors.

              Comment


                #8
                cclsys,

                You cannot adjust the opacity. If you want a lighter color I suggest you just choose one that is lighter by nature.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Opacity is coded like this:

                  private Color backcolorup = Color.FromArgb(OpacityValue, Color.LightYellow);

                  I don't know if the application of the defined color causes in your case an issue or not.

                  Regards
                  Ralph

                  Comment


                    #10
                    Originally posted by NinjaTrader_Josh View Post
                    cclsys,

                    You cannot adjust the opacity. If you want a lighter color I suggest you just choose one that is lighter by nature.
                    Thank you Josh. But I have a custom-programmed indicator that does exactly that. But the code is protected so I can't see how the programmer did it. It even has an option in the menu panel to adjust opacity (from 1 - 255).

                    So it must be possible, eh?

                    Comment


                      #11
                      Sure it is possible, but this is beyond what I can offer support for. Please see Ralph's post for a hint.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        thanks for transparency assist. Worked great.

                        Originally posted by Ralph View Post
                        Opacity is coded like this:

                        private Color backcolorup = Color.FromArgb(OpacityValue, Color.LightYellow);

                        I don't know if the application of the defined color causes in your case an issue or not.

                        Regards
                        Ralph
                        Ralph, thank you very much. That worked, although I would like to be able to both choose the colors in the Panel menus and also adjust opacity. Ideally. The way it is now I can do all that manually by opening the code.

                        What I have is:

                        private Color colorup = Color.DarkGoldenrod;
                        private Color colordown = Color.SteelBlue;
                        private int opacityValue = 25;
                        private Color backcolorup = Color.FromArgb(75, Color.LightYellow);
                        private Color backcolordown = Color.FromArgb(75, Color.Azure);


                        Now the first two are used for arrow coloring and work fine (though I like the backcolor better when fairly transparent).

                        I tried putting colorup in instead of Color.LightYellow but it didn't like that.
                        I also tried putting in opacityValue instead of 75 but it didn't like that either.

                        But then before posting this I added Backcolorup and Backcolordown into the Properties at the end so they would appear in the menus and you get the rgb numbers that can only be adjusted in the Web color submenus and you add in the opacity number ahead, so it is like 75,255,255,100.

                        So that worked well. Thank you very much. Now I can choose a rich color but have it very transparent. Not a big deal of course. Part of my doing this is just to try to learn Ninja coding better.

                        But I like having one method indicator be a Paintbar, another a line, another a backcolor and that way you can have three methods with minimal busyness on the chart.

                        In addition today I was trying to get a visual assist because I wanted to add a condition into the Donchian medians I like to work with, namely that both are moving in the same direction, not just a simple cross and this is very helpful visually since sometimes it's hard to keep track of with low number tick charts.

                        Again, thanks.

                        ( And also thanks again Josh )

                        Comment


                          #13
                          In the protected indicator I have it is possible though to have opacity in the menu and then pick the colors from the usual Web versus Custom drop down area. I suspect this has something to do with how one configures things for display in the Properties area.

                          I have now also understood - belatedly - that Josh's suggestion to choose lighter colors ends up doing the same thing anyway.

                          So all is well.

                          (although I wish I could figure out how to change those line colors just to have the skill down but it doesn't matter I guess!)
                          Last edited by cclsys; 03-19-2009, 05:23 PM.

                          Comment


                            #14
                            Originally posted by cclsys View Post
                            I tried putting colorup in instead of Color.LightYellow but it didn't like that.
                            I also tried putting in opacityValue instead of 75 but it didn't like that either.
                            There is no reason why 75 works as an parameter but an integer variable does not, same for Color.LightYellow. Is the compiler complaining about it? What is the error message?

                            Regard
                            Ralph

                            Comment


                              #15
                              I have closed down Ninja for the night and will revisit tomorrow.

                              But after I used your code, I just have the Color.LightYellow or whatever in it, but then having added it to the Properties so it shows up in the Indicator Menu dropdowns once loaded, the display in there features the opacity number followed by the 3 rgb numbers.

                              One strange thing is that when you go into the Custom menu, though, some colors, like Blue, comes up Blue and you cannot then have the opacity number ahead of it. Other colours pop up the three rgb numbers and then ahead of those you add in the opacity.

                              Looks like there is another wrinkle in setting it up in the code for it to work properly. I'll check for that error message tomorrow.

                              Thanks again.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by yertle, Yesterday, 08:38 AM
                              7 responses
                              28 views
                              0 likes
                              Last Post yertle
                              by yertle
                               
                              Started by bmartz, 03-12-2024, 06:12 AM
                              2 responses
                              21 views
                              0 likes
                              Last Post bmartz
                              by bmartz
                               
                              Started by funk10101, Today, 12:02 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post funk10101  
                              Started by gravdigaz6, Yesterday, 11:40 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by MarianApalaghiei, Yesterday, 10:49 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X