Dark Theme
Light Theme
Welcome to NexusFi: the best trading community on the planet, with over 200,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 -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Updated October 26, 2010
Top Posters
looks_one
mrticks
with 4 posts (0 thanks)
looks_two
MWinfrey
with 2 posts (4 thanks)
looks_3
Trader.Jon
with 2 posts (1 thanks)
looks_4
traderwerks
with 1 posts (0 thanks)
trending_up
6,739 views
thumb_up
5 thanks given
group
3 followers
forum
9 posts
attach_file
4 attachments
October 19th, 2010, 07:08 AM
Dublin, Ireland.
Experience: Advanced
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
Hey Folks am looking for some help with the attached strategy. It does everything I want it to do but only once! It will go long/short after entry signal with a stop loss and then if it is profit will trail the stop loss at the open [1] as coded. However, once this order is stopped out it does not take any other orders.
I posted on the NT forum here Long/short strategy with cancel order and trail stop - NinjaTrader Support Forum and was told I need to make sure "IOrder object is reset to null" but am not sure where to do this as I copied this strat from the NT sample strategies.
Basically, I'm looking for a strat to do the following:
1. Enter long if Close[1] > Open[1]
or
Enter short if Close[1] < Open[1]
2. Set initial stop loss to n ticks.
3. Cancel pending order if not filled after n bars.
4. If n ticks in profit then set stop loss to low/high of Open[1].
If anyone could point me in the right direction I would REALLY appreciate it!
Thanks.
Attached Files
Elite Membership required to download: TrailOneBar.zip
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
October 20th, 2010, 07:13 PM
Near the BEuTiFULL Horse Shoe
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184
I am not a programmer, and I didnt integrate into your code, so I did add some code snippets that might help you along the road (into your own shell) .. dont try to compile, I didnt use your namespaces or ordersignal names. I hope it helps.
TJ
Attached Files
Elite Membership required to download: FDAX1LBtrail.cs.txt
October 20th, 2010, 07:44 PM
Posts: 688 since Jun 2009
Thanks Given: 436
Thanks Received: 465
mrticks
If anyone could point me in the right direction I would REALLY appreciate it!
Thanks.
You have a logic error so it is not going to run the way you expect it to work.
And use Round2TickSize instead of the (7 * (TickSize / 2)) thing you are doing.
October 21st, 2010, 06:38 AM
Dublin, Ireland.
Experience: Advanced
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
Trader.Jon
I am not a programmer, and I didnt integrate into your code, so I did add some code snippets that might help you along the road (into your own shell) .. dont try to compile, I didnt use your namespaces or ordersignal names. I hope it helps.
TJ
Hi TJ thanks for that!
I've cobbled together another strat from your sample code, will test it now and see how it behaves. I appreciate you taking a look at this.
Thanks!
Attached Files
Elite Membership required to download: Trailing_One_Bar_prev_cancel_order.txt
October 21st, 2010, 06:40 AM
Dublin, Ireland.
Experience: Advanced
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
traderwerks
You have a logic error so it is not going to run the way you expect it to work.
And use Round2TickSize instead of the (7 * (TickSize / 2)) thing you are doing.
I took out that piece of code in my latest version as I only had that in there from copying a sample snippet.
I read your blog by the way and like the sample strategies you post on the website for reference!
October 26th, 2010, 01:38 PM
Near the BEuTiFULL Horse Shoe
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184
mrticks
Hi TJ thanks for that!
I've cobbled together another strat from your sample code, will test it now and see how it behaves. I appreciate you taking a look at this.
Thanks!
Have you tried out your new code? I will have a quick look later if you still need that comment ... unfortunately I dont use breakeven in my code ( anytime recently ) and I may have some challenge to follow correctly.
Jon
October 26th, 2010, 02:09 PM
Dublin, Ireland.
Experience: Advanced
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
Trader.Jon
Have you tried out your new code? I will have a quick look later if you still need that comment ... unfortunately I dont use breakeven in my code ( anytime recently ) and I may have some challenge to follow correctly.
Jon
Hi Jon,
I tested it but alas it did not perform as I had hoped. It will enter long or short and set a stop loss and then move to breakeven but does not modify the trail stop to follow at O/H/L/C of n bars ago or
SetStopLoss( "Long", CalculationMode.Price, Open[3] + 2 * TickSize, false);
as they say in C#.
I've attached the strat if you'd like to give it a whirl and see if you can do anything with it!
Code
/* If we have a long position and the current price is breakeven + x ticks in profit, raise the stop-loss order to Open[3] + 2 * TickSize.
*/
if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + 8 * TickSize)
{
// Checks to see if Close[0] is b/e + x ticks
if (GetCurrentAsk() > previousPrice + trailProfitTrigger * TickSize)
{
// Modifies stop-loss to Open[3] + 2 * TickSize
SetStopLoss( "Long", CalculationMode.Price, Open[3] + 2 * TickSize, false);
}
}
/* If we have a short position and the current price is x ticks in profit, raise the stop-loss order to breakeven.
*/
if (Position.MarketPosition == MarketPosition.Short && Close[0] <= Position.AvgPrice - 4 * TickSize)
{
// Checks to see if our Stop Order has been submitted already
if (stopOrder != null && stopOrder.StopPrice > Position.AvgPrice)
{
// Modifies stop-loss to breakeven
stopOrder = ExitShortStop(0, true, stopOrder.Quantity, Position.AvgPrice, "ShortStop", "Short1SB");
}
}
Attached Files
Elite Membership required to download: sample_trail_strat_TJ.zip
October 26th, 2010, 03:27 PM
Lubbock TX
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,336
mrticks
Hi Jon,
I tested it but alas it did not perform as I had hoped. It will enter long or short and set a stop loss and then move to breakeven but does not modify the trail stop to follow at O/H/L/C of n bars ago or
SetStopLoss( "Long", CalculationMode.Price, Open[3] + 2 * TickSize, false);
as they say in C#.
I've attached the strat if you'd like to give it a whirl and see if you can do anything with it!
Code
/* If we have a long position and the current price is breakeven + x ticks in profit, raise the stop-loss order to Open[3] + 2 * TickSize.
*/
if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + 8 * TickSize)
{
// Checks to see if Close[0] is b/e + x ticks
if (GetCurrentAsk() > previousPrice + trailProfitTrigger * TickSize)
{
// Modifies stop-loss to Open[3] + 2 * TickSize
SetStopLoss( "Long", CalculationMode.Price, Open[3] + 2 * TickSize, false);
}
}
/* If we have a short position and the current price is x ticks in profit, raise the stop-loss order to breakeven.
*/
if (Position.MarketPosition == MarketPosition.Short && Close[0] <= Position.AvgPrice - 4 * TickSize)
{
// Checks to see if our Stop Order has been submitted already
if (stopOrder != null && stopOrder.StopPrice > Position.AvgPrice)
{
// Modifies stop-loss to breakeven
stopOrder = ExitShortStop(0, true, stopOrder.Quantity, Position.AvgPrice, "ShortStop", "Short1SB");
}
}
MrTicks, it just occured to me that you aren't an elite member. The code I'm going to share will be limited to Elite members only.
October 26th, 2010, 04:15 PM
Lubbock TX
Experience: Intermediate
Platform: NinjaTrader
Broker: Stage 5 Trading
Trading: CL
Posts: 1,878 since Jul 2009
Thanks Given: 1,450
Thanks Received: 3,336
Last Updated on October 26, 2010