Programmatically "drag chart left" Indicator - futures io
futures io



Programmatically "drag chart left" Indicator


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one hyperscalper with 14 posts (1 thanks)
    2. looks_two EDGE with 3 posts (6 thanks)
    3. looks_3 forrestang with 3 posts (1 thanks)
    4. looks_4 SamirOfSalem with 3 posts (0 thanks)
      Best Posters
    1. looks_one EDGE with 2 thanks per post
    2. looks_two userque with 1 thanks per post
    3. looks_3 Jasonnator with 1 thanks per post
    4. looks_4 forrestang with 0.3 thanks per post
    1. trending_up 2,246 views
    2. thumb_up 10 thanks given
    3. group 5 followers
    1. forum 24 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Programmatically "drag chart left" Indicator

(login for full post details)
  #1 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received

Hi.

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

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
need help writing easylanguage radarscreen weekly perfor …
EasyLanguage Programming
Is there a way to rename an existing trade?
MultiCharts
Multichart NET set signal parameters different than the …
MultiCharts
Tradenlernen martin popov
Trading Reviews and Vendors
1-min Intrabar indicator
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on futures io
How much do you know about Bitcoin?
129 thanks
I finally blew up an account
43 thanks
The Crude Dude Oil Trading System
36 thanks
Spoo-nalysis ES e-mini futures S&P 500
30 thanks
The tiyfTradePlanFactory indicator
21 thanks
 
(login for full post details)
  #2 (permalink)
 forrestang 
Urban Samurai
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,239 since Jun 2010
Thanks: 306 given, 950 received


hyperscalper View Post
...

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.
hyperscalper

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
Quoting 
Warning: These are UI properties which are designed to be set by a user. Attempting to modify these values through a custom script is NOT guaranteed to take effect.

However, it can still be done with:
 
Code
ChartControl.Properties.BarMarginRight = MyMargin;
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.

Reply With Quote
The following user says Thank You to forrestang for this post:
 
(login for full post details)
  #3 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received



forrestang View Post
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.

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.

hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #4 (permalink)
 Jasonnator 
Denver, Colorado United States
 
Experience: Intermediate
Platform: NT8 + Custom
Broker: NT Brokerage, Kinetick, IQFeed, Interactive Brokers
Trading: ES
 
Jasonnator's Avatar
 
Posts: 126 since Dec 2014
Thanks: 37 given, 121 received

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.

Good luck!

Reply With Quote
The following user says Thank You to Jasonnator for this post:
 
(login for full post details)
  #5 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received


Jasonnator View Post
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.

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 !!

hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #6 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received

Hi. I just got this thoughtful reply from NinjaTrader, where support Jim suggests
the following to determine active bar x coordinate on canvas?:

float startX = (float)ChartControl.GetXByBarIndex(ChartBars, BarsArray[0].Count-1);

[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 !!

[edit]https://ninjatrader.com/support/helpGuides/nt8/getxbybarindex.htm?zoom_highlightsub=GetXByBarIndex

[edit]https://ninjatrader.com/support/helpGuides/nt8/?chartbars.htm

https://ninjatrader.com/support/forum/forum/ninjatrader-8/platform-technical-support-aa/1133640-indicator-draw-line-from-active-bar

hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #7 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received

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 .

This is documented at:
https://github.com/amazing-andrew/AutoHotkey.Interop

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 !!

hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #8 (permalink)
userque
Chicago IL
 
 
Posts: 180 since Apr 2016
Thanks: 503 given, 127 received


hyperscalper View Post
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 .

This is documented at:
https://github.com/amazing-andrew/AutoHotkey.Interop

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 !!

hyperscalper

In addition to AHK, there are also AutoIt and SikuliX

Since you know about AHK, I assume you know about AutoIt. But I listed them just in case.

Not sure which is cleaner/easier for your purposes.

https://www.autoitscript.com/site/autoit/
RaiMan's SikuliX

Reply With Quote
The following user says Thank You to userque for this post:
 
(login for full post details)
  #9 (permalink)
 EDGE 
Saint Louis, Mo., USA
 
Experience: Advanced
Platform: NinjaTrader, Tradestation
Broker: Amp/CQG, Velocity/TT, Kinetick, TS
Trading: Anything That Moves..
 
EDGE's Avatar
 
Posts: 185 since Aug 2010
Thanks: 95 given, 364 received


hyperscalper View Post
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.

 
Code
//Variables
Chart curChart;
Get the current Chart using a dispatcher.. in State.DataLoaded or after
 
Code
ChartControl.Dispatcher.InvokeAsync((Action)(() => { curChart = Window.GetWindow(this.ChartControl.Parent) as Chart; }));

from there you can grab the absolute screen coordinates of WindowStartupLocation..
 
Code
curChart.Top
curChart.Left
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..

Chart Panel Dementions:
 
Code
ChartPanel.Width;
ChartPanel.Height;

Be Safe and Merry Christmas!

Reply With Quote
The following 3 users say Thank You to EDGE for this post:
 
(login for full post details)
  #10 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received


MY MANY THANKS TO YOU GUYZ !!
Happy Holidayz, stay safe;
hyperscalper

Started this thread Reply With Quote
The following user says Thank You to hyperscalper for this post:
 
(login for full post details)
  #11 (permalink)
 EDGE 
Saint Louis, Mo., USA
 
Experience: Advanced
Platform: NinjaTrader, Tradestation
Broker: Amp/CQG, Velocity/TT, Kinetick, TS
Trading: Anything That Moves..
 
EDGE's Avatar
 
Posts: 185 since Aug 2010
Thanks: 95 given, 364 received


hyperscalper View Post
NOW WE ONLY NEED TO FIGURE OUT HOW to scroll/jump the chart left by some meaningful amount, say, 25% of total canvas width !

These will always give you the top left corner coordinates of your chart panel..
("NOT Absolute" but chart panel relative.. so if in top panel.. normally x=0 y=0)
 
Code
X = ChartPanel.X
Y = ChartPanel.Y
These will give you the far right and bottom coordinates of the chart panel...
 
Code
W = ChartPanel.W
H = ChartPanel.H
The width and height of our panel can now be easily calculated...
 
Code
width = W - X;
height = H - Y;
To get chart panel coordinate of where the last bar should be rendered, just subtract right margin..
 
Code
xBarSBR = width - ChartControl.Properties.BarMarginRight;
Since we already have the Top Left Absolute Windows Desktop Screen Coordinates of our chart window..
 
Code
T = curChart.Top;
L = curChart.Left;
We can now calculate the Absolute Desktop Coordinate of first mouse down click
 
Code
xClick = L + xBarSBR;
yClick = T - (height/2); //middle of panel
To Calculate the Absolute Coordinates of Mouse Move 25% left of panel width containing bars
 
Code
xOffset = xBarSBR * .25;
xMoveTo = xClick - xOffset; 
yMoveTo = YClick;

Note: These will be off just a bit do to the toolbar, boarder widths, and such..
(which could be calculated as well) but for your current application and needs..
This should be close enough to get the job done and not have to do all that too..



Best of Luck and Merry Christmas!

Reply With Quote
The following 2 users say Thank You to EDGE for this post:
 
(login for full post details)
  #12 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received


EDGE View Post
Note: These will be off just a bit do to the toolbar, boarder widths, and such..
(which could be calculated as well) but for your current application and needs..
This should be close enough to get the job done and not have to do all that too..

OK, I did all of that, and I get pretty good results. So here's my ultimate
question for ya, Edge or anybody else:

Since nobody wants the hassle of simulating Mouse Drag, etc., how
can I simply set/reset the X position on Canvas of the "actively forming bar" by gaining
access to the Chart's variables in NT8 ??

Who do I need to talk to at NinjaTrader to find this out; or maybe one of
you vendors has a line to answer that question?

I'll post my Mouse Drag interface code; for those who might want to
do that; but let's see whether we can do it right !

hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #13 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received

Mouse Drag code (paste into Indicator) for use in OnBarUpdate, for example:

 
Code
		[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
	    private static extern void mouse_event(uint dwFlags, int dx, int dy, uint cButtons, uint dwExtraInfo);

	    [DllImport("user32.dll")]
	    static extern bool SetCursorPos(int X, int Y);

	    [DllImport("user32.dll")]
	    static extern bool GetCursorPos(ref Point lpPoint);

	    const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
	    const uint MOUSEEVENTF_LEFTUP = 0x0004;
	    const uint MOUSEEVENTF_MOVE = 0x0001;

	    static void Drag(int startX,int startY,int endX,int endY)
	    {
	        endX = endX - startX;
	        endY = endY - startY;
			Point currPos = new Point(); // to receive coords by ref
			GetCursorPos(ref currPos); // save pos
	        SetCursorPos(startX, startY);
	        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
	        mouse_event(MOUSEEVENTF_MOVE, endX, endY, 0, 0);
	        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
			SetCursorPos((int)currPos.X, (int)currPos.Y); // restore pos
	    }
Instead of trying to use AutoHotkey.dll and other such facilities; this way is
far more controllable and instant, so is recommended.

Any such code is subject to a lot of issues; but that will emulate a
Mouse Drag; and you'll have to fill in details. If you're messing with
this, then you're competent to do all the other stuff.

 
Code
// in protected override void OnRender(ChartControl chartControl, ChartScale chartScale)

ChartPanel	panel 	= chartControl.ChartPanels[chartScale.PanelIndex]; // this panel's index

// code fragments only to help determine position of active bar, relative
// to right margin on canvas; which can trigger your "drag left" logic
// right margin is at panel.X + panel.W

float currentBarX = ChartControl.GetXByBarIndex(ChartBars, BarsArray[0].Count-1);
// if (currentBarX < dragFromThresholdX) return; // don't drag left yet
Hope these fragments help someone; sorry if any errors or typos.

hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #14 (permalink)
 EDGE 
Saint Louis, Mo., USA
 
Experience: Advanced
Platform: NinjaTrader, Tradestation
Broker: Amp/CQG, Velocity/TT, Kinetick, TS
Trading: Anything That Moves..
 
EDGE's Avatar
 
Posts: 185 since Aug 2010
Thanks: 95 given, 364 received


hyperscalper View Post
how can I simply set/reset the X position on Canvas of the "actively forming bar" by gaining
access to the Chart's variables in NT8 ?

You can work with Min/Max of Y/Price Axis a bit here:
https://ninjatrader.com/support/helpGuides/nt8/?oncalculateminmax.htm

but I'm not familiar with a way of doing this for the X/Time Axis of a default chart.. Maybe?

Working with Chart Object Coordinates
https://ninjatrader.com/support/helpGuides/nt8/?working_with_chart_object_coordinates.htm

or ChartControl
https://ninjatrader.com/support/helpGuides/nt8/?chartcontrol.htm



Good Luck and Happy Holidays

Reply With Quote
The following user says Thank You to EDGE for this post:
 
(login for full post details)
  #15 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received


hyperscalper View Post
OK, I did all of that, and I get pretty good results. So here's my ultimate
question for ya, Edge or anybody else:

Since nobody wants the hassle of simulating Mouse Drag, etc., how
can I simply set/reset the X position on Canvas of the "actively forming bar" by gaining
access to the Chart's variables in NT8 ??

Who do I need to talk to at NinjaTrader to find this out; or maybe one of
you vendors has a line to answer that question?

I'll post my Mouse Drag interface code; for those who might want to
do that; but let's see whether we can do it right !

hyperscalper

ANYWAY... I poked at Support, and even got the NinjaTrader Support Group Manager
involved. I was met by a flat out refusal to ask their Charting Engineering how I
might be able to set the X position of the Currently Forming Bar, from within
an Indicator.

Their model is: "We can't just go asking Engineering for stuff like that." And I
ask the question "Why not?" It's just their way of doing business. I encouraged
them, given their flat refusal, that they might find ways in the future to break
down some of the "stove pipes" and answer questions like mine in the future.....

So, given their flat refusal to help with this issue; it seems that using a Mouse Drag
operation is my ONLY choice; and that would be done through the Win32 API.

There is a suggestion that Mouse Drag events may be able to be sent to a Chart,
given the Chart's HWnd window pointer; EVEN THOUGH that Chart may not currently
have Mouse Focus. This would need to be the case; because there would be
multiple "Drag Left Indicators" on Mutiple Charts typically.

I'm just going to have to use Trial and Error here; to determine how I can do that.
And learn more about Event handling at the Windows level.

Of course, NinjaTrader could re-evaluate their willingness to help with this very simple
request; but I am not holding my breath in the meantime.

SO ANY ONE WHO IS FAMILIAR WITH "SENDING" Mouse Events to Windows; in
a manner which is "atomic" and which would work seamlessly with other Mouse
Movements in progress on other Windows; that appears to be the way forward
since that is the very LAST thing that needs to be resolved; as all of the other
requirements (such as when to trigger the "drag left") are already figured out...

REMINDER: all I want to do is to DRAG LEFT on a Charting Panel which is hosting
an Indicator, programmatically (C#) ,
from the Indicator code which will access the Win32 API to do so.

And the reason for doing this? Instead of Shifting the entire Chart's contents
left on EVERY BAR, we would Drag Left (maybe 10 bars) so it would, in many
cases, NOT be necessary for Remote VPS or Dedicated Servers to send
redraws of Chart contents on every BAR advance. HUGE reduction in I/O
requirements for remotely accessed servers running NT8 via Remote Desktop.

hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #16 (permalink)
SamirOfSalem
Dubai + United Arab Emirates
 
 
Posts: 25 since Jan 2020
Thanks: 5 given, 7 received

Have you explored creating a new BarsType and manipulating its date?

I've in the past created a BarsType which re-values its PRICE, so it has its own OHLC by looking at the OHLC of some other bar (placed in another panel but within the same chart window) and then applying mathematical manipulations.

Although I haven't tried DATE manipulations, it should theoretically be possible to do something similar...

In your case you're using tick charts. I'd try creating a new BarsType, and have it constantly recalculate its own date based on the last ticks bar's datetime. This way it may be possible to keep the new BarsType constantly anchored to the same spot on the X-axis in its own panel (while the ticks bars, and their indicators, build in other panels).

Finally, get the chart to refresh only when the new BarsType's datetime needs refreshing.

Reply With Quote
 
(login for full post details)
  #17 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received


SamirOfSalem View Post
Have you explored creating a new BarsType and manipulating its date?

I've in the past created a BarsType which re-values its PRICE, so it has its own OHLC by looking at the OHLC of some other bar (placed in another panel but within the same chart window) and then applying mathematical manipulations.

Although I haven't tried DATE manipulations, it should theoretically be possible to do something similar...

In your case you're using tick charts. I'd try creating a new BarsType, and have it constantly recalculate its own date based on the last ticks bar's datetime. This way it may be possible to keep the new BarsType constantly anchored to the same spot on the X-axis in its own panel (while the ticks bars, and their indicators, build in other panels).

Finally, get the chart to refresh only when the new BarsType's datetime needs refreshing.

THANK YOU so much for your idea. I am not sure it will allow for the "periodic drag left"
which is the objective. A constant alignment on EACH bar still requires the entire
chart to the left, to be RE-DRAWN on EACH bar, and that is what we are trying to minimize by
"dragging the chart left" or "shifting the chart left" only e.g. after every 10th bar; or after
the current bar hits the right margin.

The Win32 API permits us to send Mouse Events and "drag the chart left"; but I fear that
it may be a FRAGILE solution with multiple "drag" indicators on multiple charts operating
independently. Perhaps not, since maybe we can send Mouse Events in a "transaction"
or "atomic" sequence; and by saving/restoring the active HWnd, then perhaps it would
work seamlessly..... but this is where my experience is limited.

I hope I didn't misunderstand your proposed solution...?


PLEASE REFER TO THIS VIDEO TO SEE WHAT I'M TRYING TO ACCOMPLISH:



That is Remote Desktop running on a dedicated server; using a fast 1 second chart
which will be forced to shift the entire chart image on EACH bar; unless the "drag left"
is done periodically, as shown.


hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #18 (permalink)
 forrestang 
Urban Samurai
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,239 since Jun 2010
Thanks: 306 given, 950 received

If you do figure out how to drag the chart with a simulated mouse event, please do post. I started a thread on NT on how to do this... I was recommended an indie that does this, but was too complicated.

If you figure out the minimum amount of code to accomplish this, please do post.

Reply With Quote
 
(login for full post details)
  #19 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received


forrestang View Post
If you do figure out how to drag the chart with a simulated mouse event, please do post. I started a thread on NT on how to do this... I was recommended an indie that does this, but was too complicated.

If you figure out the minimum amount of code to accomplish this, please do post.

Will do, if/when a "clean" solution is found. I can "hack" various solutions; but they
are not general enough.

BEST WOULD BE IF NINJATRADER CHARTING ENGINEERING WOULD SIMPLY TELL US
HOW WE CAN SET THE X POSITION OF THE CURRENTLY FORMING BAR DIRECTLY
FROM THE INDICATOR. I think the value of this is pretty convincing when you
consider the video posted above. Yes, NinjaTrader is typically used as a "desktop"
app; but for those of us to maintain Dedicated remote servers, or VPS servers; having
efficient I/O between the Remote Desktop server and local client is very important.

At least it's important for me...

hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #20 (permalink)
SamirOfSalem
Dubai + United Arab Emirates
 
 
Posts: 25 since Jan 2020
Thanks: 5 given, 7 received


hyperscalper View Post

I hope I didn't misunderstand your proposed solution...?

hyperscalper

If you're already almost there with the mouse-drag solution, there's really no point taking another route.

But just to explain the idea, look at how NinjaTrader deals with multi-timeframe charts like the one below (it'll be even more obvious if you overlay say 15min on 60 min, or 60 min on 1 day, etc). There seems to be some kind of pro-rating going on, with NT distributing the space available on the X-axis by approximating date/time values.

But in all cases, the latest candle in terms of timestap is what would print on the far right.

The idea is to create a fictitious candle, forwarded in time with say 15 minutes, or maybe given a fixed date "tomorrow". I'm hoping that fictitious candle will remain THE right most candle, while the ticks bars play catch-up. If THEIR dates are always earlier than that fictitious candle, they should paint farther to the left of it, i.e. somewhere in the middle of the chart window.

And just when the ticks candles are about to catch up with that "tomorrow" candle, we reset its date so that again it distances itself from the ticks bars, forcing NT to recalculate and pro-rate their positions since their timestamps are behind the tomorrow candle. As the ticks bars try to play catch-up again, they should paint somewhere in the middle. The chart is refreshed only once every so often, when we create a new date for the "tomorrow" candle.

So basically the idea is to make the ticks bars play catch-up to a tomorrow that never comes. It might work if you're looking for an all-Ninjascript approach.


Reply With Quote
 
(login for full post details)
  #21 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received


SamirOfSalem View Post
If you're already almost there with the mouse-drag solution, there's really no point taking another route.

But just to explain the idea, look at how NinjaTrader deals with multi-timeframe charts like the one below (it'll be even more obvious if you overlay say 15min on 60 min, or 60 min on 1 day, etc). There seems to be some kind of pro-rating going on, with NT distributing the space available on the X-axis by approximating date/time values.

But in all cases, the latest candle in terms of timestap is what would print on the far right.

The idea is to create a fictitious candle, forwarded in time with say 15 minutes, or maybe given a fixed date "tomorrow". I'm hoping that fictitious candle will remain THE right most candle, while the ticks bars play catch-up. If THEIR dates are always earlier than that fictitious candle, they should paint farther to the left of it, i.e. somewhere in the middle of the chart window.

And just when the ticks candles are about to catch up with that "tomorrow" candle, we reset its date so that again it distances itself from the ticks bars, forcing NT to recalculate and pro-rate their positions since their timestamps are behind the tomorrow candle. As the ticks bars try to play catch-up again, they should paint somewhere in the middle. The chart is refreshed only once every so often, when we create a new date for the "tomorrow" candle.

So basically the idea is to make the ticks bars play catch-up to a tomorrow that never comes. It might work if you're looking for an all-Ninjascript approach.


THE MOUSE THING IS BY NO MEANS WITHOUT ITS WEAKNESSES. I plan to really study
your proposal, and I had some similar ideas earlier. Another approach, with similar
weaknesses, is to SEND MOUSEWHEEL events to scroll a chart left.

DO YOU HAVE TIME or inclination to provide some code for this idea of yours; which could
very well be the best available solution?.... I REALLY APPRECIATE your idea; and I am
not yet sure which way I'll try to go to implement this behavior.

[edit] I'd like to run on a 1 second interval chart; or on a Tick Chart with only a few
Ticks per bar; so it should work on those timescales during an active market. I had
been thinking of having a "future" bar on the same timescale as the Chart, but in
the Indicator's Plot series; but I'm not sure that would work, though have not
seriously investigated it.

Thanks again,
hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #22 (permalink)
SamirOfSalem
Dubai + United Arab Emirates
 
 
Posts: 25 since Jan 2020
Thanks: 5 given, 7 received


hyperscalper View Post
THE MOUSE THING IS BY NO MEANS WITHOUT ITS WEAKNESSES. I plan to really study
your proposal, and I had some similar ideas earlier. Another approach, with similar
weaknesses, is to SEND MOUSEWHEEL events to scroll a chart left.

DO YOU HAVE TIME or inclination to provide some code for this idea of yours; which could
very well be the best available solution?.... I REALLY APPRECIATE your idea; and I am
not yet sure which way I'll try to go to implement this behavior.

[edit] I'd like to run on a 1 second interval chart; or on a Tick Chart with only a few
Ticks per bar; so it should work on those timescales during an active market. I had
been thinking of having a "future" bar on the same timescale as the Chart, but in
the Indicator's Plot series; but I'm not sure that would work, though have not
seriously investigated it.

Thanks again,
hyperscalper

Unfortunately I don't. I'd look up something like the Mirrored Bars add-on from the NinjaTrader website and start from there.

To backtrack a little, have you tried TeamViewer for your remote access instead of RDP? TV is free for personal use and does a helluva job of preventing lag, even with a bunch of charts and indicators running on the remote machine.

Reply With Quote
 
(login for full post details)
  #23 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received


SamirOfSalem View Post
Unfortunately I don't. I'd look up something like the Mirrored Bars add-on from the NinjaTrader website and start from there.

To backtrack a little, have you tried TeamViewer for your remote access instead of RDP? TV is free for personal use and does a helluva job of preventing lag, even with a bunch of charts and indicators running on the remote machine.

Thanks for the TeamViewer tip. But Remote Desktop is doing a really great job of eliminating Lag;
and it also spans 2 monitors very well. I gotta give Microsoft some kudos on that. I give mstsc.exe
a high priority locally; and have the network very well optimized by using the CTCP Congestion also (highly recommended). This faster network algo is used both on the Client and dedicated Server side where Windows Server 2012 is being used.

THIS NETWORK OPTIMIZATION is a must for Traders and Gamers.

Thanks for the info, I'll take a look at the NinjaTrader examples,
hyperscalper

Started this thread Reply With Quote
 
(login for full post details)
  #24 (permalink)
 forrestang 
Urban Samurai
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,239 since Jun 2010
Thanks: 306 given, 950 received

When I asked on the NT forum for a sample of sending a simulated keyboard event, I was recommended THIS indicator for a study case. I havent' dug into hard yet, but may give an idea of how to do this?

Reply With Quote
 
(login for full post details)
  #25 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader adv C#/Java
Broker: NinjaTrader with LeeLoo
Trading: NinjaTrader 8 advanced Strategies and Indicators
 
Posts: 70 since Apr 2020
Thanks: 5 given, 89 received


forrestang View Post
When I asked on the NT forum for a sample of sending a simulated keyboard event, I was recommended THIS indicator for a study case. I havent' dug into hard yet, but may give an idea of how to do this?

Yeah, that's the one they use. Frankly a poor excuse for "support" in the context
of the issue I have; but that's their "go to" example, apparently.

hyperscalper

Started this thread Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Programmatically "drag chart left" Indicator


Last Updated on March 29, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Our 12-year anniversary w/ $$,$$$ prizes (check soon)

June
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts