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 forrestang with 3 posts (1 thanks)
    3. looks_3 SamirOfSalem with 3 posts (0 thanks)
    4. looks_4 EDGE with 3 posts (6 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,321 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: 71 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?
EMA as a trailing stop
Traders Hideout
ID Indicator ?
ThinkOrSwim
AUSuperTrend in the NT strategy builder
NinjaTrader
RIP Murray Ruggiero
Feedback and Announcements
MCnet: (Multi-Timeframe) Directly Added Indicators vs Ba …
MultiCharts
 
 
(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,243 since Jun 2010
Thanks: 308 given, 951 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: 71 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: 145 since Dec 2014
Thanks: 39 given, 134 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: 71 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: 71 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: 71 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: 525 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, 365 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: 71 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:


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

BloodHound Fundamentals 101 w/Jeremy Tang @ SharkIndicators

Elite only
 

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