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
Chart data delay
Collapse
X
-
Great. I will look at those for examples and reply back if I need further assistance.
-
Hello mlprice12,
While we cannot see into the code for the indicator I can say that it would use OnRender for that purpose. You can see an example of drawing using OnRender by viewing the indicator SampleCustomRender. The Pivots and ZigZag indicators show how to implement using Plots to store data and OnRender to render the data in a custom way.
I look forward to being of further assistance.
Leave a comment:
-
Thanks a lot jesse,
Do you have access to the code for Order Flow Trade Detector or have insight into how the ellipses are drawn efficiently for that indicator?
Leave a comment:
-
Hello mlprice12,
From the given code it appears there would likely be many unique objects.
If you specifically needed the ellipse to highlight areas the more efficient way to do this would be to use OnRender. In that use case you would use plots or series to store data where you currently have your Draw.Ellipse statements. The way OnRender works is to only render the data for the currently visible bars so you could use OnRender to only render ellipses for the currently visible bars. That saves cpu by not creating many objects, you just have a few plots or series and then render the data from those.
https://ninjatrader.com/support/help...htsub=onrender
You could otherwise use plots to display the data which would be more efficient than drawing objects.
Leave a comment:
-
Thanks Jesse
It is 100% drawing objects OnBarUpdate; however, these objects are vital for my trading.
Are there recommendations for enhancing this code?
This is occuring on Each Tick with Volumetric series added
Code:AddVolumetric("ES 12-21", BarsPeriodType.Range, 2, VolumetricDeltaType.UpDownTick, 1);
Code:protected override void OnBarUpdate() { if (CurrentBars[1] < 505) return; if (Bars == null) return; NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe; if (barsType == null) return; if(BarsInProgress != 1) return; if (CurrentBars[1] > 505) { double price = High[0] - TickSize; //barsType.Volumes[CurrentBars[1]].GetMaximumVolume(null, out price); barVol[0] = barsType.Volumes[CurrentBars[1]].TotalVolume; double abarVol = SUM(barVol, 500)[0]; double rbarVol = barVol[0] / (abarVol/500); double barDelta = barsType.Volumes[CurrentBars[1]].BarDelta; int rbarVolInt = (int)(rbarVol*1.1); //size based on vol 0,1,2,3,4, tick // color based on delta - black - pale - dark if (barDelta >= barVol[0]*.70) { Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.Green, Brushes.Green, 20); } else if (barDelta >= barVol[0]*.30) { Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.Navy, Brushes.Navy, 20); } else if (barDelta >= barVol[0]*-.05) { Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.LightSlateGray, Brushes.LightSlateGray, 20); } else if (barDelta <= barVol[0]*-.70) { Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.Orange, Brushes.Orange, 20); } else if (barDelta <= barVol[0]*-.30) { Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.Crimson, Brushes.Crimson, 20); } else { Draw.Ellipse(this, "DOT"+CurrentBar, false, rbarVolInt, price+(rbarVolInt*.9)*TickSize, -rbarVolInt, price-(rbarVolInt*.9)*TickSize, Brushes.LightSlateGray, Brushes.LightSlateGray, 20); } } }
Leave a comment:
-
Hello mlprice12,
What you described could be expected depending on the configuration of the indicator in contrast to what your code is doing. Without more specific details on what your code does it would be difficult to point a direction other than general debugging steps. If your script runs OnPriceChange or OnEachTick that can compound problems in times of high volatility. if you are doing something not efficiently many times in a short period of time that can cause slow downs.
The best suggestion as a starting point would be to identify where your script may have high cpu use. A good area to check would be your OnBarUpdate logic. Drawing objects and other complex rendering can also cause slow downs if you are doing something many times in a small period of time. Temporarily disabling drawing objects in your code and other visual items will help to identify if that relates to the problem or not.
You may be able to utilize the playback connection if there is a specific instrument which you had observed this and know the time when that occurred. If you can re create the problem in playback then you can explore the code much more easily to find what parts contribute to the slowness.
I look forward to being of further assistance.
Leave a comment:
-
Chart data delay
During todays higher volatility period my chart created a display delay of over a minute and my trade buttons lost functionality.
This happened because I am using a few custom indicators and I'm guessing my code isn't optimally written for performance.
What are the best practices for caching indicator data or could the team lead me to a different solution?
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Shai Samuel, Yesterday, 11:29 PM
|
0 responses
2 views
0 likes
|
Last Post
![]()
by Shai Samuel
Yesterday, 11:29 PM
|
||
Started by futurestrader0000, Yesterday, 09:27 PM
|
0 responses
4 views
0 likes
|
Last Post
![]() |
||
Started by AdeptistJune, Yesterday, 09:19 PM
|
0 responses
7 views
0 likes
|
Last Post
![]()
by AdeptistJune
Yesterday, 09:19 PM
|
||
Started by Johnny90, 05-14-2022, 04:17 AM
|
4 responses
25 views
0 likes
|
Last Post
![]()
by jeronymite
Yesterday, 07:25 PM
|
||
Started by junkone, Yesterday, 07:25 PM
|
0 responses
5 views
0 likes
|
Last Post
![]()
by junkone
Yesterday, 07:25 PM
|
Leave a comment: