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

Live until cancelled order without BarsInProgress index

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

    Live until cancelled order without BarsInProgress index

    I'll try to explain what I'm intending to create and whether it's possible the best I can.

    I'm trying to make a Multi-Instrument strategy, that loads say 30+ symbols. Criteria for entries are just copied and pasted under 30+ BarsInProgress == 0 till BarsInProgress == 30 if statements.

    Entries are all taken fine but the stops is where I'm hitting some issues. The way I'm trying to place stops is using the OnPositionUpdate() method.

    The problem is this: How would the stop differentiate on which symbol to place the stop on. The way I would do it for a single symbol is something like this, where different initial stop is used based on the entry taken: entryOrder1 would be one entry criteria while entryOrder2 would be a different entry criteria.

    Code:
     
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnPositionUpdate(IPosition position)[/SIZE][/FONT]
    [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
    [/SIZE][/FONT]if (entryOrder1 != null && position.MarketPosition == MarketPosition.Long)
    {
    stopOrder1 = ExitLongStop (0, true, Position.Quantity, Low[0] - StopIncrement, "Trail Stop", "Entry");
    }
     
    if (entryOrder1 != null && position.MarketPosition == MarketPosition.Short)
    {
    stopOrder1 = ExitShortStop (0, true, Position.Quantity, High[0] + StopIncrement, "Trail Stop", "Entry");
    }
     
    if (entryOrder2 != null && position.MarketPosition == MarketPosition.Long)
    {
    stopOrder2 = ExitLongStop (0, true, Position.Quantity, MIN(Low, 3)[0] - StopIncrement, "Trail Stop", "Entry");
    }
     
    if (entryOrder2 != null && position.MarketPosition == MarketPosition.Short)
    {
    stopOrder2 = ExitShortStop (0, true, Position.Quantity, MAX(High, 3)[0] + StopIncrement, "Trail Stop", "Entry");
    }
    }
    I supose my dillema is, how would I generalize this so it automatically places these stop orders for the correct instrument and not the one whose BarsInProgress index is 0, while still retaining the LiveUntilCancelled status.

    Let me know if further clarification is needed.

    EDIT: For example, entryOrder1 may come from BarsInProgress == 14, or it may come from BarsInProgress == 20, is there a way to "detect" which BarsInProgress index it came from so that the stop can be placed for the correct index?
    Last edited by bani789; 09-02-2008, 01:11 PM. Reason: Typos

    #2
    Aren't you using individual IOrder objects for each of your instruments? If the order comes from the IOrder that stemmed from instrument 1 you will know which barsInProgress to submit to. Just change the 0 to 1 for the barsInProgressIndex parameter.
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rtwave, 04-12-2024, 09:30 AM
    2 responses
    20 views
    0 likes
    Last Post rtwave
    by rtwave
     
    Started by tsantospinto, 04-12-2024, 07:04 PM
    5 responses
    68 views
    0 likes
    Last Post tsantospinto  
    Started by cre8able, Today, 03:20 PM
    0 responses
    7 views
    0 likes
    Last Post cre8able  
    Started by Fran888, 02-16-2024, 10:48 AM
    3 responses
    49 views
    0 likes
    Last Post Sam2515
    by Sam2515
     
    Started by martin70, 03-24-2023, 04:58 AM
    15 responses
    115 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X