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

MTF + Swing + Draw.Ray + CrossAbove

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

    #31
    Hello Amedeus,

    You can use N2 as the standard format string if you want specifically 2 decimals from your calculated number.


    The profit of a trade would be SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #32

      Hi Chelsea, Hi everyone

      Thank you, I meant to draw a text with the profit in .ProfitPoints unit, not .ProfitCurrency unit.
      ultimately it would show a 2 decimal with 00, .25, .50, .75 for the ES for example, or maube a 1 decimal like .1, .2, .3 for Russell or Gold.
      This can be done by calculation with execution.Price. I'd have taught lastrade.ProfitPoints would do that but it shows too many decimals.

      **

      Back to our Swing,
      (Before totally moving on another copied Swing for MTF adaptation and tests)

      we are trying to spot multiple Swing points of the one and only NT Swing, but of different strenght, on one and single frame only.
      The point is to check that strenght.3x of CurrentBar[period.y] matches strenght.1x of CurrentBar[period.3y].
      A positive result would confirm the possibility of multiplying the swings and their strenght (not input) instead of multiplying the dataseries,
      if by any chance we are trying to spot swings of multiple degrees of importance.

      caution not to confuse the copy of the SingleDotSwing (aaaaaSdSwing) applied on charts for visual comaparison with the strategy, with NT Swing applied in the strategy.
      caution not to confuse the small dots of the aaaaaSdSwing with the Draw.Dot objects we will use to spot Swing points.

      The issue is : the Lime Dots do not appear in the pictures called 250.

      The consequently other issue is : in the pictures called dataS1LookB we tried to level up the Lookback power,
      but an out of range error appears
      , attached is the output of that.

      (btw, any comment on the CurrentBars check is very much welcome,
      the idea is to have a reference period of dataSeries1 and a minimum lookback of 250 as a mesure of "data range safety" for the check)

      what could we do to deliberately draw a lime dot where the aaaaaSdSwing dots are on X/Time axis ?
      any print idea to outlight something ?

      Also in the output, we marked in yellow some strange occurence : when BiP is 2, CurrentBars[0] is less than whan it was BiP 1...
      Is this allright ? could it not be related ? what does that mean ?

      IMO, as intended in this sample, CurrentBar[0] count should ALWAYS equal CurrentBars[1] count.

      as shown in an extra attachment, we are set as MaximumBarsLookBack.Infinite.
      Attached Files
      Last edited by Amedeus; 07-22-2021, 09:54 AM.

      Comment


        #33
        Hello Amedeus,

        Your inquiry is about SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitPoints specifically?

        The decimals are likely due to floating point arithmetic and the way computers store numbers.


        You can round this to a tick size if you would like.



        If dot is not appearing at all, on the bar number it is drawn on at the price is its drawn at (and also does not appear in the Drawing Objects window), I would expect that the method wasn't called.
        Do you have a reduced script that only draws that object with no other code to demonstrate the issue?


        Drawing objects are shown on the primary series only, which is the series creating the slots on the chart (manually added series are not picked up by the script).
        Using Draw.Dot() this will only appear on the primary bar its time is within.

        You can do your own custom calculations to estimate where time between bars would be, and custom render between bars or anywhere on the chart.



        The CurrentBars values are going to be updating independently for each added series. I would not have any expectation of the CurrentBar value of one series being related to another series.
        For each independent series, I would be expecting the bars to be showing the close time of the bar and updating sequentially.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #34
          Hey Chelsea, thanks,

          we are trying to draw only on the primary,
          the MTF caracteristic of the last sample was too much, it has been removed.

          yet we find a outside the bounds of the array error with this sample (attached pic) :
          it contains the only condition we are looking at.

          Which array could it be ? We can't say we haven't checked the price series array. Can we ?
          remains the swing highs series array... what's the trick there ? we want Swing(63) to show the last swing : SwingHighBar(int barsAgo 0 , int instance 1, int lookBackPeriod enough)...

          Attached Files

          Comment


            #35
            Hello Amedeus,

            What specific line is causing the error?

            Is it the print?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #36
              Hey Chelsea,

              of course it was the print. Thank you. This last mini sample works fine.

              The previous still hides the lime dots.
              yet,two times in a row, the copy of the previous immediately shows the dots : two exact copies applied after 1st compilation, while the previous (copied from / from post#32 ) still hides the dots...
              We are going to let that go and keep going with the new, working as expected one. (we report it only in case it rings a bell)

              In the picture attached, we can see that multiple swings can be applied at the same time on a primary.
              Minor discrepancies are to be expected.
              overall, the looks are good.

              A major downside to using multiple swings like this, is that it is slowing down the chart a good lot. (50 days of data in this example)
              This slow down is reduced to almost nothing as soon as we comment off the 12 non global dots of this test.

              We remember earlier this thread, the global Draw.TriangleUps used to show the executions.
              These global triangles were a huge lot more in number, but they did not cause such a slow down as the few non global dots did.

              We understand that one object comes from an execution related somthing. Another object comes from an indicator calculation.
              But we cannot visualize the underlying mechanics behind that difference in dynamics.
              Would you mind trying to light out the causality behind this ? or just pointing it out.

              If AddchartIndicator() is involved, as mentioned earlier, I dont see why : are we not saying to the strategy, to draw the dot at the location it knows from the swing High series ?
              Similarily to when we did say the strategy to draw a triangle at the execution. (globally ! many more)
              Attached Files
              Last edited by Amedeus; 07-22-2021, 02:14 PM.

              Comment


                #37
                Hello Amedeus,

                Chelsea is out of the office at this time, but I may shed some light on performance impact using draw objects in large numbers. Execution markers are not exactly the same as a Drawing Object and these are also different from indicator plots, which are essentially one object. (The Swing indicator uses 2 plots with a style Dot.)

                We can have performance impacted on the chart if there are Drawing Objects or Execution markers on the chart that are in excess. (If a strategy is programmed to go long and go short on each tick, and then we view the execution markers on a 60 minute chart, we can see that the execution markers do slow the chart down.) It is also possible to have slow down with too many plots, but this is not as common since plots are rarely used in as high of numbers as Drawing Objects.

                The solution to draw objects on a chart in high numbers would be to use SharpDX rendering as opposed to using Draw methods which create regular draw objects. This ensures only the drawing is made instead of creating individual objects that have their own rendering routines. I have attached an example that can demonstrate using SharpDX for purposes we would use with regular Draw methods.

                To get more acquainted with SharpDX rendering, please see the Help Guide article below, and please see the SampleCustomRender indicator that comes with NinjaTrader.
                https://ninjatrader.com/support/help..._rendering.htm

                Let us know if there is anything else we can do to help.
                Attached Files
                JimNinjaTrader Customer Service

                Comment


                  #38
                  hey Jim, thanks a lot,

                  I meant it more like what's the difference in paths of the information, from the script line using draw, to the late loaded chart.
                  Also the preformance was not that much impacted by the big number of global triangles on the executuions, but it was highly impacted by just a dozen of dots.

                  allright however, since the strategy shoud be more efficient if we add drawings with OnRender, instead of with the Draw method,
                  we are giving a shot at rendering dots and triangles up and down. Only for testing purposes.
                  if that's quick and easy, we might even try it out for the swing projections. (a few unseccessfull tests of coordinating the projection lines allready, but dots are the priority for our swing tests, we'll do lines later eventually)

                  We shall use our swing projection sample from this thread to do that.

                  it should mean one series ffor each drawing type.

                  In the previous sample about executions, the challenge resided in the multiplication of the orders : deducing what needs to be duplicated in the script and what does not.
                  The same sample with 2 orders would have been a child's play. The intricacies between things would immediatly show up.

                  In this OnRender case, the level is a lot higher. Even if we can see that this is simplifeid for an easy placement of the OnRender object call, from the conditions..

                  Would you help us create the second example series ?
                  We started with one ellipse but a dictionary error shows.
                  we don't have a clue if it is either simply because the Y of the dot is not clear, or maybe a void has not been copied or is too much..

                  The conditions for the OnRender object to show are the same : on the long execution (from OnExecution), where the the vertical lines are.

                  Do these attachments help us to see what's missing ?
                  the error message names the strategy an indactor.. that's intriguing.
                  Attached Files
                  Last edited by Amedeus; 07-24-2021, 06:35 AM.

                  Comment


                    #39
                    hey again,

                    the error was solved by duplicating the opacity property.

                    attached is a screenshot with 2 questions :

                    I am unable to adapt the price per bar (entry spot).

                    Also the DrawLineSerie1 (blue line) is showing every now and then.
                    it is supposed to connect the last 2 swings and that's it.
                    the line appears when :
                    DrawLineSeries2[0] = true;
                    if (DrawLineSeries2[0] )
                    DrawLineSeries2[1] = false;

                    Why do the dots not appear on executions ?
                    and is this thr right way to have only the 2 last swings connected ?
                    Attached Files
                    Last edited by Amedeus; 07-25-2021, 11:59 AM.

                    Comment


                      #40
                      hey again,

                      report :
                      the line now shows on the swing spots only, after placing the code outside (BarsInProgress == 0).
                      attachment.
                      it's a great news, but unexplained.

                      also attached is a picture of what the projections of the swing can look like using OnRender()
                      and the sample that goes with.

                      Remain the rendered execution spot to adjust. Any idea how ?

                      **

                      this exercise made us thinking about the mtf swing. (that we've been looking at for a few days now..)

                      what's the difference between the SwingHigh and SwingHighPlot series ? wich is a instancr, which isn't ? what's their family of object ?

                      from what we can grasp,the Addplot from the Swing is a problem for a mtf adaptation. and it is highly related with the SwingHighPlot.

                      Could we transform one of the SwingHigh or SwingHighPlot into one of the voids that we did with the OnRender sample.
                      Wich one would it be ? and why
                      I still don't really get the difference between the different voids that we did with this last sample, can we not repertoriate the doubles without the AddPlot part of it ?
                      Attached Files
                      Last edited by Amedeus; 07-25-2021, 04:58 PM.

                      Comment


                        #41
                        Hello Amedeus,

                        Where you have mentioned:
                        "Remain the rendered execution spot to adjust"
                        I'm exactly sure what this means.. Are you trying to get execution information from OnExecution and render these yourself in OnRender() instead of allowing NinjaTrader to render the arrows and profit / loss lines?
                        Are you trying to adjust the x or y value of a rendered object?

                        In the Swing indicator included with NinjaTrader, The SwingHigh is a plot series added with AddPlot() which generates Values[0] and plots on the chart. SwingHighPlot is a public series that returns Values[0] so this can be shown in the Strategy Builder Value plot selection and to be called from host script such as another indicator or strategy.

                        I'm not familiar with the word repertoriate.
                        AddPlot() adds a plot that is rendered on the chart. If you do not want a rendered line or histogram on the chart, you can use a private Series<double> instead of AddPlot().
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #42

                          Hey Chelsea, thank you,

                          Are you trying to get execution information from OnExecution and render these yourself in OnRender()
                          Absolutely.
                          execPrice (from post #39 attachment) is a double defined in OnExecution(). Converted in pixels in OnRender().
                          The DrawSeries is applied in OnExecution().

                          instead of allowing NinjaTrader to render the arrows and profit / loss lines?
                          it was meant in the case of a non-mtf-swing strategy, to have a look at historical executions, since it could not be applied on secondary frames.
                          But we realized since then, that OnRender() can't do Global anyway. So, in the case of a non-mtf-swing, Draw.markers would be the option.
                          NT execution markers would be 1st choice in the case of a mtf-swing strategy.

                          Are you trying to adjust the x or y value of a rendered object?
                          yes .
                          We are trying to render ellipses on each entry, like a Draw.TriangleUp would do for a long execution in OnExecution().
                          Is this not possible unless creating an index of historical execution prices ? OnRender() seems to only have the last execution in mind.


                          Repertoriate is not a word, thank you very much, it would have meant "do an inventory" if it were.
                          "to index the doubles without the Addplot part of it" would have been appropriate.
                          Did you switch SwingHigh and SwigHighPlot in your explaination ?
                          SwingHigh looks public, SwingHighPlot looks private.
                          SwingHigh is not declared like the other series in the declaration zones, only at the end.
                          Attached Files
                          Last edited by Amedeus; 07-26-2021, 12:42 PM.

                          Comment


                            #43
                            Hello Amedeus,

                            As a heads up, do not call Draw methods in OnRender(). This is custom rendering only and not where you should call Draw methods.
                            Call Draw methods in OnBarUpdate() or OnOrderUpdate(). Just not in OnRender().

                            When custom rendering, if you want a x value for a bar use ChartControl.GetXByBarIndex().


                            If you want a y value for a price use <chartScale>.GetYByValue().


                            Your screenshot is not showing SwigHighPlot.
                            This is defined on line 356 in the #region Properties.

                            You have drawn a yellow line next to swingHighSeries which is an internal private series used for calculations.

                            What do you want an inventory of?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #44
                              hey Chelsea and everyone, thank you very much,

                              We were not sure of the kind of inventary... /index.
                              It was in fact about keeping the SwingHighSeries needed in the calculation of the swing,
                              nevermind, it looks like we've been successfull at this. (pictures attached). Doing as indicated, thanks again.

                              We've been working, doing some adjustements to our sample and to a copy of the swing.
                              We did cut the Addplot for a double series and did do the same with SwingHighPlot.

                              Following what we understood from post#12,
                              we also duplicated the Functions SwingHighBar and SwingLowBar, in order to have 2 Swings :
                              one in (BarsInProgress == 0) the other in (BarsInProgress == 1).
                              This implies duplicating all variables, unless we disagree that it does.

                              Yet as we can see on the chart, when applied on a higher frame (270 ticks), the lime dots make no sense.
                              These lime dots are rendered from the strategy.
                              The variables used are from the (BarsInProgress == 1) (90 ticks) calculation of the swing, and the added Functions.
                              The 90 tick chart confirms that OnRender dots and lines are set up properly.
                              On the 270 chart, the lime dots should stay where the 90 tick secondary would be/is, instead of showing up where they are.

                              We tried to screenshot an overview of the code of the modified swing indicator.
                              We suspect it is enough to spot why the indicator still only talks about the primary dataseries to the strategy.
                              But also is attached a .txt of it, for details.

                              Would you mind indicate to us what we still miss about the strategy-Swing dataseries communication.
                              Why the strategy sill can't catch the secondary Swings values.
                              Are the functions not handled correctly ?
                              (btw, what about the string of the exceptions ? is doing this ok ?)
                              Attached Files

                              Comment


                                #45
                                5 attachments tops.
                                here is the chart going with post #44
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by alifarahani, Today, 09:40 AM
                                6 responses
                                36 views
                                0 likes
                                Last Post alifarahani  
                                Started by Waxavi, Today, 02:10 AM
                                1 response
                                17 views
                                0 likes
                                Last Post NinjaTrader_LuisH  
                                Started by Kaledus, Today, 01:29 PM
                                5 responses
                                14 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by Waxavi, Today, 02:00 AM
                                1 response
                                12 views
                                0 likes
                                Last Post NinjaTrader_LuisH  
                                Started by gentlebenthebear, Today, 01:30 AM
                                3 responses
                                17 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Working...
                                X