Thanks
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
When stoploss is filled strategy still thinks it has a position
Collapse
X
-
When stoploss is filled strategy still thinks it has a position
Hi, I have noticed that when a stoploss is hit and filled the strategy is not synching its position to the account position (which would now be flat) and continues to think it has a position. I am using ExitLongStopMarket for the stoploss. How can I get it to know that if the stop gets hit, it is in fact now flat?
ThanksTags: None
-
Hello RaygunWizzle,
Thank you for your post.
I suggest reviewing the information about strategy position vs. account position here:
The positions only check for a sync when enabling a strategy, depending on the start behavior selected, or if you right-click the Strategies tab and select Synchronize All Positions. Syncing account positions is described here:
After the stop loss is hit, what do you see on the Strategies tab for the strategy position and for the account position? Where are you seeing that the strategy continues to think it has a position? What is your logic for ExitLongStopMarket()? Is this a position with multiple contracts, and if so does the quantity for your exit order match the quantity that was entered?
I look forward to your reply.Emily C.NinjaTrader Customer Service
-
So the account will be flat but the strategy will think it still has a position. I am seeing this in the strategies tab, it will show it as having a position and continue showing the theoretical Unrealized. My logic for the stop exits looks like this, and you can see it constantly updates to Position.Quantity:
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
if (execution.Order.OrderState == OrderState.Filled && execution.MarketPosition == MarketPosition.Long)
{
if (currentStop == 0)
{
ExitLongStopMarket(0, true, Position.Quantity, (Position.AveragePrice - 140), "PositionStop", "");
}
else if (currentStop > 0)
{
ExitLongStopMarket(0, true, Position.Quantity, currentStop, "PositionStop", "");
}
}
if (execution.Order.OrderState == OrderState.Filled && execution.MarketPosition == MarketPosition.Long && execution.Order.Name == "PositionStop")
{
EnterLong(1, "");
}
}
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
{
if (order.OrderType == OrderType.StopMarket && order.OrderState == OrderState.Accepted)
currentStop = order.StopPrice;
}
Comment
-
Oh and that EnterLong bit was an attempt at getting it to restart after the stop filling but that doesnt seem to be working either.
Comment
-
Hello RaygunWizzle,
Thank you for your reply.
Please add print statements and enable TraceOrders in your strategy so you may better understand its behavior and narrow down which parts of your logic are being hit and causing the unexpected long strategy position. We have a guide to using these tools for debugging here:
If you are unsure of the meaning of the output, please feel free to share it by right-clicking the NinjaScript Output window and selecting Save As. This will create a text file that you may attach to your reply here with any additional questions you have.
Please let us know if we may be of further assistance.Emily C.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by lightsun47, Today, 03:51 PM
|
0 responses
4 views
0 likes
|
Last Post
by lightsun47
Today, 03:51 PM
|
||
Started by 00nevest, Today, 02:27 PM
|
1 response
8 views
0 likes
|
Last Post
by 00nevest
Today, 03:48 PM
|
||
Started by futtrader, 04-21-2024, 01:50 AM
|
4 responses
44 views
0 likes
|
Last Post
by futtrader
Today, 03:01 PM
|
||
Can someone turn this thinkscript into a ninjascript. 5PM CST OHL and Previous Day
by Option Whisperer
Started by Option Whisperer, Today, 09:55 AM
|
1 response
13 views
0 likes
|
Last Post
by bltdavid
Today, 02:44 PM
|
||
Started by port119, Today, 02:43 PM
|
0 responses
9 views
0 likes
|
Last Post
by port119
Today, 02:43 PM
|
Comment