Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Using NinjaTrader 8, a mouse "drag left" on the body
of the chart, causes the chart to shift left, and to expose
a blank area between the current bar and the right margin
of the chart. (You are all familiar with the Left Arrow
symbol which appears upper right corner of chart when
this condition exists.)
Into this blank space, the "new bars" are drawn. And these
bars will continue to be drawn, until the right margin is
encountered; as which time it will "shift the entire body
of the chart left" to make room for the next bar. BUT
this shift is done on EVERY new bar; and that's what I
want to avoid, as much as possible.
On remote (using RDP or xfreerdp protocols) the shifting
of the entire chart image left; basically means rewriting
the entire chart area. Static pixel areas ARE NOT transmitted
over the network, since they haven't changed.
But if we drag most charts to the left, then new bars can
be added, generally (but not always, e.g. chart y rescaling
is an exception) there can be NO PIXEL changes to the
left of the active bar, or ony very very few pixel changes.
When this is true; then the Chart Image to the left of the
active bar; DOES NOT NEED TO BE RENDERED from the
remote dedicated or vps server back to the viewing client.
THIS REDUCES NETWORK I/O by 95% or more, in most
normal cases.
I WANT TO PROGRAMMATICALLY "DRAG LEFT" MAYBE
50% OF THE CHART'S WIDTH; but then do nothing until
active Bars force the chart to scroll again; AT WHICH TIME
I just want to do the "drag left again" but using code
instead of the Mouse to do this job.
TWO THINGS are needed:
1) recognize that the new Bar is going to force scroll left, and
2) change the variables in ChartPanel (or wherever they are)
so the "scroll left" action is done automatically.
PLEASE HELP. I COMPLETELY STRUCK OUT WITH NINJATRADER
PLATFORM SUPPORT ON THIS ONE; AND I KNOW THERE MUST
BE A SIMPLE SOLUTION.
HERE IS A VIDEO ILLUSTRATING WHAT I WOULD LIKE TO
ACCOMPLISH; only without using the Mouse to drag left
from time to time. Just code in some simple Indicator I
could use to do the periodic shifting of the chart:
hyperscalper
Can you help answer these questions from other members on NexusFi?
As I have gotten into using the OnRender() method in the past week or, I found your issue interesting and I understand WHY you want to do it... and basically scoured the documentation, as it seems like there should be a way to do this.
I initially though setting the barMargin would be the ticket. This is not recommended to be done programmatically, due to the DOCS saying
However, it can still be done with:
This works. HOwever, after doing this I realized that while this will programmatically shift the chart to the left, it still draws the bars in the same way... everything is just shifted over, not what you were looking for.
So I started an NT thread HERE, and they don't think its possible either, but seems like something they have as a future feature.
2 things that may work:
ustom capturing of user inputs, as if it were done from a keyboard... but I don't know how to do that, and seems to be a hacky solution.
Potentially drawing a bar chart from scratch. It could go on a chart with transparent bars, and the visual representation will just be there.
I'm not sure if the latter solution would serve your purposes, but it seems doable.
Yeah, most people can't see WHY anyone would want this behavior;
but it's all about remote I/O reduction.
The variables necessary are in the Charting package, obviously,
and eventually somebody will figure it out.
[edit] Should be able to get the active forming bar's offset from the
Right Margin, and eventually reset that variable; plus requesting a
Chart refresh; to solve the problem easily !!
[edit] I can see you ran into the same Brick Wall with NT, that I did, when
requesting this auto scroll left behavior !! lol
[edit] I really really need a fix here, as you can see from the
video link I posted, since I use a lot of Tick charts;
so it's time to "get creative" !!! ha ha
[EDIT] Just thinking out of the box here... If an Indicator could
fill out "future" Plot Values, and that could "push" the Indicator
left, away from the right margin (assuming alignment, etc) then
that could help produce the desired effect, maybe...
I so much DON'T want to write an AutoHotKey type solution here,
even though that would be possible.
Thanks for taking an interest here; and if I can crack the nut, then I'll
post a control Indicator anybody could use.
Broker: NT Brokerage, Kinetick, IQFeed, Interactive Brokers
Trading: ES
Posts: 159 since Dec 2014
Thanks Given: 40
Thanks Received: 166
I'm on the road so I can't write actual code but I think I can point you in the right direction. Here's how I would approach this:
1. In OnBarUpdate, set a flag any time there is a new bar completed and it is beyond your far right threshold index. This flag you'll need to check in the OnRender method. I would name is something like isDirty. This should be just a simple private field in your indicator class
2. Also in OnBarUpdate, keep track of the LastBarPainted which is under the Chart control object (accessed via OnRender parameters).
3. Do a comparison between last bar painted index and the SlotsPainted (also a ChartControl property). If it's beyond, call your "scroll left" method.
3a. You'll need to figure out how to initially set isDirty to true so it will run at least once and store the right most index. Should be some if logic once you are sure the bars have actually painted.
4. When you call your scroll left method, make sure you clear your isDirty flag and set it back to false.
You may need to call ForceRefresh to force the chart to redraw. Try it without it first because that is an expensive operation.
Scroll left method will need to use some of the ChartScale properties where you set where you want to horizontally scale the chart from/to. I would recommend tracking the pre scroll index on the far right as well as the far left, then figure out how far you want to move that left. Hopefully if you do it correctly, you're overall chart scale will stay the same. That difference amount between your far right and your "destination" is what you'll have to set your from index as. Again, you may have to convert to/from time by index or vice versa so be careful.
There could be some conversions you need to do with index to time based on where you want to move from/to so watch out for those. The indexing in NT is very tedious so fair warning in advance.
The only other way I *might* try would be trying to programmatically click and drag the mouse but I think that would be much harder and you'd have to track focus and definitely do conversions from point space to chart space. No thanks in my opinion.
The above mechanism would only trigger once your far right bar exceeded your threshold so it wouldn't be a mega drag in performance. Hard to explain in black and white and from memory of NT docs but I hope it's clearer than mud.
Any help on this is greatly appreciated, but I have to say that your very
first criterion presupposes that we can determine when a new bar is beyond
some far right threshold index (and to the left of the right margin).
But, so far, we don't know how to do that; so the rest of your very good
proposal becomes kinda moot.
Unless I'm wrong about that, but NT won't reveal how this could even be
determined, so far as I know. (perhaps you know?)
I could accomplish this with AutoHotKey, most likely, simulating Mouse Drags;
but I don't think anybody wants to go there !!
[EDIT]STOP PRESS! this works, which is also equivalent to:
float startX = (float)ChartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex);
That X value only needs to approach the right margin which is given by:
float maxRight = (float)(panel.X + panel.W); // right margin
where panel is:
ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex];
NOW WE ONLY NEED TO FIGURE OUT HOW to scroll/jump the chart left
by some meaningful amount, say, 25% of total canvas width !
I have verified that this is a piece of the ultimate
solution... hope so... That tells us when Drag Left is needed; which
is the first part of the problem solved !!
OK, I've binged on various approaches to generating
the Mouse Drag function I need; and my final choice
is to use from C# an AutoHotKey.Interop approach which loads
the AutoHotKey.dll .
Which will involve a small AHK script consisting of various
functions related to Mouse Drag emulation.
If my Indicator can determine absolute Coordinates on the
screen of its Indicator Panel and dimensions; then I should
be able to (in an "atomic" uninterruptible series of inputs) Move the mouse
to a start position, Mouse Down, move (drag) to a position
deltax to the Left, and Mouse Up.
At this time, having looked at alternatives; this appears to
be the most straightforward method of implementing the
Chart Drag Scroll Left which is required.
Yes, I know it, I said it, that I did not want to use AutoHotKey,
BUT by integrating the AutoHotKey.dll and calling it from my
control Indicator; I can get to the end point in my quest
with the least effort; and probably the best reliability.
YOU MAY DISAGREE; AND, if you disagree; give me an
alternative which is "cleaner"
Obviously, I'd just like to reassign the x offset of the rightmost
bar on the Canvas, and request a Refresh; but I do not know
how to do that !
Requesting help; if one of you can figure out that last piece of
the puzzle !!
Get the current Chart using a dispatcher.. in State.DataLoaded or after
from there you can grab the absolute screen coordinates of WindowStartupLocation..
beware though.. this ultimately comes from your stored xmal workspace file..
so if you move the window.. you must re-save the workspace and refresh your ninjascript..