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

  • NinjaTrader_Kate
    replied
    Hello futurenow,

    Thank you for your patience.

    Took me a bit but I've got an example of using a secondary data series to plot a single secondary instrument series - I'd recommend simply making different versions for different added instruments.

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

    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello futurenow,

    Thank you for your replies.

    I've been taking a look at this today and it's not really designed to work with multiple secondary series as input. I'm in the process of seeing if I can get it to properly plot from a single secondary series, however, I haven't gotten that working yet. I'll work on this further tomorrow and let you know my findings.

    Thanks in advance; I look forward to assisting you further.

    Leave a comment:


  • futurenow
    replied
    Note:

    During these days I’ve made many small modifications and variations of the code and now I just noticed that the 2nd added DataSeries shows values in the Data Box or in the mini Data Box, but it doesn’t plot anything in the chart, so maybe I missed some small detail but the general idea is still there in the code in basically the same form with also what I just wrote here as the main reference.

    Thank you!

    Leave a comment:


  • futurenow
    replied
    Hello

    Thank you for your last post!


    Now I’m trying to add 2 DataSeries into the code but I can’t get the expected result.

    If you load the script you attached in a previous post of this thread then it loads as should making the process to start from 0 every month, but I’m noticing that when I try to add 2 DataSeries, then the script doesn’t make the process to start from 0 every month even when I try to adapt the code to take into account the fact of adding the 2 extra DataSeries. The plotted lines-on-close start from 0 for the first bar loaded in the chart, but that’s all and now the plots don’t start from 0 for the next months. It is like if for the 2 added DataSeries, the code doesn’t recognize that every month it has to make the plots to start from 0.

    I also noticed that when I modify the 2nd added DataSeries ticker, let’s say changing it from ‘CL 06-22’ to ‘GC 06-22‘, then the line-on-close plotted in the chart for the 1st added DataSeries gets modified with other zig-zags shapes and others Y-axis values in general and I don’t understand why this happens if the idea is that the 2nd added DataSeries needs to be independent of the 1st added DataSeries.

    Bellow I attached the modified script trying to add the 2 DataSeries I described, to see if you could help me to solve this part that I have not been able to get a solution. I have a couple days doing modifications trying to get the desired result that is the script only works with the 2 added DataSeries and consequently skipping the main DataSeries loaded in the chart and that the script works always in the same way regardless of the main instrument/s loaded in the chart, where the only needed function of the chart is to make the added DataSeries match into the time-frame specified in the chart, i.e. that the added DataSeries automatically match with the time-frame selected in the chart, either being intraday or daily+ time-frames like: 5 min, 120 min, 1 day, 1 week, …


    Thank you in advance!


    Attached Files

    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello futurenow,

    Thank you for your reply.

    The example really isn't intended for live trading or copy/paste purposes, but the issue is with line 64 where it gets the brush from the axis pen. If you change that to use a brush of your chosen color, you won't get the error anymore when trying to compare two instances. For example:

    ShadowColor = Brushes.RoyalBlue;

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

    Leave a comment:


  • futurenow
    replied
    Hello

    I’m just trying to test this script '
    ExamplePlotNetChangeCandles' with the Strategy Builder, and it works as should when you add a condition like:

    If (IndClose[0] > NumericValue)
    //do something



    But when the condition is in the next form:

    If (IndClose[0] > IndClose[1])
    //do something


    Then the Builder displays the Error message you see in the attached picture “Unhandled exception: An item with the same key has already been added.”

    This Error message is also displayed when for example you use more than 1 condition even if previously the first condition initialy worked as should.

    I think this is first time I see this Error message, so what could be happening in these cases? Because the interesting would be to able work with the script with the Builder.


    As reference, I tried with 2 different PCs and I got the same result, with the same Error message in both cases.


    Thank you!



    Click image for larger version

Name:	ExamplePlotNetChangeCandles - Unhandled exception - An item with the same key has already been added.png
Views:	232
Size:	4.5 KB
ID:	1196777

    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello futurenow,

    Thank you for your reply.

    You'd simply want to draw a line when you reset everything to 0 at the start of the new month. You'd want to ensure the tag name is unique for each one, so in the following example, I'm using both the month and the current bar number in the tag to ensure each is unique and will not be replaced instead of a new line being drawn:

    Code:
     // if it's a different month reset to 0 on the first tick of the new month's first bar
    else if (CurrentMonth != Time[0].Month && IsFirstTickOfBar)
    {
    // reset current month to our new month
    CurrentMonth = Time[0].Month;
    //reset CurrentStartValue to the open of the current month
    CurrentStartValue = Open[0];
    // set open of this month's first bar to 0
    IndOpen[0] = 0;
    [B]Draw.VerticalLine(this, "Month " + Time[0].Month + " " + CurrentBar, Time[0], Brushes.Yellow);[/B]
    }
    I've also noticed that the previous example has some issues with scaling since we've set the plots to Transparent, which makes the autoscaling not work correctly. I've overridden OnCalculateMinMax as well as added the yellow line on the break of each month in the below version of the script so that it scales correctly.

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

    Leave a comment:


  • futurenow
    replied
    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

    Leave a comment:


  • NinjaTrader_Kate
    replied
    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.

    Leave a comment:


  • futurenow
    replied
    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

    Leave a comment:


  • NinjaTrader_Kate
    replied
    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

    Leave a comment:


  • futurenow
    replied
    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

    Leave a comment:


  • futurenow
    replied
    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.

    Leave a comment:


  • futurenow
    replied

    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.

    Leave a comment:


  • NinjaTrader_Kate
    replied
    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.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by maybeimnotrader, Yesterday, 05:46 PM
3 responses
22 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by adeelshahzad, Today, 03:54 AM
5 responses
32 views
0 likes
Last Post NinjaTrader_BrandonH  
Started by stafe, 04-15-2024, 08:34 PM
7 responses
32 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by merzo, 06-25-2023, 02:19 AM
10 responses
823 views
1 like
Last Post NinjaTrader_ChristopherJ  
Started by frankthearm, Today, 09:08 AM
5 responses
22 views
0 likes
Last Post NinjaTrader_Clayton  
Working...
X