Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can we use ninjascript + hotkeys for trade management (once a trade is live?)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can we use ninjascript + hotkeys for trade management (once a trade is live?)

    I am not a programmer but I can understand some basic coding (took a couple of classes back in my college days, it was basically intro to c++)

    Is it possible to program a script and tie it to a hotkey, for example:

    I am long ES X lots at 3000.

    Price shoots up to 3006.

    I want to hit a hotkey (ie: F4) and have it automatically place (X - 1) lots 2 ticks below current price.

    So whenever I hit F4, I want to dump all but 1 lot of whatever my total position is and keep 1 left as a runner. I want it to be 2 ticks below current price as I prefer that than market orders.

    Could someone help point me in the right direction? Thanks!



    #2
    Hello LenovoX1E,

    Thanks for your post.

    This could be accomplished using C# and the PreviewKeyDown event from the ChartControl to look for the keys and set e.Handled = true;.

    See the example script that was created by my colleague Chelsea in this forum post: https://ninjatrader.com/support/foru...973#post685973

    Note that this concept is applied to the text box in this sample. The textbox needs to be in focus in this sample for the key handling to occur. This would be the same general concept for placing orders, except that you would subscribe to ChartControl in place of the textbox.

    The ChartControl is what is focused when the indicator is applied. If you use ChartControl then you would have general key handling on the chart. Note that since ChartControl is already a property in the script, you would check if ChartControl != null in State.Historical. Then, you would subscribe to ChartControl.PreviewDownKey += ChartControl_PreviewDownKey;.

    See the help guide documentation below.
    ChartControl: https://ninjatrader.com/support/help...artcontrol.htm

    Let us know if we may assist further.
    Last edited by NinjaTrader_BrandonH; 03-15-2022, 08:39 AM.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X