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!
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
NinjaTrader
Performace problem
Collapse
X
-
Hello superg3,
Thanks for your reply.
The example code was intended to give you an idea that you could then code, as you have.
When your code compiles fine but is not working as expected, please check the "log" tab of the control center for any run-time type errors.
If errors, or even if no errors found, then you will need to debug your code. Typically this is done by using print statements just ahead of an instead of conditional code blocks. The print statements can be used to output the state of the variables so you can then understand why it is or is not making the decisions needed to draw. The print statements send their output to the New>Ninjascript output window. Here is a link to our debugging tips for further detail: https://ninjatrader.com/support/help...script_cod.htm
- Likes 1
Leave a comment:
-
Excuse me Paul, I should explain it better. Actually what I wanted to show you is what happens when I introduce the code to get better performance. It compiles but the objets are not draw.
With the original code and performace issues:
and with the additional code for better performance:
I can't see what is wrong:
Code:if (CurrentBar < 1) // avoid out-of-range error return; { if (FirstTickOfBar) // Do on bar close { if (Volume[1] >= VolRelev1) { if (Close[1] > Open[1]) { if (ActivarZonas) { if (firstTime) { beginBar = CurrentBar; // this will be the beginning point firstTime = true; // change so that we don't process again } DrawRectangle("ZonaUp1" + beginBar, false, (CurrentBar - beginBar), Close[1] - TickSize, LongitudZona*-1 , High[1] + TickSize, ColorMarcoZonaUp, ColorFondoZonaUp, OpacidadFondoZona); } else { firstTime = false; // if the condition is no longer true then reset so we can draw the new rectangle the next time the condition is true. } if (ActivarMarcadoresVelas) { DrawLine("MarcaHUp1" + CurrentBar, false, 1, 0, 1, Low[1] - TickSize, ColorMarcaHorVelaUp, EstiloMarcaHorVelaUp, GrosorMarcaHorVelaUp); } } } } } }
Last edited by superg3; 03-07-2019, 01:35 PM.
Leave a comment:
-
Hello superg3,
Thanks for your reply.
Please note that we do not provide debugging services.
You asked for performance assistance which has been provided. We cannot go through your code line by line if this is what you are asking for.
If you have a specific Ninjascript question, please feel free to ask here or you can alternatively write into PlatformSupport[at]Ninjatrader[dot]Com and mark the e-mail atten Paul and include a link to this thread for reference.
Alternatively, if you would like your script professionally coded we can provide references to 3rd party coders.
Leave a comment:
-
Hello dear Paul,
please ¿could I send you an email with my full code?
Leave a comment:
-
Hello superg3,
Thanks for your post.
Your code runs either Calculate.OnEachTick or Calculate.OnPriceChange so that means your code will execute many hundreds to thousands of time per bar (depending on volatility and bar size).
If you have conditions that once they occur as the bar is building no longer need to be checked you can skip that code section on future ticks until the next bar. For example, you can use an int variable to save the bar number when the condition is true and check the bar number on the conditions so that once the condition is true and the action is executed it will no longer be executed until the next bar. For example (assuming you create an int variable named savedBar):
if (ActivarVolRelevantes && CurrentBar != savedBar) // check that the CurrentBar is not the same as the saved bar
{
if (Volume[0] >= VolRelev1)
{
PlotColors[0][0] = ColorVolRel1;
savedBar = CurrentBar; // save the current bar number to prevent repeating until the very next bar
}
}
CurrentBar is the bar number currently being processed, reference: https://ninjatrader.com/support/help...currentbar.htm
Another performance issue could be the number of unique draw objects being drawn over the historical data. If you are drawing the objects from one bar to the next and you have many bars in a row then you have many draw objects that really could be just one object that is updated from its beginning point to the current bar. This would require additional logic in your coding to note the beginning bar to reference back to and then using the same tagname until the condition changes the beginning point.
For example (assuming a bool called firstTime set to false and an int called beginBar)
if (some condition to draw rectangle)
{
if (firstTime)
{
beginBar = CurrentBar; // this will be the beginning point
firstTime = true; // change so that we don't process again
}
Draw.Rectangle(... using tag name with +begInBar... use start bar of (CurrentBar - beginBar), draw to the currentbar 0...);
}
else
{
firstTime = false; // if the condition is no longer true then reset so we can draw the new rectangle the next time the condition is true.
}
Leave a comment:
-
Performace problem
Hello,
I wrote the code below in my indicator, it gives me the info I need but it results in performance probllems. Could you tell me if there is a better way to draw the objets with a lower performance impact?
Code:protected override void OnBarUpdate() { Value.Set(Volume[0]); if (ActivarVolRelevantes) // if true { if (Volume[0] >= VolRelev1) { PlotColors[0][0] = ColorVolRel1; } } if (ActivarVolRelevantes) { if (Volume[0] >= VolRelev2) { PlotColors[0][0] = ColorVolRel2; } } if (CurrentBar < 1) // avoid out-of-range error return; if (FirstTickOfBar) // Do on bar close { if (Volume[1] >= VolRelev1) { if (Close[1] > Open[1]) { if (ActivarZonas) { DrawRectangle("ZonaUp1" + CurrentBar, false, 1, Close[1] - TickSize, LongitudZona*-1 , High[1] + TickSize, ColorMarcoZonaUp, ColorFondoZonaUp, OpacidadFondoZona); } if (ActivarMarcadoresVelas) { DrawLine("MarcaHUp1" + CurrentBar, false, 1, 0, 1, Low[1] - TickSize, ColorMarcaHorVelaUp, EstiloMarcaHorVelaUp, GrosorMarcaHorVelaUp); } } if (Close[1] < Open[1]) { if (ActivarZonas) { DrawRectangle("ZonaDown1" + CurrentBar, false,1, Close[1] + TickSize, LongitudZona*-1, Low[1] - TickSize, ColorMarcoZonaDown, ColorFondoZonaDown, OpacidadFondoZona); } if (ActivarMarcadoresVelas) { DrawLine("MarcaHDown1" + CurrentBar, false, 1, 0, 1, Low[1] - TickSize, ColorMarcaHorVelaDown, EstiloMarcaHorVelaDown, GrosorMarcaHorVelaDown); } } if (Close[1] == Open[1]) { DrawOnPricePanel = true; DrawRectangle("ZonaEven1" + CurrentBar, false, 2, Close[1] + TickSize, 0, Open[1] - TickSize, Color.Transparent, Color.Blue, 3); } }
Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by lorem, Yesterday, 09:18 AM
|
5 responses
16 views
0 likes
|
Last Post Today, 12:29 PM | ||
Started by Spiderbird, Today, 12:15 PM
|
0 responses
5 views
0 likes
|
Last Post
by Spiderbird
Today, 12:15 PM
|
||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
12 responses
42 views
0 likes
|
Last Post Today, 12:09 PM | ||
Started by FrazMann, Today, 11:21 AM
|
0 responses
6 views
0 likes
|
Last Post
by FrazMann
Today, 11:21 AM
|
||
Started by geddyisodin, Yesterday, 05:20 AM
|
8 responses
52 views
0 likes
|
Last Post Today, 10:45 AM |
Leave a comment: