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
How can I prevent a strategy from auto disabling after position is closed?
Collapse
X
-
Hi Chelsea,
Thanks for pointing the right direction.
I'm not finding the cause yet.
I'll do more testing tomorrow and be back asap with results.
Be well!
-
Hello Cormick,
Testing the SampleMACrossover lets us know if the issue is with NinjaTrader or an issue with your custom logic.
It sounds like you have identified the line of code causing the issue. What specific line of code when uncommented causes the behavior?
Is the 'if, else if' written correctly and not causing an error with the inner action block logic commented out?
- Likes 1
Leave a comment:
-
Hi Chelsea,
I did not test the SampleMACrossover.
But when I comment out the If() Else If() code from the OnBarUpdate in my strategy
(The If() contains the Long side code, and the Else It() the Short side code),
The strategy does not auto-disable.
I tested commenting out the all the Long side only and placing a long trade, and it does not auto-disable itself in this test.
When I comment out only part of the Long Side Only, it auto-disables itself.
And when I comment out All the Short side (Else IF ()) only code it does auto-disable itself.
A demo vid:https://drive.google.com/file/d/1twi...ew?usp=sharing
00:00 - 1:25 = Part of the Long Side code commented out (Short Order)
1:28 - 3:25 = All the Long Side code commented out (Long Order)
3:25 - 4:04 = All the Short Side code commented out (Long Order)
4:05 - 5:45 = Both the Long and the Short Sides code commented out (Long Order)
Leave a comment:
-
Hello Cormick,
Yes, I mean if you run the SampleMACrossover on a chart does it become disabled?
Reduce a copy of your custom script. Remove all logic that is not necessary for reproducing the behavior.
For example try removing all logic in OnBarUpdate(). Does the behavior still occur?
- Likes 1
Leave a comment:
-
Hi Chelsea,
Thanks for the answer.
No CloseStrategy() nor SetState() anywhere in the script.
The log shows no error (no colored highlighted lines), only regular logging.
I'm not sure what you suggest with reproducing with the SampleMACrossover.
How would I reproduce it?
Do you mean loading the SampleMACrossover on the chart and testing it it executes without auto-disabling itself?
Leave a comment:
-
Hello Cormick,
Does the strategy call CloseStrategy() or SetState() anywhere in the script?
Do any errors appear on the Log tab of the Control Center?
Can you reproduce this with the SampleMACrossover included with NinjaTrade?
Leave a comment:
-
Hi Chelsea,
My strategy always auto-disables itself after 30 seconds or so.
The strategy is supposed to auto Exit Manually entered trades, both long trades and short trades, using the unmanaged approach.
The strategy works without auto-disabling itself when with the Long side code only.
But it does auto-disable itself when both the long and short sides code is set.
What I get in the Output Window:
Enabling NinjaScript strategy 'AutoExitManuEntryDelay/238743863' : On starting a real-time strategy - StartBehavior=AdoptAccountPosition EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Ignore all errors ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=True MaxRestarts=4 in 5 minutes
Disabling NinjaScript strategy 'AutoExitManuEntryDelay/238743863'
Enabling NinjaScript strategy 'AutoExitManuEntryDelay/238743863' : On starting a real-time strategy - StartBehavior=AdoptAccountPosition AccountPosition=CL 09-21 1L EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Ignore all errors ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=True MaxRestarts=4 in 5 minutes
Disabling NinjaScript strategy 'AutoExitManuEntryDelay/238743863'
Why does it auto-disable itself?
How to make it not auto-disable itself?
Here's a demo vid:
Leave a comment:
-
Hello RFrosty,
Manual orders are not able to be seen by NinjaScript Strategies.
Manually clicking the Close button specifically will disable a strategy on the same instrument and account, so don't do this.
If you want to manually close a position, place an order in the opposite direction and don't click Close.
- Likes 1
Leave a comment:
-
I am manually opening an EURUSD and AUDUSD positions while the strategy is enabled. When I manually open the EURUSD, the Strategy closes the position which is expected. When I manually open the AUDUSD (the instrument the strategy is attached), the position is closed by the strategy as expected but the strategy is then auto disabled. I am expecting the strategy to remain enabled even if all positions are made flat by the strategy.Last edited by RFrosty; 07-05-2020, 08:18 PM.
Leave a comment:
-
Hello RFrosty,
This strategy doesn't submit any orders. If there are no orders being submitted, I highly doubt this strategy is becoming disabled automatically.
I ran this myself and it didn't disable. I'll leave it running in real-time for a while, but I highly doubt this strategy will disable as there are no orders being placed.
https://drive.google.com/file/d/1_-B...w?usp=drivesdk
Personally, I think what you provided is not the same script you are testing.
Leave a comment:
-
I have attached the source to validate.Attached Files
Leave a comment:
-
I don't see any errors in the logs and I am not calling CloseStrategy anywhere.
Leave a comment:
-
Hello RFrosty,
Welcome to the NinjaTrader forums!
A strategy will only become automatically disabled if an error occurs or if the connection is disconnected. Otherwise the strategy will keep running and will not be disabled.
Are you certain that CloseStrategy() or setting the State is not in the code?
Do you see any errors appearing on the Log tab of the Control Center when the strategy is disabled?
Is the connection still connected?
Leave a comment:
-
How can I prevent a strategy from auto disabling after position is closed?
I have created a new strategy and specified AUDUSD as the instrument. The strategy currently closes any open positions that are opened by a human. If I manually open a position on EURUSD, the strategy works fine and closes the position while leaving the strategy enabled. If I then manually open a position on AUDUSD, the instrument the strategy is attached to, the strategy closes the position and then automatically disables itself. In the code I am using the position.Close() method. I would like for the strategy to never automatically disable itself. How can I prevent this? Thank you.
The log shows a category="Default "and Message="Disabling NinjaScript strategy 'MyStrategy/205101387'
Right now, the only workaround I can think of is to create a new strategy and specify a different instrument such as "NZDUSD" and then I should be able to close EURUSD & AUDUSD positions without the strategy auto disabling itself. I am hoping there is a better way such as overriding what appears to be default behavior.Last edited by RFrosty; 07-03-2020, 01:35 PM.Tags: None
- Likes 1
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by mly916, Today, 09:48 PM
|
0 responses
6 views
0 likes
|
Last Post
by mly916
Today, 09:48 PM
|
||
Started by Mikey_, Today, 09:21 PM
|
0 responses
10 views
0 likes
|
Last Post
by Mikey_
Today, 09:21 PM
|
||
Started by cre8able, Today, 05:53 PM
|
3 responses
13 views
0 likes
|
Last Post
by cre8able
Today, 09:20 PM
|
||
Started by Aryan Kumar, Today, 09:04 PM
|
0 responses
4 views
0 likes
|
Last Post
by Aryan Kumar
Today, 09:04 PM
|
||
Started by yertle, Yesterday, 05:49 PM
|
3 responses
16 views
0 likes
|
Last Post
by Mindset
Today, 08:38 PM
|
Leave a comment: