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

adjustable plot opacity - what am i missing ?

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

    adjustable plot opacity - what am i missing ?

    trying to make an indicator who's plot opacity can be changed... i've read everything i can find on this site but to no avail... this one's behavior is nuts...
    when the indicator is placed on the chart the opacity of the plot is as the indicator is written when it was placed on the chart and no changes can be made to the opacity afterwards...
    here's a 5min kama that i use on 1min and volume charts

    the only success i've had in getting any opacity control was after seeing a comment suggesting put the PlotOpacity variable in the "Plots" group but still no ability to change the indicator once placed other than change the source code, recompile and place the indicator...

    (LOOKS LIKE I CAN'T INCLUDE A CHART TEMPLATE-but here's the essentials) i've included a chart template that has two incidents of the indicator placed - using the same color - the 30% opacity indicator was placed with the stroke hard coded and the 80% was placed with the stroke variable coded (PlotOpacity) and they retain their respective opacities when placed on a fresh chart but the opacity of either cannot be changed with the indicator coded and compiled with a variable definition for opacity in the Stroke of the plot definition..
    Attached Files

    #2
    Hello stafe,

    The user can adjust opacity in the Plots section in the Indicator properties window.

    Below is a link to a video demonstrating using hexidecial rgba values in property windows.


    From code, you would need to create a new brush with opacity and assign this to the Plots[0].Brush.

    private brush myBrush;

    [XmlIgnore]
    [Display(Name = "Evolving VAb Color", Order = 8, GroupName = "Display Settings")]
    public Brush MyBrush
    {
    get { return myBrush; }
    set
    {
    myBrush = value;
    if (myBrush == null)
    return;

    if (myBrush.IsFrozen)
    myBrush= myBrush.Clone();

    myBrush.Opacity = PlotOpacity / 100d;
    myBrush.Freeze();

    Plots[0].Brush = myBrush;
    }
    }​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thanks for getting back,
      check my work, but i'm not getting any control of the plot color other than what is set in the regular dialogue for "Plots"
      i'm attempting to plot a fat pink line at 65% opacity or 166,256,192,203 which seems do-able by selecting Pink for "Evolving VAb Color" and 166 or 65 for opacity...
      if i set Plots color to transparent - it's transparent regardless of how the "Display Parameters" parameters are set...
      can't get any control of opacity... i removed the stroke definition and just used the simplest AddPlot(KamaBrush, "Kama5min"); possible... thus a default to black and 1 point line... i also removed all indicator templates for this indicator to make sure nothing would be coming from that direction
      Attached Files

      Comment


        #4
        Hello stafe,

        Apologies the Plots object is not populated when the script is being reloaded until State.DataLoaded, while this input would be attempting to set the plot brush before that.

        Instead, try setting Plots[0].Brush = myBrush; in State.DataLoaded (but keep the rest of the code in the setter the same).
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          in that form the plot color now selects from the custom color input (unlike before ) and the plot thickness, dash and line style select from the plots definition input but still no opacity control with the PlotOpacity variable... i changed the name of the custom color input to "Color VariableOpacity"...
          when the PlotOpacity set is in the Properties section is that read only when the indicator is refreshed as in F5 ?
          should i define AddPlot using a Stroke instead of simple ? not sure where AddPlot runs in relation to Properties

          just tried using an AddPlot with a Stroke definition and it picked up everything correctly only the first time the indicator was placed but, like before, opacity could not be altered successfully even though when a different color for "Color VariableOpacity" was selected the plot changed color but kept the original density set when it was first placed... it's just not picking up a new opacity value but at least now it will change color -- however the plot definition color preview doesn't update to the new color with old opacity ... that's kind of different...

          another note after tinkering... with AddPlot including a stroke the opacity is set by the value that is coded into the indicator on the Parameter line for PlotOpacity and this is the opacity that the plot is stuck with until removed, code is adjusted and indicator is placed afresh with new desired opacity... essentially the same behavior as before with the only difference being the color can be changed through "Color VariableOpacity"
          Attached Files
          Last edited by stafe; 04-17-2024, 03:49 PM.

          Comment


            #6
            Hello stafe,

            Try setting the Opacity directly in State.DataLoaded.

            Plots[0].Opacity = PlotOpacity;
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              PERFECT !!! thanks...
              one last question -- if i wanted to change a plot opacity conditionally would i be better off using sharpDX for the plot rendering ? i'm guessing sharpDX would use less resources, ie faster ?

              Comment


                #8
                Hello stafe,

                If its a plot, it's being rendered by NinjaTrader behind the scenes.

                But if you wanted to draw your own shapes in OnRender() you are free to do so.

                All drawing tools do the rendering in OnRender(), but if there are multiple drawing objects, its faster to render these in a single script to prevent the overhead of adding and updating many script classes.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  how do i make the "Color Variable Opacity" color persist between session breaks? i thought it had something to do with XMLignore but all my other custom brushes are set up with it...

                  Comment


                    #10
                    Hello stafe,

                    Testing with the Playback connection, I'm not seeing that the color changes after a session ends and another session begins.

                    Do you mean you are reloading the script? If so, you may need to override the Clone method.

                    Below is a link to an example.
                    I have a button on the toolbar that I want to use to toggle a plot to visibile/show to invisible/hidden;.... I can do this in NT7 but NT8 seems to store the latest Brush in the Chart Parameters...NT7 didn't do this? I can set the plot brush to Transparent dynamically (hidden), but then how do I get it to Show again? (for the
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      i'm sorry, i wasn't clear, session break meaning closing the program, then restarting the program next time, the color setting goes back to the coded default... does the info above for overriding the clone of the brush take care of the color setting defaulting to coded color (gray) after a program restart? thanks
                      Last edited by stafe; 04-24-2024, 01:51 PM.

                      Comment


                        #12
                        Sorry ChelseaB, i'm not sure i'm following... the link you attached is for hiding and unhiding a plot it seems... the issue i'm having is the indicator loses the color setting for the new brush "KamaBrush" when i restart NinjaTrader after shutting down the computer... does the technique for overriding a cloned brush take care of the issue ? i was thinking the brush might need to be defined outside of parameters or something -- very novice in this respect...

                        Comment


                          #13
                          Hello stafe,

                          If you have a public property, and this is not using XmlIgnore(), it should be saved with the workspace. Are you saving the workspace?

                          The example is showing how to copy property values over the new clone (which is created when reloading the script).

                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            i noticed this issue when i opened a workspace i had closed the previous evening when i shut down the computer...
                            i was able to push on the problem this afternoon - - i closed all workspaces and the program, i deleted the _Workspaces.xml file in the workspaces folder so i wouldn't have anything load on startup for certain.. i then created a new 1min chart of the ES and added 3 instances of KAMAmin5 yellow/2,5,10 magenta/2,10,20 and pink/3,10,15 and set the opacities to 65... i then saved the workspace and closed it... and tried re-opening the workspace file but found no indicators plotting and the three indicators i had set with blank "KamaBrush" setting and a transparent Plot Color setting but maintaining their period variables and plot width,style and dash.style settings -- the same thing happens when saving a chart template... no errors in the log while saving or opening workspaces nor while saving a chart template ...

                            with Notepad++ i converted the chart template from an xml file to a .cs and it's named ""z test KAMAmin5_xml2cs"" the other file is the workspace xml file converted to a .cs file
                            Attached Files

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Torontobluejays, Today, 08:43 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post Torontobluejays  
                            Started by sastrades, 01-31-2024, 10:19 PM
                            12 responses
                            186 views
                            0 likes
                            Last Post sastrades  
                            Started by Jimmyk, 01-26-2018, 05:19 AM
                            8 responses
                            863 views
                            0 likes
                            Last Post emuns
                            by emuns
                             
                            Started by giulyko00, 04-24-2024, 12:03 PM
                            6 responses
                            29 views
                            0 likes
                            Last Post giulyko00  
                            Started by 00nevest, 04-27-2024, 02:27 PM
                            3 responses
                            27 views
                            0 likes
                            Last Post 00nevest  
                            Working...
                            X