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 love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    31 views
    0 likes
    Last Post love2code2trade  
    Started by cls71, Today, 04:45 AM
    2 responses
    10 views
    0 likes
    Last Post eDanny
    by eDanny
     
    Started by proptrade13, Today, 11:06 AM
    0 responses
    5 views
    0 likes
    Last Post proptrade13  
    Started by kulwinder73, Today, 10:31 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by RookieTrader, Today, 09:37 AM
    3 responses
    15 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Working...
    X