Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss?

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

    SetStopLoss?

    I am running the following strategy for BSC ETF. My Datasource is IQFeed (parameters - Capture1 attachment).

    Here is the code:

    Code:
    [SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]protected[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] Initialize() {[/SIZE]
    [SIZE=1]TraceOrders = [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1];[/SIZE]
    [SIZE=1]Add([/SIZE][SIZE=1][COLOR=#2b91af][SIZE=1][COLOR=#2b91af]PeriodType[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1].Minute, 5);[/SIZE]
    [SIZE=1]SetProfitTarget([/SIZE][SIZE=1][COLOR=#2b91af][SIZE=1][COLOR=#2b91af]CalculationMode[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1].Percent, 0.5);[/SIZE]
    [SIZE=1]SetStopLoss([/SIZE][SIZE=1][COLOR=#2b91af][SIZE=1][COLOR=#2b91af]CalculationMode[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1].Percent, 0.1);[/SIZE]
    [SIZE=1]ExitOnClose = [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1];[/SIZE]
    [SIZE=1]ExitOnCloseSeconds = 90;[/SIZE]
    [SIZE=1]IncludeCommission = [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1];[/SIZE]
    [SIZE=1]Slippage = 0;[/SIZE]
    [SIZE=1]TimeInForce = [/SIZE][SIZE=1][COLOR=#2b91af][SIZE=1][COLOR=#2b91af]TimeInForce[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1].Day;[/SIZE]
    [SIZE=1]EntriesPerDirection = 1;[/SIZE]
    [SIZE=1]EntryHandling = [/SIZE][SIZE=1][COLOR=#2b91af][SIZE=1][COLOR=#2b91af]EntryHandling[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1].UniqueEntries;[/SIZE]
    [SIZE=1]BarsRequired = 15;[/SIZE]
    [SIZE=1]CalculateOnBarClose = [/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1];[/SIZE]
    [SIZE=1]}[/SIZE]
    [SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]protected[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] OnBarUpdate() {[/SIZE]
    [SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] (BarsInProgress == 1) {[/SIZE]
    [SIZE=1][COLOR=#0000ff][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1] (ToDay(Time[0]) == 20080317 && ToTime(Time[0]) == 63000 && Volume[0] >= 10 * 50) {[/SIZE]
    [SIZE=1]EnterLongLimit(10, 26.31, [/SIZE][SIZE=1][COLOR=#a31515][SIZE=1][COLOR=#a31515]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=1]);[/SIZE]
    [SIZE=1]}[/SIZE]
    [SIZE=1]}[/SIZE]
    [SIZE=1]}[/SIZE]
    Output from turning on TraceOrders = true:

    2/18/2010 10:33:06 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Percent Value=0.5 Currency=0 Simulated=False
    2/18/2010 10:33:06 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Percent Value=0.1 Currency=0 Simulated=False
    2/18/2010 10:33:06 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Percent Value=0.5 Currency=0 Simulated=False
    2/18/2010 10:33:06 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Percent Value=0.1 Currency=0 Simulated=False
    3/17/2008 6:30:00 AM Entered internal PlaceOrder() method at 3/17/2008 6:30:00 AM: Action=Buy OrderType=Limit Quantity=10 LimitPrice=26.31 StopPrice=0 SignalName='' FromEntrySignal=''
    3/17/2008 6:30:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00002/Back101' Name='Profit target' State=Working Instrument='BSC' Action=Sell Limit price=39.47 Stop price=0 Quantity=10 Strategy='MyCustomStrategy' Type=Limit Tif=Day Oco='NT-00000' Filled=0 Fill price=0 Token='056896b3aa2a49479a7383a424dad26f' Gtd='12/1/2099 12:00:00 AM'
    3/17/2008 6:30:00 AM Cancelled OCO paired order: BarsInProgress=1: Order='NT-00002/Back101' Name='Profit target' State=Cancelled Instrument='BSC' Action=Sell Limit price=39.47 Stop price=0 Quantity=10 Strategy='MyCustomStrategy' Type=Limit Tif=Day Oco='NT-00000' Filled=0 Fill price=0 Token='056896b3aa2a49479a7383a424dad26f' Gtd='12/1/2099 12:00:00 AM'
    2/18/2010 10:33:07 AM Cancelled pending exit order, since associated position is closed: Order='NT-00002/Back101' Name='Profit target' State=Initialized Instrument='BSC' Action=Sell Limit price=39.47 Stop price=0 Quantity=10 Strategy='MyCustomStrategy' Type=Limit Tif=Day Oco='NT-00000' Filled=0 Fill price=0 Token='655985fc48404426b576197834152df9' Gtd='12/1/2099 12:00:00 AM'
    2/18/2010 10:41:38 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Percent Value=0.5 Currency=0 Simulated=False
    2/18/2010 10:41:38 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Percent Value=0.1 Currency=0 Simulated=False


    The results of the strategy are:
    • Entry Price = 26.31
    • Exit Price = 3.18
    • Entry time = 3/17/2008 6:35
    • Exit time = 3/17/2008 6:35
    • Profit = -0.8791
    • Exit name = Stop loss
    Why is this strategy entering and exiting on the same bar with an 87% loss based on the stop loss exit?

    Thanks,
    Erik
    Attached Files

    #2
    Remember that stop loss orders are market orders. Suggest you check the data of that bar to see what is available range in that bar.
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    663 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    376 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    110 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    575 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    580 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X