Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
whats wrong here?
Collapse
X
-
whats wrong here?
Im trying to do a very simple strategy for testing purposes where I simply enter a long position, hold it for x days, exit, repeat. I built a condition where if close>0, enter long. After 5 bars, exit long. I assumed this would just keep creating positions one after another. It produces zero trades. Code is pasted in txt file.Tags: None
-
Sorry I should have provided more info - Im backtesting it against a basket of stocks that I have backtested many strategies against. I've also just run it against a single stock in a chart.
Attached is a couple pics of the param setup and results.
THis seems like the most basic stratgey I just cant figure out whats going on.
Comment
-
Your code evaluates to flat.
Originally posted by meegwell View PostIm trying to do a very simple strategy for testing purposes where I simply enter a long position, hold it for x days, exit, repeat. I built a condition where if close>0, enter long. After 5 bars, exit long. I assumed this would just keep creating positions one after another. It produces zero trades. Code is pasted in txt file.
If I may be allowed to wax pedantic for a while,- Your Condition 1 will make a long entry on EVERY bar
- Your Conditon 2 will exit a long position on EVERY bar after bar 5.
Hence from bar 6 onwards, there will be an entry AND an exit on every bar. As you do not have a BarsRequired directive, this will only show evaluation after bar 20. Therefore, all the evaluated bars shown will have entry and exit on the bar. Given the way the OnBarUpdate() function returns, the most likely return is a logical evaluation of the entire block, which in this case means that it would simply make neither entry nor exit, as that is logically flat on the bar.
To do what you seem to be describing you would have to filter your entries so that you only enter if there is not an existing position.
Code:// Condition set 1 if (Position.MarketPosition != MarketPosition.Long && Close[0] > 0) { EnterLong(DefaultQuantity, "long"); }
Code:// Condition set 2 if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry() == 6) { ExitLong("long"); }
Last edited by koganam; 02-07-2011, 12:50 AM.
Comment
-
koganam:
- Your Condition 1 will make a long entry on EVERY bar
- Your Conditon 2 will exit a long position on EVERY bar after bar 5.
Then, the second condition will exit long position 5 bars from entry of long position "long"...correct?
I have i one position per direction limit, and the exit is 5 bars from the entry of position labeled "long" ...?
At a minimum, shouldn't I see one entry at the very beginning into a long position?
Because of the way that ExitLong() functions, the market position filter is implied. Nonetheless, so as to avoid any possible unintended consequences, I would make it explicit thus.
Note that your ExitLong() syntax also seems incorrect, at least according to the syntax primitives in the NT help.
Thank you for your intput. Note that my goal for this strategy is to simply enter into many short lived long positions regardless of market/price action. Obviously it is for informational testing purposes and not to make a profit.
Thanks for the input and suggestions,
Meegwell
Comment
-
I am limited to one position per direction. So I would expect to see this enter a long position (labeled "long") at the first available bar.
Then, the second condition will exit long position 5 bars from entry of long position "long"...correct?
I have i one position per direction limit, and the exit is 5 bars from the entry of position labeled "long" ...?
At a minimum, shouldn't I see one entry at the very beginning into a long position?
"Hence from bar 6 onwards, there will be an entry AND an exit on every bar. As you do not have a BarsRequired directive, this will only show evaluation after bar 20. Therefore, all the evaluated bars shown will have entry and exit on the bar." (emphasis added)
Here, you were asking about the first 6 bars. Their evaluation will not be shown as they are before bar20.
Comment
-
I changed the code to this, as you suggest, with the same results...zero trades:
Code:///<summary> /// Called on each bar update event (incoming tick) ///</summary> protectedoverridevoid OnBarUpdate() { // Condition set 1 if (Position.MarketPosition != MarketPosition.Long && Close[0] > 0) { EnterLong(DefaultQuantity, "long"); } // Condition set 2 if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry() == 6) { ExitLong("long"); } }
Comment
-
If someone could suggest something for this simple goal (can be achieved w/ wizard) that works I would appreciate it. I'll restate my goal:
Im trying to do a very simple strategy for testing purposes where I simply enter a long position, hold it for x days, exit, repeat. I built a condition where if close>0, enter long. After 5 bars, exit long. I assumed this would just keep creating positions one after another. It produces zero trades.
Comment
-
Let us try a little debugging. Add the code in red, then check the output window to see if you get any text telling you about the entries.
In the meantime, do you have any entries in the NT log relating to errors from the strategy?
Code:protectedoverridevoid OnBarUpdate() { // Condition set 1 if (Position.MarketPosition != MarketPosition.Long && Close[0] > 0) { [COLOR="Red"]Print(""); Print("Long entry on bar: " + CurrentBar);[/COLOR] EnterLong(DefaultQuantity, "long"); [COLOR="Red"]Print("Long entry should have been made on bar: " + CurrentBar);[/COLOR] } // Condition set 2 if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry() == 6) { [COLOR="red"]Print(""); Print("Long exit on bar: " + CurrentBar);[/COLOR] ExitLong("long"); [COLOR="Red"]Print("Long exit should have been made on bar: " + CurrentBar);[/COLOR] } }
Comment
-
I just copied your code so that I could see what is going on. Right from the start, you are generating an exception because your variable (which is not even used), is called bars, so the property is generated as Bars, which is a reserved name in NT, so is causing problems in the getter/setter.
As it did not take very long once I input your code, I have simply written the strategy for you, and corrected the variable, and also turned it into a parameter, just in case you may want to optimize the number of bars.
I must say I am a bit surprised that the strategy may actually be viable. Well, they do say; "Simple is better".
EDIT: Oops. It looks like I misspelled your name. Sorry.Attached Files
Comment
-
I appreciate your trying to help but we are getting way too complex for such a simple request...its well beyond my desire to keep it simple w/ the wizard at this point.
Thanks
Originally posted by koganam View PostLet us try a little debugging. Add the code in red, then check the output window to see if you get any text telling you about the entries.
In the meantime, do you have any entries in the NT log relating to errors from the strategy?
Code:protectedoverridevoid OnBarUpdate() { // Condition set 1 if (Position.MarketPosition != MarketPosition.Long && Close[0] > 0) { [COLOR=red]Print("");[/COLOR] [COLOR=red]Print("Long entry on bar: " + CurrentBar);[/COLOR] EnterLong(DefaultQuantity, "long"); [COLOR=red]Print("Long entry should have been made on bar: " + CurrentBar);[/COLOR] } // Condition set 2 if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry() == 6) { [COLOR=red]Print("");[/COLOR] [COLOR=red]Print("Long exit on bar: " + CurrentBar);[/COLOR] ExitLong("long"); [COLOR=red]Print("Long exit should have been made on bar: " + CurrentBar);[/COLOR] } }
Comment
-
Understood. However, you did have a basic initial problem with the strategy, that I found when I copied your code, run it, and looked in the log. I have already made another post, with an attachment for you. It really would not have taken so long if I had just downloaded your code and tried it in the first place. Sometimes when we who think we are teachers try to help, we make things more difficult than they need be. Regards.
Comment
-
I really appreciate your effort and thank you. I posted a different thread to try to start fresh because I really feel like this is simple...Ill follow up there.
As far as being viable, its not - or I should say it shouldn't be. Thats not the point. It is to be used as a adaptable statistical benchamark...adaptable to the different markets I throw at it. Its purpose is not to implement live, but as a tool for my elaborate testing and development process....which, at the end of the day, produces simple strategies!!!
go figure...
Thansk again,
Meegwell
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by traderqz, Today, 12:06 AM
|
10 responses
18 views
0 likes
|
Last Post
by traderqz
Today, 02:49 PM
|
||
Started by algospoke, 04-17-2024, 06:40 PM
|
5 responses
46 views
0 likes
|
Last Post Today, 02:36 PM | ||
Started by arvidvanstaey, Today, 02:19 PM
|
1 response
6 views
0 likes
|
Last Post Today, 02:33 PM | ||
Started by mmckinnm, Today, 01:34 PM
|
3 responses
5 views
0 likes
|
Last Post Today, 02:12 PM | ||
Started by f.saeidi, Today, 01:32 PM
|
2 responses
9 views
0 likes
|
Last Post
by f.saeidi
Today, 02:10 PM
|
Comment