Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy with custom Trade buttons does not generate orders after manual cancel

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

    Strategy with custom Trade buttons does not generate orders after manual cancel

    Hi
    I have created a strategy with some custom trade buttons in the trade panel.
    The Code for the event is the following:
    Code:
    protected void ScalperLongClick(object sender, RoutedEventArgs e)
    {
    TriggerCustomEvent(o =>
    {
    //find the lowest low for scalper long
    int lowestBar = LowestBar(Low, 5);
    double low = Low[lowestBar];
    double high = High[lowestBar];
    
    //Draw.ArrowUp(this, CurrentBar+"", false,lowestBar, Low[0]-TickSize*5, Brushes.Green);
    
    EnterLongStopMarket(0,true, 1,high + TickSize * 5, CurrentBar+"SuperLong");
    SetStopLoss(CalculationMode.Price,low - TickSize * 1);
    SetProfitTarget(CalculationMode.Price,high + TickSize * 19);
    
    Draw.Line(this, CurrentBar + "Entry", 1, high + TickSize * 5, -1, high + TickSize * 5, Brushes.Orange);
    Draw.Line(this, CurrentBar + "SL", 1, low - TickSize * 1, -1, low - TickSize * 1, Brushes.Orange);
    
    ForceRefresh();
    }, null);
    }
    when I click the button the stopmarket order is generated and if the price is hit the stoploss and takeprofit orders are also generated as expected.
    After one of those are hit I can do the same again and it works as expected.

    The issue I get is if I press the button and generate the order but then after a while cancel the order by clicking the little x on the order on the chart.
    After that I cannot generate any new orders by pressing the button. I need to reload Ninjascript and then it works again.

    Is there any way to fix that behavior ?

    #2
    Hello SuneSorgenfrei,

    Thanks for your post.

    I would suggest creating a custom button in your script to use CancelOrder() to cancel the order and use a bool to detect if the order was canceled by clicking the custom button to cancel the order instead of manually closing the order by clicking the 'x' button next to the order marker on the chart.

    CancelOrder(): https://ninjatrader.com/support/help...ancelorder.htm

    Please see the LongShortToolbar script linked below from our NinjaTrader Ecosystem User App Share center for an example of entering and exiting orders using custom buttons.


    And, see this reference sample demonstrating how to create custom buttons using C# WPF: https://ninjatrader.com/support/help...ifi.htm​
    <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
    118 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