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

Capture Stroke values and duplicate into Plot values

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

    Capture Stroke values and duplicate into Plot values

    Objective:
    Produce plot values readable by the data box from an existing indicator which displays the values on the chart but not are available as plot readable data; i.e. invisible to the databox...


    Special note to NinjaTrader_ChelseaB: Your conversion of the IG market profile indicator [ https://ninjatraderecosystem.com/use...marketprofile/ ] is first class .
    I have tinkered with the code using several of my usual go-to's to display the desired values and have failed.


    I have already added [new] plots and properties in their correct format, just need to know what to add to the existing desired statements. Here's one for example:


    ************************************************** ************************************************** ************************************************** **********

    private void DrawPOC(MPHelper helper)
    {
    if (DrawPOCBool)
    {
    Draw.Line(this, "POC" + helper.CurrentIndexString,
    IsAutoScale,
    helper.POCStartBar,
    helper.POCPrice,
    helper.POCStartBar >= helper.POCEndBar ? helper.POCEndBar : 0,
    helper.POCPrice,
    POCStroke.Brush,
    POCStroke.DashStyleHelper,
    (int)POCStroke.Width);​​

    ​************************************************* ************************************************** ************************************************** ************

    In this case, the value I wish to plot is the POC.
    Again, Tried a variety of code-sets and have failed. Where me go wrong??

    Thanx
    JM

    #2
    Hello johnMoss,

    Thanks for your post.

    If you would like to add a plot to a script that uses a Stroke parameter, you could use the AddPlot() overload below that lets you specify a Stroke parameter. Then, you could assign a value to the plot by using Values[0][0] = X, where 'X' is the value that you want to assign to the plot.

    AddPlot(Stroke stroke, PlotStyle plotStyle, string name)

    See the first and second sections of sample code on the help guide page below which demonstrates using this AddPlot() syntax.


    If you do not want plots to be visible in the Data Box window, you could set DisplayInDataBox to false in the State.SetDefaults section of OnStateChange().

    See this help guide page for more information and sample code: https://ninjatrader.com/support/help...yindatabox.htm

    Let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Perfect. Thank you Brandon ...

      Comment


        #4
        OK, I have worked on this for a while attempting a multitude of code configurations but it isn't working. The example provided [on examination and viewing subsequent further links] don't appear to apply completely to what I'm up to here. The indicator in question is attached. Is not a definition for 'POCStroke' not already created in the Change & Defaults configs? If coded up per instruction it won't compile, as it is asking for a definition...

        ************************************************** ****************************
        From the indicator attached here:


        POCStroke = new Stroke(Brushes.Blue, DashStyleHelper.Solid, 5);

        ************************************************** ****************************


        ************************************************** ****************************
        Specifically as assumedly called for to convert POCStroke:

        AddPlot(Brushes.Transparent, "POC");
        AddPlot(Stroke.POCStroke, PlotStyle.Line, "POC");

        ************************************************** ****************************

        yields a compile error.

        I've attempted this in a variety of alterations including single line constructs, several of which did compile, but did not yield databox values...

        I appear to be faltering on establishing a proper definition for the string??

        Thanx
        JM

        Attached Files

        Comment


          #5
          Hello johnMoss,

          Thanks for your note.

          I have manually imported the indicator you shared and tested it on my end. I did not receive any compile errors when compiling the indicator. However, I did encounter a runtime error when enabling the indicator on a chart. The error indicated that "Added Plots or Lines must have a unique name."

          When looking at your shared script, I see that you added two plots to the script using AddPlot() and both plots contain the same name "POC".

          To avoid this runtime error, you would need to give each plot in your script a unique name. For example, plot 1 could be called "POC1" and plot 2 could be called "POC2".

          Then, you could assign a value to the plot. Based on the code you shared in your initial post, you could assign the POCPrice to the first added plot (POC1) by calling Values[0][0] = helper.POCPrice.

          Code:
          private void DrawPOC(MPHelper helper)
          {
          if (DrawPOCBool)
            {
              Draw.Line(this, "POC" + helper.CurrentIndexString,
                IsAutoScale,
                helper.POCStartBar,
                helper.POCPrice,
                helper.POCStartBar >= helper.POCEndBar ? helper.POCEndBar : 0,
                helper.POCPrice,
                POCStroke.Brush,
                POCStroke.DashStyleHelper,
                (int)POCStroke.Width);​​
          
              Values[0][0] = helper.POCPrice;
          
          ...​
          Let me know if I may assist further.
          Last edited by NinjaTrader_BrandonH; 09-28-2022, 09:31 AM.
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            Thank you Brandon,

            Referring to your last correspondence, what I had done is follow the instructions [ and subsequent linked articles] from your first response. I had just commented everything out and left it there for the moment . I may need to revisit them to resolve a final issue.

            In review, what I'm actually up to is to be able to access 5 primary values of interest [POC, VAL, VAH, IB Low, and IB High] from the indicator which I can access inside strategy builder (SB).

            As a general rule, If one can get the databox to display a desired value it then becomes accessible to the SB. In the current construct attached, I've accomplished this with three of the 5 items I'm after, and will finish the other two in continuance...

            The remaining issue now is a compilation error in SB I'm not sure how to resolve. I have attached the current indicator construct here to see if something immediately obvious to you is in play.
            As a quick test, I built a simple crossover strategy just to see if it would fire an entry. But it won't compile.

            Specifically, when attempting to compile the strategy, an error is generated:

            'Ninjatrader.GUI.Stroke' is a 'type', which is not valid in the given context (Line 62 in the strategy)

            Am I perhaps missing an item in the indicator declarations that I now need to add?

            Current Indicator IGMarketProfile and failed strategy IGStrat are attached.


            ********** Added code is commented with my initials for easy spotting; 1st set begin at Line 150, 2nd set begin at Line 656, 3rd set begin at Line 1809. **********

            Thanx

            JM








            Attached Files

            Comment


              #7
              Hello johnMoss,

              Thanks for your note.

              This compile error message indicates that an incorrect parameter is being used when calling IGMarketProfile().

              Since a Stroke parameter is required when calling IGMarketProfile(), you would need to create a Stroke variable and assign a value to the variable. This variable could be used for the Stroke parameters when calling IGMarketProfile.

              For example, if you create a Stroke variable called MyStroke, you pass that in as your Stroke argument when calling IGMarketProfile().

              Code:
              protected override void OnStateChange()
              {
                if (State == State.SetDefaults)
                {
                  IsOverlay = true;
                  // set the Stroke default to red brush
                  MyStroke = new Stroke(Brushes.Red);
                }
                else if (State == State.Configure)
                {
                }
                else if (State == State.DataLoaded)
                {                
                  IGMarketProfile1 = IGMarketProfile(Close, 8, Brushes.Fuchsia, true, true, true, true, false, true, true, true, DateTime.Parse("3:16 PM"), DateTime.Parse("8:29 AM"), Brushes.Transparent, Brushes.Transparent, Brushes.Transparent, Brushes.Red, Brushes.Blue, 10, 80, 2, 4, IGMarketProfileEnums.SessionType.RTHAndETH, Brushes.Lime, false, MyStroke, MyStroke, MyStroke, Brushes.Black, 80, Brushes.Yellow, Brushes.LightCoral, Brushes.LightGreen, DateTime.Parse("8:30 AM"), DateTime.Parse("3:15 PM"), true, Brushes.LightGray, IGMarketProfileEnums.ColorMode.EachLetterDifferentColor, new SimpleFont("Arial", 10) {Bold = false, Italic = false}, Brushes.LightGray, new SimpleFont("Tahoma", 8) {Bold = false, Italic = false}, 50, 4, 30, 68, MyStroke, MyStroke, MyStroke, Brushes.Black, MyStroke);
                }​
              }​
              
              [NinjaScriptProperty]
              [Description("My Stroke")]
              [B]public Stroke MyStroke[/B] { get; set; }​
              See this help guide page for more information about the Stroke class: https://ninjatrader.com/support/help...roke_class.htm

              Let me know if I may assist further.
              Last edited by NinjaTrader_BrandonH; 09-29-2022, 01:45 PM.
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                Thank you, I see how that would work but I need to build this property inside the indicator itself. I am super fond of using the strategy builder (SB) as it is so much more efficient to set & reset conditionals...

                Point being what do I need to do to the indicator itself so to make it workable inside the SB without having to modify the strategy each time in the Editor?

                I had assumed creating the plots would do just that, as they heretofore always have. Hence I've called the correct plot from the SB Condition Editor... Just haven't run into this before...

                Thanx

                Comment


                  #9
                  Hello johnMoss,

                  Thanks for your note.

                  Unfortunately, it would not be possible to use this indicator in a Strategy Builder strategy since it requires multiple Stroke arguments when calling the indicator. Stroke parameters cannot be used in the Strategy Builder.

                  You would need to manually code the Stroke parameter into an unlocked strategy as seen in post # 7. Or, you could consider modifying the logic of the indicator so that it uses Brushes instead of Stroke parameters throughout the script.

                  Working with Brushes: https://ninjatrader.com/support/help...th_brushes.htm

                  Please let me know if I may assist further.
                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    I'll give that a shot. Thank you sir...

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by timmbbo, 07-05-2023, 10:21 PM
                    3 responses
                    150 views
                    0 likes
                    Last Post grayfrog  
                    Started by Lumbeezl, 01-11-2022, 06:50 PM
                    30 responses
                    804 views
                    1 like
                    Last Post grayfrog  
                    Started by xiinteractive, 04-09-2024, 08:08 AM
                    3 responses
                    11 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by Johnny Santiago, 10-11-2019, 09:21 AM
                    95 responses
                    6,193 views
                    0 likes
                    Last Post xiinteractive  
                    Started by Irukandji, Today, 09:34 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Working...
                    X