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

Coding opacity

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

    Coding opacity

    I have an indicator which allows the coloring of regions between a variety of moving averages. I have customized this as follows (e.g. here going long):

    if (this.BreakOut)
    {
    DrawRegion("Region1" + this._intStartBar.ToString(), CurrentBar - this._intStartBar + 1, 0, Plot1, Plot2, Color.Empty, up_Color, up_Opacity);
    }

    whereby "up_Color" and "up_Opacity" are user definable. Works beautiful but ...

    I would like to change this using "Color.FromArgb" as that would allow an even more fine tuned coloring of the regions.

    I tried this:
    {
    DrawRegion("Region1" + this._intStartBar.ToString(), CurrentBar - this._intStartBar + 1, 0, Plot1, Plot2, Color.Empty, Color.FromArgb(up_Opacity, up_Color));
    }

    but then got the error message that DrawRegion takes 7 arguments.

    I then tried this:

    {
    DrawRegion("Region1" + this._intStartBar.ToString(), CurrentBar - this._intStartBar + 1, 0, Plot1, Plot2, Color.Empty, Color.FromArgb(up_Opacity, up_Color), up_Opacity);
    }

    which works but with Opacity levels from 1-5 only, not 1-255.

    Help please.

    How do I properly incorporate this Color.FromArgb into the DrawRegion command.

    sandman

    (PS: I am not really programmer but work by looking at other indicator codes and then with trial and error to make it work for what I want.)

    #2
    Hello sandman,

    Thank you for your inquiry.

    Please take a look at the NinjaTrader help guide at this link for more information about DrawRegion(): http://ninjatrader.com/support/helpG...drawregion.htm

    You will want to specify the opacity in areaOpacity rather than the alpha channel in Color.FromArgb.

    You will notice that the areaOpacity parameter has a valid value from 0 (completely transparent) to 10 (no opacity).

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ZacharyG View Post
      You will want to specify the opacity in areaOpacity rather than the alpha channel in Color.FromArgb.

      You will notice that the areaOpacity parameter has a valid value from 0 (completely transparent) to 10 (no opacity).
      It appears you did not understand my question, or else I did not clearly enough state what I am after.

      Yes, indeed I have noticed that. THAT IS WHAT I HAVE ALREADY and it is working just fine. I wrote this inquiry to find out how to switch from what you call area opacity to alpha channels because that opens the range of opacity settings from a mere 1-10 to
      1-254. I am already using 1-10 and am now interested to get to use 1-254.

      My question is how to do that i.e. how do I properly incorporate this Color.FromArgb into the DrawRegion command? Perhaps DrawRegion is the wrong command to be able to use Color.FromArgb. If so, what needs to be used to be able to utilize Color.FromArgb?
      I am asking because that is not explained in the reference you cited and which I had studied already.

      sandman

      Comment


        #4
        Hello,

        Thank you for the reply.

        When using the DrawRegion it will override the alpha you set with the FromArgb and only allows for a 0 - 10 value, setting alpha in FromArgb produces the same result no matter what the alpha you set is in this case.

        For more fine control over drawing on the chart you would likely need to use the Plot override which allows you to create custom drawings. This is a fairly advanced subject when trying to do what you would need to do as you would need to convert bar and price values into X and Y coordinates using this method. You would also need to draw a custom shape with the points of both series. This would not be something we could directly support as this would be a fairly complex item although there are a few samples included with NinjaTrader if you want to look into it. Those samples are the CustomPlotSample and the Pivots indicator.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by sandman View Post
          It appears you did not understand my question, or else I did not clearly enough state what I am after.

          Yes, indeed I have noticed that. THAT IS WHAT I HAVE ALREADY and it is working just fine. I wrote this inquiry to find out how to switch from what you call area opacity to alpha channels because that opens the range of opacity settings from a mere 1-10 to
          1-254. I am already using 1-10 and am now interested to get to use 1-254.

          My question is how to do that i.e. how do I properly incorporate this Color.FromArgb into the DrawRegion command? Perhaps DrawRegion is the wrong command to be able to use Color.FromArgb. If so, what needs to be used to be able to utilize Color.FromArgb?
          I am asking because that is not explained in the reference you cited and which I had studied already.

          sandman
          You have already done it. Just lock the last parameter to the maximum value.
          Code:
          DrawRegion("Region1" + this._intStartBar.ToString(), CurrentBar - this._intStartBar + 1, 0, Plot1, Plot2, Color.Empty, Color.FromArgb(up_Opacity, up_Color), [COLOR="Red"][B]10[/B][/COLOR]);

          Comment


            #6
            Jesse. I was afraid that something like yours would be the answer. Ah well, more study to be done. Thanks in any case that you got this clarified. Meantime I figured out that while this 1-255 opacity level does not work with Drawregion, it works beautifully with BarColor and BackColor:

            BarColor = Color.FromArgb(upOpacitylevel, upColor);
            BackColor = Color.FromArgb(downOpacitylevel, downColor);

            sandman

            Comment


              #7
              koganam.

              I received your 2nd message that the 1-255 (Color.FromArgb) does work with DrawRegion() by locking the last value which in your message you had set to "10". While that works it limits the choseable opacity range to 1-10. Which is what Jesse had said (using the DrawRegion will override the alpha you set with the FromArgb and only allows for a 0 - 10 value).

              But what I want is to be able to chose between 1-255. I tried a variety of things but could not get it to work. It could be that it was not clear what I am after but if there is way to use this alpha opacity with levels between 1-255 with DrawRegion() then perhaps you could look over the code I have. For that reason I have attached the indicator (Test) which I have. Looking forward to hearing back from you.

              sandman
              Attached Files

              Comment


                #8
                Hello,

                For DrawRegion specifically there would be no way that I am aware of because it is specifically overriding the colors alpha that you insert with its own alpha because that is a property of DrawRegion.

                The only way I do know that you could draw a Region that has full opacity or alpha control, would be to use the Plot Override which would be much more complicated. That would be because you would have to write logic comparable with what the current DrawRegion is doing regarding creating a custom shape between points in two sets of data.

                For this I believe in NinjaTrader 7 there would be no way to use DrawRegion and get a full 255 alpha color, instead the Plot Override would need to be used.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by GussJ, 03-04-2020, 03:11 PM
                11 responses
                3,221 views
                0 likes
                Last Post xiinteractive  
                Started by andrewtrades, Today, 04:57 PM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by chbruno, Today, 04:10 PM
                0 responses
                6 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by josh18955, 03-25-2023, 11:16 AM
                6 responses
                436 views
                0 likes
                Last Post Delerium  
                Started by FAQtrader, Today, 03:35 PM
                0 responses
                9 views
                0 likes
                Last Post FAQtrader  
                Working...
                X