View Full Version : Exiting a position with SetStopLoss or SetProfitTarget
SuzyG
12-19-2006, 10:28 AM
If I have set SetStopLossand SetProfitTarget in the Initialize() method and one gets executed, how and where would I put code to capture the exit amount with the time and print it to the output window?
NinjaTrader_Ray
12-19-2006, 10:47 AM
There is not supported method to output the actual fills resulting from a stop or target order to the output window. Am I clear as to what you are asking?
You can getthis information from the Control Center Log tab or the Executions Tab.
Ray
SuzyG
12-19-2006, 11:02 AM
Yes, this is what I need. Is something like this planned? I see it in the Control Center Log or the Executions Tab, but when testing this is something that would be helpful because I retest and it is hard to determine which is which.
NinjaTrader_Ray
12-20-2006, 01:22 AM
Not planned at this moment.
Ray
This is something that I was trying to figure out how to handle as well.
It seems to me that another method would be useful for strategies in addition to Initialize() and OnBarUpdate().
Specifically, I'd like to be able to get the buy/sell amounts related to a fill or stop whenever EnterLong(), EnterShort(), etc. complete, and when a profit target or trailing stop is reached causing the position to be closed.
I suggest that this capability might be implemented as another method which gets called when these types of events occur. Since these types of events are quite different than ticks and timed intervals that correspond to OnBarUpdate, I'd suggest a new method to implement this (e.g., OnMarketEvent() or something like that.)
I would find this capability very useful.
KBJ
P.S. You mention that there is not a supported method. Does this mean there is currently a way to do this that is not supported? If so, could you give us an idea of how to do this?
NinjaTrader_Ray
03-24-2007, 04:14 AM
Hi KBJ,
Unfortunately I can't give you an idea since this then means we do provide support. We have a clear line that we have drawn right now. We anticpate releasing support for additional existing functionality as we are able to properly provide support for it.
Ray
funk101
04-02-2007, 09:52 PM
Is there no way to trace out what the stoploss value is? I want to make sure the params are being met ie: trailing stop loss as I set them with setstoploss().
I'm having a hard time here. I can't get this stoploss to send in the order. What am I doing wrong? This runs in onBarUpdate(). It prints to output right, but the order never get's sent, I can see in my"Orders" panel.
/// <summary>
/// Track Trades
/// </summary>
public void TrackTrade()
{
if (Position.MarketPosition != MarketPosition.Flat) {
if (Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= 4){
double stopLoss = Close[1];
SetStopLoss(orderName, CalculationMode.Price,stopLoss, false);
Print ("------------------------------------");
Print ("------------------------------------");
Print("Setting stop to "+stopLoss+" in "+Bars.BarsSinceSession);
Print ("------------------------------------");
Print ("------------------------------------");
}
Print("Open PnL: " + Position.GetProfitLoss(Close[0], PerformanceUnit.Points));
}
}
And I would actually prefer to do this with Points instead of Price. Any suggestions?
funk101
04-02-2007, 11:39 PM
I realize that I wasn't sending in the order at time of entry. That's why. But, I'm still having a hard time trying to "amend" the orig. stoploss. Say, initial stop is 12 ticks, when a PnL of 4 points is hit, I want to move up to basically a trailing 2 tick stop. Can't seem to get this happening.
NinjaTrader_Dierk
04-02-2007, 11:47 PM
Let's see if we could clarify... some hints:
- NT6B10 has a new option "TraceOrders=true;", which you can set in the Initialize method. This traces info to the Output window and could give you an idea what is going wrong.
- Sorry, there is no CalculationMode.Point but NT supports CalculationsMode.Ticks which should come close.
- Do you have any other exit order placed which potentially prevents the submission of the stop loss order as you enter a position?
In general it's a good idea to go from a simple strategy which works to a more complex one (I suppose your OnBarUpdate method does more than just calling TarckTrade). I suggest simplifying the strategy to a point where it works as expected and then add feature after feature to see where the logic breaks.
PS: As I wrote this reply you added a new post. However, info above could help you to isolate issue in your recent post.