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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    54 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    72 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X