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
NT hangs when I run a strategy
Collapse
X
-
Entry orders executing well now
Thanks a lot for that tip. The entry orders are now executing as expected.
-
Hello mbesha,
I took a look at the updated strategy. Upon initially loading it I only see a single entry for each direction being placed.
I wanted to check with you have you enabled more than one entry per direction?
Because you submitting two orders both in the same direction, by default the strategies are set to allow 1 order per direction so only the first entry would go through but the second being the same direction would not be submitted.
In the strategies properties when you add it to a chart you can specify a quantity for entries per direction.
Can you check what yours is set to? I have attached an image of where the Entries per direction option is located in your strategies properties.
Once I enabled the 2 entries per direction I see the additional order being placed in the condition.
Please let me know if I may be of additional assistance.
Leave a comment:
-
New problem with entry orders
Hi Jesse. I realized that there is a problem with the execution of my entry orders. As you can see from the following code snippet which I have attached for reference, when a variable called numoc is more than one, two entry orders are executed. This is executed when my position is flat (check for the method called WhenFlat() ).
.....
else if (numoc > 1 && numoc % 2 == 0)
{
if(BOP(1)[0] > 0.5)
{
myEntryOrderL = EnterLong(numoc/2,"BL"); //Buy, Low Profit target
myEntryOrderH = EnterLong(numoc/2,"BH"); //Buy, High Profit target
}
else if(BOP(1)[0] < -0.5)
{
myEntryOrderL = EnterShort(numoc/2,"SL"); //Sell, Low Profit target
myEntryOrderH = EnterShort(numoc/2,"SH"); //Sell, High Profit target
}
}
else if (numoc > 1 && numoc % 2 != 0)
{
if(BOP(1)[0] > 0.5)
{
myEntryOrderL = EnterLong((numoc+1)/2,"BL"); //Buy, Low Profit target
myEntryOrderH = EnterLong((numoc-1)/2,"BH"); //Buy, High Profit target
}
else if(BOP(1)[0] < -0.5)
{
myEntryOrderL = EnterShort((numoc+1)/2,"SL"); //Sell, Low Profit target
myEntryOrderH = EnterShort((numoc-1)/2,"SH"); //Sell, High Profit target
}
}
.....
For some reason, only myEntryOrderL gets filled but myEntryOrderH doesn't fill when the entry condition is met even though both are in the same if statement. Then after only myEntryOrderL gets filled, the OnBarUpdate method issues an error message when it moves on to WhenLong() or WhenShort(). Could you please tell me why this is so? I have checked the code and the logic seems okay. I have attached my whole strategy for your reference.Attached Files
Leave a comment:
-
Thanks for the useful tip. True to your word, when I changed the while loops into if statements, the strategy could get enabled without a hitch. Highly appreciate your kind and quick assistance!!
Leave a comment:
-
Hello mbesha,
Thank you for supplying the code that helps in looking into this further.
From what I can see the first sign of what would cause this would be the "while" loops that are in OnBarUpdate.
While loops should not be used in OnBarUpdate because while loops will loop until broken so I believe this is starting a loop on the first bar then getting no further because the loop is still running.
I would recommend changing these to if statements in place of while statements for the OnBarUpdate section specifically.
After commenting out the while statements I was able to get the strategy to load and NinjaTrader was responsive.
for the while(TradingDays) because this is a bool this could easily be converted to an if statement, if(TradingDays)
Because OnBarUpdate is already looping through the data set you would not need to create an additional loop for a boolean condition, you would only need to check if it is true or false while OnBarUpdate is looping.
Please let me know if I may be of additional assistance.
Leave a comment:
-
I have attached the strategy file for your reference and I have checked the loops in the OnBarUpdate() method and they all seem to have exit conditions. I can not read anything on the output window because as I mentioned earlier, the whole program freezes. The chart I am using the strategy on has Tick Value 1 Line Break 15 data series and the account is the Sim101 with a cash value of $1000 and a margin requirement of $100. Please check the code for me and see if you can find what is the root cause of the problem. Thanks.Attached Files
Leave a comment:
-
Hello mbesha,
Without seeing the code for this it is hard to say exactly what is happening.
It sounds like there may be some sort of loop happening in the OnBarUpdate.
One thing you may check is the output window to see if anything is noted after it is enabled.
You can access this by going to the Tools menu and clicking Output window.
If you would like I can take a look at your code if you would like to post it and see if I notice anything that sticks out.
If you do not want to post your code publicly please send your question into support [at] ninjatrader.com
Please let me know if I may be of additional assistance.
Leave a comment:
-
NT hangs when I run a strategy
Hi. I wrote my own custom strategy and compiled it with no errors. However, when I try to run it on my chart, the whole program hangs on me. What could be the cause of this and can you recommend a way of fixing this? Thanks in advance.
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by f.saeidi, Today, 09:29 AM
|
5 responses
18 views
0 likes
|
Last Post Today, 02:58 PM | ||
Started by SilverSurfer1, 04-04-2024, 12:42 PM
|
4 responses
73 views
0 likes
|
Last Post Today, 02:58 PM | ||
Started by kevinenergy, 02-17-2023, 12:42 PM
|
114 responses
2,639 views
1 like
|
Last Post Today, 02:56 PM | ||
Started by pickles1774, 04-08-2024, 07:14 AM
|
5 responses
21 views
0 likes
|
Last Post Today, 02:46 PM | ||
Started by Lele2k24, 03-27-2024, 11:24 AM
|
17 responses
74 views
0 likes
|
Last Post Today, 02:06 PM |
Leave a comment: