NexusFi: Find Your Edge


Home Menu

 





Help: Inhibit Ninja Default Mouse action while capturing clicks


Discussion in NinjaTrader

Updated
    1. trending_up 1,677 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 SharkPub 
Zelienople, PA, USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: Futures
Posts: 1 since May 2015
Thanks Given: 1
Thanks Received: 0

I have been able to capture mouse movement and mouse clicks in Ninja Script. Portions of code (apprx 3,000 lines) are shown below. I can intercept the mouse clicks and read the keyboard state to decide how to process the click. The problem is that after intercepting the mouse click, I get the Ninja Trader "mouse action".

The question is: When I decide I want to capture a mouse click, how do I inhibit that mouse click from causing the default ninja trader actions? Alternatively, is there a way to disable the default mouse actions for some period of time, then re-enable them later (i.e. User clicks on a button. Disable all Ninja default mouse actions. Pick points on the chart and record them. Re-enable Ninja default mouse actions).

I am a beginner at this sort of thing, and would appreciate your help.

Thank you! Have a GREAT day!

SharkPub


Code for start up:

// --- mcdOnStartUp() --- Add to end of "OnStartUp()"
private void mcdOnStartUp()
{
if ( bDebug ) Print("mcdOnStartUp()");
bUpdated = false;
if ( (bInstalled = bIsBSModeActive()) == false ) {
// Print("mcdOnStartUp() - not active...");
return;
}

//add the mouse events
// Print("mcdOnStartUp()");
this.ChartControl.ChartPanel.MouseMove += new MouseEventHandler(mcdMouseEvent);
this.ChartControl.ChartPanel.MouseClick += new MouseEventHandler(mcdMouseEvent);

return;
}

Code for event handling:

private void mcdMouseEvent(object sender, MouseEventArgs e)
{
try
{
TriggerCustomEvent(new CustomEvent(mcdMouseTriggerEvent),e );
}
catch (Exception ex)
{
Print("Error1 " + ex.ToString());
}
}

private void mcdMouseTriggerEvent(object state)
{
int loc = 0;
int idx = -3;
int barclick = 0;
bool bDbg = false;

if ( !bUpdated )
return;

if ( curPt == null ) {
curPt = new chartPoint(this);
}
try
{
MouseEventArgs m = (MouseEventArgs)state;
loc = 1;
int bShift = 0, bAlt = 0, bCntrl = 0, bLeft = 0, bRight = 0;
bool bProcessed = false;
// Save points in case they changed
double tptShift0 = ptShift0;
double tptShift1 = ptShift1;
double tptAlt0 = ptAlt0;
double tptAlt1 = ptAlt1;
double tptCntrl0 = ptCntrl0;
double tptCntrl1 = ptCntrl1;
if ( m != null ) {
MouseButtons MBLeft = MouseButtons.Left;
MouseButtons MBRight = MouseButtons.Right;
bShift = (Control.ModifierKeys & Keys.Shift) != 0? 1:0;
bAlt = (Control.ModifierKeys & Keys.Alt) != 0? 2:0;
bCntrl = (Control.ModifierKeys & (Keys.ControlKey | Keys.Control)) != 0? 4:0;
if ( (bShift | bAlt | bCntrl) != 0 && (m.Button & (MBLeft | MBRight)) == (MBLeft | MBRight) ) {
// Both right and left button pressed, clear the oints
if ( bShift != 0 ) { ptShift0 = ptShift1 = 0; if ( bDbg ) Print(" pt Shift reset"); }
if ( bAlt != 0 ) { ptAlt0 = ptAlt1 = 0; if ( bDbg ) Print(" pt Alt reset"); }
if ( bCntrl != 0 ) { ptCntrl0 = ptCntrl1 = 0; if ( bDbg ) Print(" pt Cntrl reset"); }
} else if ( (bShift | bAlt | bCntrl) != 0 &&
(m.Button & (MBLeft | MBRight)) != 0 ) {
// set a point
curPt.setChartPosition(m.X,m.Y,1);
// Set the Y-position
double y = curPt.rYposTick;
if ( (m.Button & MBLeft) != 0 ) {
if ( bShift != 0 ) { ptShift0 = y; if ( bDbg ) Print(" pt Shift 0 set to: "+y.ToString("0.0000")); }
if ( bAlt != 0 ) { ptAlt0 = y; if ( bDbg ) Print(" pt Alt 0 set to: "+y.ToString("0.0000")); }
if ( bCntrl != 0 ) { ptCntrl0 = y; if ( bDbg ) Print(" pt Cntrl 0 set to: "+y.ToString("0.0000")); }
}
if ( (m.Button & MBRight) != 0 ) {
if ( bShift != 0 ) { ptShift1 = y; if ( bDbg ) Print(" pt Shift 1 set to: "+y.ToString("0.0000")); }
if ( bAlt != 0 ) { ptAlt1 = y; if ( bDbg ) Print(" pt Alt 1 set to: "+y.ToString("0.0000")); }
if ( bCntrl != 0 ) { ptCntrl1 = y; if ( bDbg ) Print(" pt Cntrl 1 set to: "+y.ToString("0.0000")); }
}
// Print("Shift="+(bShift==0?"up":"down")+" Alt="+(bAlt==0?"up":"down")+" Cntrl="+(bCntrl==0?"up":"down"));
// Print("Set point to "+y.ToString("0.0000"));
bProcessed = true;
// this.printChartControl(this);
}
// Check for one of the points changed position
if ( tptShift0 != ptShift0 || tptShift1 != ptShift1 ||
tptAlt0 != ptAlt0 || tptAlt1 != ptAlt1 ||
tptCntrl0 != ptCntrl0 || tptCntrl1 != ptCntrl1 ) {
// Force re-serialization of the data
barEntrySerialData.serializeClass( getInstrument(this), this );
}
....
}
}
catch (Exception ex)
{
Print("Error loc="+loc.ToString()+" computing projection bar: "+ex.ToString());
}
return;
}


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Ninjatrader users - good CONNECTIONs post and article fr …
NinjaTrader
Czechia Live at 52.5% as England Rides 4-2 Wave to Co-Fa …
Prediction Markets & Event Contracts
Netherlands & Germany Surge as World Cup Field Narro …
Prediction Markets & Event Contracts
Warsh Drops Easing Bias, December Hike Now Above 50% -- …
Prediction Markets & Event Contracts
Trump Media to sell instant access to market-moving soci …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Want your NinjaTrader indicator created, free?
5 thanks
FootPrintV2 Chart for NT8
1 thanks
BERN ALGOS algo trading journal
1 thanks
Afternoon-close session
1 thanks
Franks Trading Journey
1 thanks
  #3 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,550 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,427


@SharkPub

 
Code
    HandledMouseEventArgs ee = (HandledMouseEventArgs) e;

    ee.Handled = true;

Sometimes Windows/NT gets a strop on about this sort of thing but it's often good on Tuesdays, except when it decides to bar it or ignore it completely, so don't expect it to work 100%, I have used it but don't rely on it.

Be aware to treat moves, down clicks, up clicks, wheel moves separately as required (I prefer separate handler routines), also for the keyboard not all keys give you up and down, e.g. arrow keys you just get the up and no auto repeat, whereas the control/alt/shift keys you get up and down with auto-repeat..


Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on July 23, 2015


© 2026 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 - Downloads - Top
no new posts