Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Loss Handling

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

    Stop Loss Handling

    Hi, I have a question about stop loss handling in strategies, say, there is 1 strategy and i'm running it using 3 different param...ie, in the strategy tab, there will be 3 different strategies

    I need to write to a database when there is a stop loss order filled, I've attached the code below

    My problem is, sometime, even though the strategy is using 3 set of param but all outstanding orders may hit stop loss at the same time, i can see from the execution tab that, all 3 stop orders are filled, but sometime, the database miss 1 or 2 orders data. Similarly, 3 long/short orders enter at the same time is possible, but so far i have not have any error on those orders

    I have never had problem with Pentium + Windows 7 combo, but after I change the box to Xeon + Windows 7, I start to notice the error

    I suspect it is only a problem for cut loss order is because the stop loss is filled very quickly (unlike the long/short orders, which require the onBarUpdate() to be called and each onBarUpdate() can take about 100-300 ms to run)

    is there any insight from your side?? thanks



    protected override void OnOrderUpdate(IOrder order)
    {
    // If OnOrderUpdate() is called from a stop loss or profit target order add it to the appropriate collection
    if (order.OrderState == OrderState.PendingSubmit)
    {
    // Add the "Stop loss" orders to the Stop Loss collection
    if (order.Name == "Stop loss")
    stopLossOrders.Add(order);

    // Add the "Profit target" orders to the Profit Target collection
    else if (order.Name == "Profit target")
    profitTargetOrders.Add(order);
    }


    // Process stop loss orders
    if (stopLossOrders.Contains(order))
    {
    // Check order for terminal state
    if(order.OrderState == OrderState.Filled)
    {
    //stop loss filled
    Print("Stop Loss");

    if(order.OrderAction==OrderAction.Buy || order.OrderAction==OrderAction.BuyToCover)
    {
    //log

    }
    else if(order.OrderAction==OrderAction.SellShort || order.OrderAction==OrderAction.Sell)
    {
    //log

    }


    }
    if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)
    {
    // Print out information about the order
    Print(order.ToString());

    // Remove from collection
    stopLossOrders.Remove(order);
    }


    }


    // Process profit target orders
    if (profitTargetOrders.Contains(order))
    {
    // Check order for terminal state
    if(order.OrderState == OrderState.Filled)
    {
    //profit target filled
    Print("Profit Target");
    if(order.OrderAction==OrderAction.Buy || order.OrderAction==OrderAction.BuyToCover)
    {
    //log

    }
    else if(order.OrderAction==OrderAction.SellShort || order.OrderAction==OrderAction.Sell)
    {

    //log
    }


    }
    if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)
    {
    // Print out information about the order
    Print(order.ToString());

    // Remove from collection
    profitTargetOrders.Remove(order);
    }

    }
    }

    #2
    Hello lawrence124,

    Thank you for your post.

    Are the three instances of the strategy outputting to the same file?

    What instruments and period types are the strategies enabled on? (Example: ES 09-13, 1 Minute)

    Can you provide a toy version of your script that we may test on our end for this item?

    I look forward to your response.

    Comment


      #3
      HSI future, 2 minutes bar

      i use:



      to send a message to another c# application for log handling

      is it possbile to use thread.sleep(100) to slow down the cut loss order handling speed ?? as i concern about reliability more than speed

      Thanks

      Comment


        #4
        Hello lawrence124,

        Thank you for your response.

        I am not familiar with XMDMessaging, however one of our forum members may be able to assist you in this area.

        If you use Print() statements in your code to print information to the Output window, do you see the correct information for each order?
        You can also try using StreamWriter to write to a text file to test this as well, we have a reference sample on StreamWriter at the following link: http://www.ninjatrader.com/support/f...ead.php?t=3475

        Please let me know if I may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, Today, 08:19 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        5 views
        0 likes
        Last Post Rapine Heihei  
        Started by f.saeidi, Today, 08:01 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 07:51 PM
        0 responses
        6 views
        0 likes
        Last Post Rapine Heihei  
        Started by frslvr, 04-11-2024, 07:26 AM
        5 responses
        97 views
        1 like
        Last Post caryc123  
        Working...
        X