Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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​
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by AaronKoRn, Today, 09:49 PM
    0 responses
    11 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    10 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    11 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,980 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X