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

Idea for study to plot an instrument chart sliced in cycles & in dollar change terms

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

    Idea for study to plot an instrument chart sliced in cycles & in dollar change terms

    Hello

    I need guide about a starting point to create a study or a kind of “indicator” to plot let’s say the ES (S&P future), but the plot need to be generated within 2 conditions:
    • The condition 1 is the chart plot be starting from 0 in a specified cycle, let’s say monthly cycle.
    • The condition 2 is the chart plot be in dollar change starting in $0 at the beginning of the defined cycle.

    Let’s put an example:
    Specifying and using the cycle called ‘Month’, it means the chart will show from Sunday to Friday the plot of the ES, starting in $0 on Sunday at the open market time, and after this the study will start drawing the chart just as the ES does, but the generated chart instead to be drawn as a standard chart, let’s say plotting:
    4,100.00
    4,100.25
    4,100.50
    4,100.25
    4,100.00
    4,099.75
    4,099.50


    Instead of that, the ES quote values the indicator would generate are the ES changes from the beginning of the cycle, just as a normal chart but not showing the real quotes, no, showing the tick dollar value changes:
    $0.00
    $12.50
    $25.00
    $12.50
    $0.00
    -$12.50
    -$25.00

    … and so on until the last tick at the end of the specified kind of cycle, in this case on Friday at the market close time.

    I don’t know how start to work with this, to take the ES quote, to specify that the chart be divided by cycles, like a kind of slices of the ES standard chart, then specify it need to start from $0 and after this keep plotting and drawing the chart but in terms of dollars change from the start point.

    I haven't seen anything similar to take it as a starting point and I would
    like to ask to the person that will give the answer, that please ask to the others coworkers in the development area to see if someone could provide maybe a template or any code portion with which I could start

    Thank you
    Last edited by futurenow; 05-03-2021, 12:01 PM.

    #2
    Hello futurenow,

    Thank you for your post.

    It's a little unclear exactly what you're looking for here. What it sounds like you're wanting is getting the netchange from an arbitrary starting point and plotting it, is that correct?

    You could use time checks or date checks to reset your "cycle" when you wish and set a private variable to 0 at each reset. You could then add the difference in prices divided by TickSize to that variable as more bars develop and plot the resulting values.

    I wouldn't have any examples that would be specific to this, however. If that's not quite what you're looking to do, can you provide a mockup of what you're looking for?

    Thanks in advance: I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your quick reply Kate,

      Originally posted by NinjaTrader_Kate View Post
      It's a little unclear exactly what you're looking for here. What it sounds like you're wanting is getting the netchange from an arbitrary starting point and plotting it, is that correct?
      I will attach 2 pictures for better understand the kind of result the indicator should show, just as example. But yes, I think "netchange" could be the keyword when I talk about “dollar change”. In the pictures you can confirm this. In this case, getting the netchange of ES from a defined specific staring point to an ending specific point, i.e. if the cycle is monthly (every month), then the cycle starts the first tradable day in the month and ends the last tradable day in that month.


      You could use time checks or date checks to reset your "cycle" when you wish and set a private variable to 0 at each reset. You could then add the difference in prices divided by TickSize to that variable as more bars develop and plot the resulting values.
      Now you see the attached pictures and having a better idea about the result, is there a thread, a template or any kind of starting point I could use to start to complete the code with the details I need?

      I tried going to https://ninjatraderecosystem.com/user-app-share/ but there are around 900 indicators, so if you or your coworkers could please provide that starting point it will be a light in the darkness for me In case you don’t remember any example, please ask to the developers if possible.


      I also made a search in https://ninjatrader.com/support/help...erence_wip.htm but I couldn’t find ‘time checks’ or ‘date checks’ to see some examples about how they work, because I haven’t seen or used them for now.

      A staring point could be the code portion, or even a more complete example or examples about:
      • How to set the instrument, in this example the ES future
      • How to convert the ES quote to netchange shown as dollar value, that it would be something like multiplying the ES tick moves per 12.50 to show the dollar value change in every moment, tick-by-tick in real time or in market replay.
      • And how to set the cycle specifying in the code if the cycle is ‘Month’, then start at the every tradable day when you find a new staring month, and then ends the cycle at the end of that month. Then reset the plot to 0 and do the same again with the next month, and so on.

      I’m still learning in the indicators development process, and normally once I obtain a guide, or example or starting point with some code portions examples, normally I’m able to continue, sometimes with help, some others times slowly, but improving step by step, so thank you Kate.

      Click image for larger version

Name:	Standard chart with comments.png
Views:	262
Size:	142.2 KB
ID:	1154673

      Click image for larger version  Name:	Chart based in Dollar change within cycles - 1.png Views:	0 Size:	97.5 KB ID:	1154539


      Click image for larger version  Name:	Chart based in Dollar change within cycles - 2.png Views:	0 Size:	200.1 KB ID:	1154538





      Last edited by futurenow; 05-04-2021, 05:00 PM.

      Comment


        #4
        Hello futurenow,

        Thank you for your reply.

        Just to be clear, in platform support, we do not create/write strategies, we do not provide debugging services. We also cannot provide programming education services. If you would like the strategy created for you, we can provide references to 3rd party programmers who could meet your needs.

        That being said, I usually suggest if you're not familiar with using DateTime objects to create time and date comparisons, that you set a few up in a Strategy Builder window and unlock the code to see how they are structured:



        This example from our help guide goes into how you can manipulate DateTime objects to use for comparisons:



        As we do not have any examples of what you're looking for, I will see if I can come up with a very basic example you can use for a starting point, however, this will not be completed today. Please note that the samples we provide are intended to give you further direction to move forward, and are not intended to be used for copy and paste purposes.

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thank you Kate

          As we do not have any examples of what you're looking for, I will see if I can come up with a very basic example you can use for a starting point, however, this will not be completed today. Please note that the samples we provide are intended to give you further direction to move forward, and are not intended to be used for copy and paste purposes.
          I just can say thank you for the example you talk about to use as starting point, and yes, I understand it can take time not being ready today.

          And about what you comment, yes, I understand what you explain, and my questions were just for that, to have an starting point with which to take some ideas and after that to be able to start to develop the concepts I could have in mind. For that reason I asked you to know if in any of your sites is there anything that could be used to take one or more ideas because I thought that among hundreds of indicators it could be something maybe not similar but that could show for example how is the process to take the quote data from a ticker (in this example the ES) showing how to work with this data in the way you need, in this case for example checking for each tick move and representing and plotting that in a chart in dollar value change (net change) instead of the ES current chart value that for example at this moment I see is 4,158.25.

          So, as after you could check the pictures with the mock-up idea you could confirm there is not examples about what I'm looking for, then I really appreciate you taking the time and dedication to provide an example as starting point.

          Just one final note, in the main question an extra picture is now submitted, just to see what would be the original standard chart form, from which the indicator would "convert" to the way I describe. In others words to better see what would be the original plain form a chart is shown, and then the "conversion" (if is the correct way to say this) the indicator would make and plot as result.

          Thank you very much

          Comment


            #6
            Hello futurenow,

            Thank you for your patience.

            I've created an example indicator that modifies the Candlestick Indicator Example from our publicly available User App Share found here:

            This is a sample of how to create an indicator in Candlestick (OHLC), which was tooked from the Spread Indicator with Candlesticks developed by kdoren and originally coded for the NinjaTrader 7 platform by NinjaTrader_AdamP.


            The version below is modified to show each bar's net change in price over a monthly span and resets to 0 at the beginning of each new month. You could modify this to use different reset intervals, perhaps weekly or per session. The linked indicator above is helpful for creating indicators you'd like displayed in a Candlestick type format.

            Please let us know if we may be of further assistance to you.

            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
            Attached Files
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Kate View Post
              Hello futurenow,

              Thank you for your patience.
              Thanks to you for taking your time and for the example you have created that it could useful for the other users too.



              I've created an example indicator that modifies the Candlestick Indicator Example from our publicly available User App Share found here:

              https://ninjatraderecosystem.com/use...cators-sample/

              The version below is modified to show each bar's net change in price over a monthly span and resets to 0 at the beginning of each new month. You could modify this to use different reset intervals, perhaps weekly or per session. The linked indicator above is helpful for creating indicators you'd like displayed in a Candlestick type format.
              I see the net change and the resets are working properly, as should, perfect! Thank you Kate! You are the best!



              Please let us know if we may be of further assistance to you.
              Yes, thank you. Now I’m analyzing something, there is a process I do manually and I think it could be more efficient if it is done directly by code. Ok, that process is I plot some overlaid symbols, for example 2 symbols like the ES and the CL, both in the same chart panel, and each one independently from the other, so basically what is called "overlaid". Well, what I actually do to get that result is to add the indicator twice and plot the resulting charts both in the same panel, which visually provides a good result but in fact what is running in the background is the same indicator twice and I would like to have the way to get that kind of plots with only 1 single indicator, because if I need 3 symbols then what is needed is an extra 3rd instance of the indicator, which is not efficient.

              I tried to search in the Ecosystem site but I couldn’t find any idea to use as base to start to work with:


              I will leave a picture to have a visual idea about the result I’m explaining for a 2 overlaid symbols example.

              Click image for larger version

Name:	Visual illustration - 2 overlaid charts (ES and CL).png
Views:	267
Size:	63.4 KB
ID:	1156705

              Comment


                #8
                Hello futurenow,

                Thank you for your reply.

                This wouldn't be possible as you can't plot in different scales from the same instance of an indicator. They'd all have to be on the same scale - one part couldn't be left justification and another part on Overlay justification. Your best bet would be to use an instance of the indicator for each data series and use the overlay function to overlay them on top of each other.

                Please let us know if we may be of further assistance to you.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9

                  Hello Kate! Thank you for your reply.

                  Originally posted by NinjaTrader_Kate View Post
                  This wouldn't be possible as you can't plot in different scales from the same instance of an indicator. They'd all have to be on the same scale - one part couldn't be left justification and another part on Overlay justification.
                  Ok, I understand your point, but for that a possible solution could be to plot all the data series in the same scale and justification, for example in this case all the symbols in “Overlay justification”. Let’s talk about a default chart example to finally try to arrive to the indicator situation, to see if we could find a solution having more details about the idea.

                  As you may know and as you can see in the first picture, you can add and apply multiple data series in a standard chart, in the picture is applied 2 Futures, ES and CL, both in the same time scale (60 min), both in the same chart panel, with the ES as the “main” or base plot and with the CL as a “secondary” plot overlaid over the ES chart, but in the indicator these could be treated basically as 2 independent plots but overlaid in the same chart panel.

                  Well, what I would like to have is a similar feature in the indicator where you can add 1, 2 or more data series (multiple ticker symbols: Futures, Stocks, ETFs), to be plotted in the same chart panel. I.e. having something similar as a default NinjaTrader 8 chart but in this case via the indicator, where you could select Ticker 1, Ticker 2, Ticker 3,… (less than 10 tickers/symbols), and about the resultant scale and justification for the indicator, they don’t necessarily have to be exactly as in the picture, because what is in the picture is just an approximate concept to have the base idea, and the tickers could be plotted in a similar way but following the NT8 scale rules, for example all the symbols in “Overlay justification” to all be under the same settings/parameters.

                  I don’t know if I’m using the right exact technical words for every case but I think now with the new description and the picture you could have a better idea about how could be the process to get the final result.



                  Your best bet would be to use an instance of the indicator for each data series and use the overlay function to overlay them on top of each other.
                  Thank you for the suggestion Kate. That was what I was thinking to do but I would like to avoid to have let’s say 30 instances of the indicator running all them at the same time to analyze different timeframes etc. when that could be done maybe with 4 instances for example, 1 instance for each timeframe.

                  Thank you!

                  Click image for larger version  Name:	Visual illustration - 2 overlaid charts (ES and CL) in standard chart and in the indicator 1.png Views:	0 Size:	410.7 KB ID:	1157383


                  Possible result for the Indicator Properties

                  Click image for larger version

Name:	Visual illustration - 2 overlaid charts (ES and CL) in standard chart and in the indicator 2.png
Views:	201
Size:	442.2 KB
ID:	1157385
                  Last edited by futurenow; 05-24-2021, 11:21 AM.

                  Comment


                    #10
                    Oh! One more clarification, if possible, ideally the Ticker Symbols in the indicator would be independent from the data series in the chart. I mean, it would be perfect if the Ticker Symbols you can choose in the in the indicator don’t necessarily need to previously be in the chart.

                    For example, you could have a simple standard chart with the SPY, and in the indicator you could select the next:

                    Ticker Symbol 1: ES
                    Ticker Symbol 2: CL
                    Ticker Symbol 3: GC

                    I.e. that ES, CL and GC are chosen in the Indicator independently of what previously be in the chart. Actually I see you can only choose only the Ticker Symbols you previously have in the chart data series, and a non-direct relationship between the chart data series and the indicator data series would be perfect, of course if possible.

                    Thank you

                    Last edited by futurenow; 05-24-2021, 11:39 AM.

                    Comment


                      #11
                      Hello

                      I'm trying to add a simple static and fixed Zero Line in the indicator with the next line of code but it doesn't plot anything

                      Code:
                      if (State == State.SetDefaults)
                      {
                      ...
                          A[B]ddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZeroLine);[/B]
                      }
                      I was checking the MACD as example because in the MACD that line of code does the work exactly as I need, just drawing a line at the 0 level of the indicator sub-chart (sub panel), but for some reason when I add this code portion in the custom indicator it does not plot anything. I tried changing the line type, the width of the line, the color etc. but no any line plotted

                      The NinjaScript compilation runs as should with no errors. Am I missing anything?

                      Thank you

                      Click image for larger version

Name:	Zero Line not getting plot as in the MACD.PNG
Views:	291
Size:	20.2 KB
ID:	1166816

                      Comment


                        #12
                        Hello futurenow,

                        Thank you for your reply.

                        What's going on is that we're overriding OnRender to plot the candles, but since we had plots that we didn't need rendered holding the indicator high/low/open/close values to plot the candles with, we didn't need to call the base OnRender so that plots would be rendered as they usually are.

                        I've created an updated version that sets the plots to transparent and then calls the base OnRender so the zero line shows up.

                        Please let us know if we may be of further assistance to you.
                        Attached Files
                        Kate W.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Kate View Post
                          What's going on is that we're overriding OnRender to plot the candles, but since we had plots that we didn't need rendered holding the indicator high/low/open/close values to plot the candles with, we didn't need to call the base OnRender so that plots would be rendered as they usually are.

                          I've created an updated version that sets the plots to transparent and then calls the base OnRender so the zero line shows up.
                          Thank you so much Kate for the explanation and for the update. You always takes your time to explain the concepts in the most helpful way. Now I can confirm the update is showing the Zero Line.



                          Additionally there is a detail I just noticed, and it is about the candlesticks the indicator plots, I've noticed those candlesticks has not upper and lower shadows and checking the custom plotted chart I'm not sure if in a down bar what the indicator plots is the bar's Low or the bar's Close.

                          Into the code I see the part where there is a comment that says "assign high/low values since we're not really using them" with the next section of code, so I could assume the answer is the custom candlesticks plotted by the indicator only have Open and Close based on their corresponding instrument's bars/candlesticks, i.e. only working with the open and the close of each bar and obviating the upper/lower shadows, but I would like to confirm well this important detail because the most important use I would give to the indicator is doing certain analysis based on the type of chart "Line on Close", and I mean a Line on Close chart generated by the indicator, not just the standard Line on Close chart you can obtain by setting up the Data Series into the instrument.
                          Code:
                          ...
                             // assign high/low values since we're not really using them
                             if(IndClose[0] > IndOpen[0])
                              {
                                     IndHigh[0] = IndClose[0];
                                     IndLow[0] = IndOpen[0];
                              }
                             else if (IndClose[0] < IndOpen[0])
                              {
                                     IndHigh[0] = IndClose[0];
                                     IndLow[0] = IndOpen[0];
                             }
                             else if (IndClose[0] == IndOpen[0])
                             {
                                    IndHigh[0] = IndClose[0];
                                    IndLow[0] = IndClose[0];
                             }
                          ...
                          For example if I would like to work with close price then I'm not sure what those custom candlesticks shows are the real close or the low/high.


                          Thank you for your time

                          Comment


                            #14
                            Hello futurenow,

                            Thank you for your reply.

                            The original candlestick indicator example I adapted for this particular example allows you to set plots for the high and low as well as open and close. Since we're working with the net change of the entire bar, we only really care about the open and close and we just set the high and low to be equal to either the open or close depending on the bar direction. Referencing IndClose[barsAgo] or IndOpen[barsAgo] would get you the indicator open or indicator close price for that rendered bar.

                            Please let us know if we may be of further assistance to you.
                            Kate W.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Kate View Post
                              The original candlestick indicator example I adapted for this particular example allows you to set plots for the high and low as well as open and close. Since we're working with the net change of the entire bar, we only really care about the open and close and we just set the high and low to be equal to either the open or close depending on the bar direction. Referencing IndClose[barsAgo] or IndOpen[barsAgo] would get you the indicator open or indicator close price for that rendered bar.

                              Thank you for the confirmation about in the example we are only focusing about the open and close



                              Ok. Now I'm trying to get an extra item but I'm not getting the right result in the chart

                              Could be way to plot a static fixed vertical line every certain time, for example in this situation starting every Month (at the moment 0 of every month).

                              I actually know that when you want to plot a vertical line when a certain event happens you use something like the next line:
                              'Draw.VerticalLine(this, "tag1", eventReached, Brushes.Yellow, DashStyleHelper.Solid, 1);'

                              But what about you need for visual purposes the line get plotted just every specific amount of time and not when a specific event takes place:
                              'Draw.VerticalLine(this, "tag1", ...Month, Brushes.Yellow, DashStyleHelper.Solid, 1);'

                              I tried with different ways but sometimes the code get errors, and some other times the printing process only happens in the begining of current month (in this case on August 01), but I'm unable to get this static line in the previous periods loaded/shown in the chart

                              For example, I tried a simpler way into the code in 'OnBarUpdate'
                              'Draw.VerticalLine(this, "tag1", 10, Brushes.Red);'


                              I could think the easiest way is to use a kind of code line like:
                              'Draw.VerticalLine(this, "tag1", ...Month, Brushes.Yellow, DashStyleHelper.Solid, 1);'

                              Into:
                              Code:
                              protected override void OnStateChange()
                              {
                                  if (State == State.SetDefaults)
                                  {
                                     ...
                                     //something like the next line
                                     Draw.VerticalLine(this, "tag1", [COLOR=#e67e22][B]...Month[/B][/COLOR], Brushes.Yellow, DashStyleHelper.Solid, 1);
                                  }
                              }

                              Thank you

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by elderan, Yesterday, 08:03 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by samish18, Yesterday, 08:57 AM
                              8 responses
                              25 views
                              0 likes
                              Last Post samish18  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              3 responses
                              10 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by RookieTrader, Today, 07:41 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post RookieTrader  
                              Started by maybeimnotrader, Yesterday, 05:46 PM
                              1 response
                              19 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X