![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
|
Can anyone tell me why this isn't working properly?
Code:
// risk management
if (Positions[0].MarketPosition==MarketPosition.Long)
{
// place profit target
EnterLongLimit(Positions[0].AvgPrice+(profitamount*TickSize));
// place stop loss
EnterLongStop(Positions[0].AvgPrice-(stopamount*TickSize));
// track breakeven highwater
hw=Math.Max(hw,Positions[0].GetProfitLoss(High[0],PerformanceUnit.Points));
if (hw>=betrigger)
behit=true;
// place breakeven order
if (behit)
EnterLongStop(Positions[0].AvgPrice);
// place trailing stop
EnterLongStop(hw-(stopamount*TickSize));
}
elseif (Positions[0].MarketPosition==MarketPosition.Long)
{
// place profit target
EnterShortLimit(Positions[0].AvgPrice-(profitamount*TickSize));
// place stop loss
EnterShortStop(Positions[0].AvgPrice+(stopamount*TickSize));
// track breakeven highwater
hw=Math.Max(hw,Positions[0].GetProfitLoss(High[0],PerformanceUnit.Points));
if (hw>=betrigger)
behit=true;
// place breakeven order
if (behit)
EnterShortStop(Positions[0].AvgPrice);
// place trailing stop
EnterShortStop(hw+(stopamount*TickSize));
}
|
|
|
|
|
|
#2 |
|
Member
Join Date: Jan 2009
Posts: 40
Thanks: 0
Thanked 0 times in 0 posts
|
elseif (Positions[0].MarketPosition==MarketPosition.Long)
just as a guess. |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
|
good call. probably the culprit. Thanks for the help.
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
|
still not working. What could be wrong?
|
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,384
Thanks: 252
Thanked 967 times in 950 posts
|
What exactly is not working?
Is this a MultiInstrument Strategy? Positions should only be used in that context - http://www.ninjatrader-support.com/H...Positions.html Have you tried adding Print() statements and TraceOrders to debug the code?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
|
Found the problem. The problem is I was using EnterLongLimit and EnterLongStop to exit positions.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exit strategy.... | jed77 | Strategy Development | 18 | 10-16-2008 09:58 AM |
| Exit strategy question | twaydow | Strategy Development | 1 | 09-30-2008 10:34 AM |
| 'Exit on Close' in Strategy Wizard | Elliott Wave | Strategy Development | 1 | 05-07-2008 10:14 PM |
| Entry / Exit Strategy | Edgar V. | Strategy Analyzer | 19 | 03-17-2008 07:29 AM |
| Exit Strategy in Initialize() | Oli | Automated Trading | 10 | 03-30-2007 03:06 AM |