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 pibrew, Today, 06:37 AM
    0 responses
    4 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    11 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    16 views
    0 likes
    Last Post AaronKoRn  
    Working...
    X