Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10
I have a break-even component in there also. Maybe that is my problem. I'll go over a few strategies from other people and see how they have coded it out.
The SetTrailStop() method can NOT be used concurrently with the [COLOR=#0000ff]SetStopLoss()[/COLOR] method for the same position, if both methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use both methods in the same strategy if they reference different signal names.
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10
Here is the code that I had:
#region Breakeven and Trailing Stops // Resets the stop loss to the original value when all positions are closed switch (Position.MarketPosition) { case MarketPosition.Flat: SetStopLoss(CalculationMode.Ticks, stopLoss); previousPrice = 0; break; case MarketPosition.Long: // Once the price is greater than entry price+ breakEvenTicks ticks, set stop loss to breakeven if (Close[0] > Position.AvgPrice + breakEvenTicks * TickSize && previousPrice == 0) { initialBreakEven = Position.AvgPrice + plusBreakEven * TickSize; SetStopLoss(CalculationMode.Price, initialBreakEven); previousPrice = Position.AvgPrice; PrintWithTimeStamp("previousPrice = "+previousPrice); } // Once at breakeven wait till trailProfitTrigger is reached before advancing stoploss by trailStop size step else if (previousPrice != 0 ////StopLoss is at breakeven && GetCurrentAsk() > previousPrice + trailProfitTrigger * TickSize ) { newPrice = previousPrice + trailStop * TickSize; SetStopLoss(CalculationMode.Price, newPrice); previousPrice = newPrice; PrintWithTimeStamp("previousPrice = "+previousPrice); } break;
My entries are beautiful on the strategy!!!! Just can't get the trailing stop working. It takes the stop loss and initial breakeven but doesn't trail. When I get the code for trailing stop then I'll post it.
You need to get rid of the SetStopLoss code and use SetTrailStop I believe. I'll post an example later.
EDIT: I found this in my 6.5 folder and if memory serves the SetTrailStop function worked in this strategy both short and long. It's sloppy but might give you some ideas.
Elite Membership required to download: ZN_v1_Backtest.cs
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10
MXASJ
You need to get rid of the SetStopLoss code and use SetTrailStop I believe. I'll post an example later.
EDIT: I found this in my 6.5 folder and if memory serves the SetTrailStop function worked in this strategy both short and long. It's sloppy but might give you some ideas.
Thanks MXASJ, I'll take a look at that template. Appreciate the response.
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10
MXASJ
You need to get rid of the SetStopLoss code and use SetTrailStop I believe. I'll post an example later.
EDIT: I found this in my 6.5 folder and if memory serves the SetTrailStop function worked in this strategy both short and long. It's sloppy but might give you some ideas.
I got exactly what I wanted from that, perfect entries and spot on trail stops, so am going to modify a breakeven to it and see how it runs.
Glad it helped! In terms of breakeven you can do that with your target/trail in some ways. A two contract ZN example with a target on the first contract @ 5 ticks and an 8 tick trail on both contracts becomes a "breakeven" trade once that target is hit (ignoring slippage).
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10
MXASJ
Glad it helped! In terms of breakeven you can do that with your target/trail in some ways. A two contract ZN example with a target on the first contract @ 5 ticks and an 8 tick trail on both contracts becomes a "breakeven" trade once that target is hit (ignoring slippage).
Thanks. Will hopefully get some code up here later with a breakeven type method on it. Depending on how the day goes!