NexusFi: Find Your Edge


Home Menu

 





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 5,848 views
    2. thumb_up 10 thanks given
    3. group 5 followers
    1. forum 24 posts
    2. attach_file 1 attachments




 
Search this Thread

Programmatically "drag chart left" Indicator

  #11 (permalink)
 
EDGE's Avatar
 EDGE 
Saint Louis, Mo., USA
 
Experience: Advanced
Platform: NinjaTrader, Tradestation
Broker: Amp/CQG, Velocity/TT, Kinetick, TS
Trading: Anything That Moves..
Frequency: Daily
Duration: Minutes
Posts: 209 since Aug 2010
Thanks Given: 98
Thanks Received: 392


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
Thanked by:

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
Quant vue
Trading Reviews and Vendors
REcommedations for programming help
Sierra Chart
 
  #12 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader C# Custom
Broker: NinjaTrader LeeLoo Rithmic
Trading: Nasdaq Futures NQ/MNQ
Posts: 314 since Apr 2020
Thanks Given: 15
Thanks Received: 522


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
  #13 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader C# Custom
Broker: NinjaTrader LeeLoo Rithmic
Trading: Nasdaq Futures NQ/MNQ
Posts: 314 since Apr 2020
Thanks Given: 15
Thanks Received: 522


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
  #14 (permalink)
 
EDGE's Avatar
 EDGE 
Saint Louis, Mo., USA
 
Experience: Advanced
Platform: NinjaTrader, Tradestation
Broker: Amp/CQG, Velocity/TT, Kinetick, TS
Trading: Anything That Moves..
Frequency: Daily
Duration: Minutes
Posts: 209 since Aug 2010
Thanks Given: 98
Thanks Received: 392


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
Thanked by:
  #15 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader C# Custom
Broker: NinjaTrader LeeLoo Rithmic
Trading: Nasdaq Futures NQ/MNQ
Posts: 314 since Apr 2020
Thanks Given: 15
Thanks Received: 522


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
  #16 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44

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
  #17 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader C# Custom
Broker: NinjaTrader LeeLoo Rithmic
Trading: Nasdaq Futures NQ/MNQ
Posts: 314 since Apr 2020
Thanks Given: 15
Thanks Received: 522


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
  #18 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047

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
  #19 (permalink)
 hyperscalper 
boise idaho
 
Experience: Advanced
Platform: NinjaTrader C# Custom
Broker: NinjaTrader LeeLoo Rithmic
Trading: Nasdaq Futures NQ/MNQ
Posts: 314 since Apr 2020
Thanks Given: 15
Thanks Received: 522


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
  #20 (permalink)
 SamirOfSalem   is a Vendor
 
Posts: 74 since Jan 2020
Thanks Given: 23
Thanks Received: 44



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




Last Updated on March 29, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts