Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
bool declarations
Collapse
X
-
bool declarations
I created a new strategy using the Strategy Builder and within it there were 2 bool variables which the Builder declared in 'Public Class' and made the assignments of false in 'SetDefaults'. When I use Print statements to check the status they are always 'True'. The only thing within the body that would change them to true is if a trade were taken which is not happening because the bool must be false is a condition of entering the trade,which would be followed with changing the bool to true. Is the declaration correct in 'Public Class'?Tags: None
-
Hello galsermil,
Thank you for your post.
Can you provide the script you're testing with so I may see if the same occurs on my end of things? You can export a script from Tools > Export > NinjaScript add-on. Do not check the box to export as a compiled assembly or I will be unable to review your logic. Please attach the resulting .Zip file to your reply.
Thanks in advance; I look forward to assisting further.
-
Kate, I will certainly export the script to you but I also want to make you are aware of a couple of things that I have done and the result. I commented out all of the text except a few lines of Debugging print statements. I have 18 pairs in my Demo account but I used only three as my guinea pigs when I commented out the lines and they are AUD/USD, GBP/USD, and USD/CAD. The result was that all three reported my bools as false. I then removed the comment lines for the script that set conditions for and entered a Short trade. When I did this, the AUD/USD and GBP/USD remained false but the USD/CAD reported true.
Kate, the export facility will not export the strategy.. The message is make sure all of the elements are include. I'm not sure what that means but there are two indicators referenced one of which is in the list and I included it and the other is RSI and it is not referenced so I can't include it.
Comment
-
Kate
I am attaching the .cs file. I hope that works. The divergence indicator is third party proprietary so I am not sure what to do about it. If worst comes to worst, can you log into my computer through Team Viewer?Attached Files
Comment
-
Hello galsermil,
Thank you for your reply.
I was able to strip out the bits referencing the proprietary indicator, and it looks like what's occurring is that an order is being submitted before the strategy has processed at least the number of bars specified by its BarsRequiredToTrade property. Since the order was triggered, but gets ignored because we haven't reached 20 bars yet, your bool gets flipped to true but no order is seen, which means you can't exit and flip that bool back to false.
Try the following:
protected override void OnBarUpdate()
{
Print("Top "+Instrument.FullName+" "+ Time[0]+" First_Trade_Open = " + First_Trade_Open + " Second_Trade_Open: " + Second_Trade_Open);
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 20)
return;
This way no orders get placed until we're past the number of bars required to trade.
Please let us know if we may be of further assistance to you.
Comment
-
Kate,
I assume you are speaking of the export error. If so it did not appear in the log but on the face of the Export screen. See this screencast :https://www.screencast.com/t/bx4qRaJc3
Comment
-
Hello galsermil,
Thank you for your replies.
The export error was due to referencing a 3rd party assembly, which I stripped out of your code to run it. I am not talking about the export error or needing to comment out any logic, I am saying to simply change your current bars check at the top of OnBarUpdate as in the bolded version below:
Please let us know if we may be of further assistance to you.Code:protected override void OnBarUpdate() { Print("Top "+Instrument.FullName+" "+ Time[0]+" First_Trade_Open = " + First_Trade_Open + " Second_Trade_Open: " + Second_Trade_Open); if (BarsInProgress != 0) return; [B]if (CurrentBars[0] < 20) return;[/B] // OnBarUpdate code continues - don't comment out sets
Comment
-
Kate,
Did this change deal with why the bool variables were being changed to 'open'. I can't check it as yet on my end as I have created a compile error which I need to sort out. By the way. may I ask you what is the instruction for determining the profit/loss on a single trade. What I am using, I believe is for all trades?
Comment
-
Hello galsermil,
Thank you for your reply.
Yes. Please see this section of my prior reply:
As far as getting PnL from a specific trade, that can be done with the TradeCollection:...what's occurring is that an order is being submitted before the strategy has processed at least the number of bars specified by its BarsRequiredToTrade property. Since the order was triggered, but gets ignored because we haven't reached 20 bars yet, your bool gets flipped to true but no order is seen, which means you can't exit and flip that bool back to false.
There's an example there of getting PnL from specific trades.
Please let us know if we may be of further assistance to you.
Comment
-
Hello galsermil,
Thank you for your reply.
What I would suggest here is first, to turn on TraceOrders so you can see if the orders are being submitted and ignored.
Strategy Builder > Default Properties > More Properties > Trace Orders, or in your State == State.SetDefaults section of OnStateChange:
if (State == State.SetDefaults)
{
TraceOrders = true;
}
This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders, which would trigger your bool to change without seeing an actual order. You can then look through and see what may be occurring.
Please let us know if we may be of further assistance to you.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
139 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment