Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Max Down Day
Collapse
X
-
I was really just wanting to simply find out if my format or use of the if statements was incorrect somehow, for instance I have... if this then enter long for 1st instrument and if this then enter long for 2nd instrument. Is that acceptable use? Should I be using "else if" or another statement?
-
I'm not seeing an obvious case where I think using an else instead of an if would make a difference.
It might help you identify the issue by grouping your script into sections according to the BIP they are intended for.
When I'm creating multi series scripts I'll often group all my BIP == 0 logic together and leave a note for myself as a comment so that I can more easily identify what the section of code is intended for.
For example
//this section is BIP == 0 which is intended to be a 5 minute SPY chart
Additionally it will be helpful to go through the individual trades that are placed on instrument X in both the script with one instrument and the script with two instruments.
Also check your entries per direction settings. It could be that your 1 instrument is allowed to place all its trades however your multi series script might be limiting it to 1 trade at a time.LanceNinjaTrader Customer Service
Comment
-
Let me back up and ask you this regarding the basics of the logic of the code I've been using below. Basically all the SMA code below is doing is just looking for a crossover using the 5min bars or 0 Index (fast sma 1 bar ago > slow sma 1 bar ago & fast sma 2 bars ago < slow sma 2 bars ago). Then after it finds a crossover I have Closes[1][0] > Highs[0][1] which is a close of the 1min bar (Index 1) above the previous 5min bar (Index 0).
So given all this I just wanted to verify, am I correct in using BIP == 1 seeing the last event that is occurring right before the signal is triggered is the progression of the 1min bar (Index 1)?
if (BarsInProgress == 1) //OnBarUpdate called for 1min bars
{
if (SMA(BarsArray[0],Fast)[1] > SMA(BarsArray[0],Slow)[1] && SMA(BarsArray[0],Fast)[2] < SMA(BarsArray[0],Slow)[2] && Closes[1][0] > Highs[0][1] + distance)
EnterLong(200);
}
Comment
-
I don't see anything "wrong" with this codeOriginally posted by zachj View Post
if (BarsInProgress == 1) //OnBarUpdate called for 1min bars
{
if (SMA(BarsArray[0],Fast)[1] > SMA(BarsArray[0],Slow)[1] && SMA(BarsArray[0],Fast)[2] < SMA(BarsArray[0],Slow)[2] && Closes[1][0] > Highs[0][1] + distance)
EnterLong(200);
}
Its saying if we are in the second series then
Check to see if the SMA of the first series is greater than another of the first series AND an sma value further back is less than another sma further back AND the first series's close is greater than its high 1 bar earlier
This event would be called every one minute assuming the 2nd series is a 1 minute chart.
If the primary is 5 minutes it would be getting data from the previously closed 5 minute bar.
Example at 10:54 it would have OHLC data from 10:50 because COBC is always true in a backtestLanceNinjaTrader Customer Service
Comment
-
Ok good to know it looks ok. Breakthrough...I dug deep into the scripts yesterday and was able to match up the single and multi scripts, there was a index # that was off in a few places and the ToTime bracketing was incorrect so it was only applying to the 1st instrument. But the big thing that's been the hang up over last couple weeks is the setstoploss(at least in relation to using the for loop). I had one for a standard stoploss percentage which is fine and then a second one which I was trying to use to exit when the reverse of the entry conditions occured(cross down of sma). I should have just been using a ExitLong here or similar as you have been telling me the whole time. It changes the profit but using setstoploss here just isn't realistic and doesn't make sense.
So then I took things a step further and brought the for loop back in for the multi instrument script and again it matches the single script! I can just loop all the instruments through one line of code instead of having to repeat EnterLong for instance over and over for every instrument. Only somewhat tedious thing is having to put an Add in for every instrument in the Initialize section but I can just set that up in excel and paste it in.
The whole point of this was so that I can have the graphs available for the whole portfolio instead of only the individual instruments. That way I can see for instance the Daily Net Profit/Loss(Max Down Day) and the Equity Curve etc. for the entire portfolio.
I know I was a pain but thanks a lot for your help Lance!
Comment
-
Everything was looking real smooth on this, I tested it over 120 instruments and the single and multi script matched up. Then I tried it on another seperate 120 instruments and everything matched except for the one stock HRB. I've attached an image of the result for single and multi for this stock. You can see both scripts enter at the same time and same price of 28.54 and then exit at the same time of 3:55 but the exit price is slightly different. 29.06 for the single and 29.11 for the multi. Any idea what could be throwing it off for this one stock of 240 stocks with all others being identicle?
I have the portion of the code for each script below that controls the exit at 3:55pm.
Single:
if (BarsInProgress == 0)
{
if (ToTime(Time[0]) >= 155000)
ExitLong(200);
}
Multi:
for (int series = 0; series < 120; series++)
if (BarsInProgress == series)
{
if (ToTime(Time[0]) >= 155000)
ExitLong(200);
}
Comment
-
When you're viewing the trade results right click on the result that you have highlighted in blue -> Chart...
You will be able to view the closing order to see if perhaps the data that was stored on your machine changed.
When you're not connected to a data feed do the results stay the same?
Let me know what you find.LanceNinjaTrader Customer Service
Comment
-
Don't know how I missed seeing this on the chart before, the single is using ExitLong(Sell), and the multi is using SetProfitTarget (Profit Target) which just so happens to be at 29.11 exactly (2% profit target). The bars look the same on each chart and the slippage is set to 0 for both. I downloaded all my data from Esignal.
Any idea why the multi would trigger Profit Target and single the ExitLong? I posted the code for SetProfitTarget for each below, I don't see anything that would cause a difference.
Single:
if (BarsInProgress == 0)
{
if (Position.MarketPosition == MarketPosition.Long)
SetProfitTarget(CalculationMode.Percent, profittarget);
}
Multi:
for (int series = 0; series < 120; series++)
if (BarsInProgress == series)
{
if (Position.MarketPosition == MarketPosition.Long)
SetProfitTarget(CalculationMode.Percent, profittarget);
}
Comment
-
Just using default fill type for both. Single is using Entry handling of AllEntries, Multi is using unique entries. Both are 1 entries per direction. That's the only settings I've found that come up with the same results. Aside from these minor differences we are discussing.
Comment
-
In order for me to look further into this I will need a simplified version of the script that replicates the error.
If you would like, please post a very basic version of your two script. Make logical checks as basic as possible. Ideally we would want one script that traded on the single instrument and another script that traded on two instruments.
In the simple state you could then more accurately debug the script.
It's my initial thought this difference has to do with using SetProfitTarget() instead of placing a limit order but I won't know for sure unless you were to simplify the script.LanceNinjaTrader Customer Service
Comment
-
The profit target of 2% was way to close so I moved it up, that eliminated the difference at least in that particular case. I then ran another set of 120 stocks that I had not tested before and there was differences all over the place and certain stocks not being traded in the multi but traded in the single run etc.
I dug into the min Bars Required a bit, I was just leaving that at the default of 20. I guess I was figuring as long as it was set to 20 for both scripts they should be the same but apparently not. I'm using the 50sma in my entry condition and then this part of the script below is the part that would require the most bars. It's looking back 4 bars, so I figure I need min bars of 50 + 4, or actually 53 bars. When I'm at the 54th bar it's looking back at 53..52..51..50. So using 53 for min bars required I ran the entire S&P 500 and every single stock matches up. I guess that was the last key to this. Does my logic of using 53 make sense?
SMA(BarsArray[0], Fast)[4] < SMA(BarsArray[0], Slow)[4]Last edited by zachj; 07-31-2013, 08:46 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
580 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
335 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
102 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
552 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|


Comment