Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Exiting a position with SetStopLoss or SetProfitTarget
Collapse
X
-
Exiting a position with SetStopLoss or SetProfitTarget
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?
Tags: None
-
imported post
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?
Comment
-
imported post
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
RayNinjaTrader Customer Service
Comment
-
imported post
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>
publicvoid 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?
Comment
-
imported post
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.
Comment
-
imported post
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.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Belfortbucks, Today, 09:29 PM
|
0 responses
6 views
0 likes
|
Last Post
by Belfortbucks
Today, 09:29 PM
|
||
Started by zstheorist, Today, 07:52 PM
|
0 responses
7 views
0 likes
|
Last Post
by zstheorist
Today, 07:52 PM
|
||
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
151 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
6 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
Comment