Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Sell at opening with profit
Collapse
X
-
Yes, the example you found will "alleviate" what you need to some degree. It will still not be perfect since you are not going down to the tick level.
This is generally why people will go into forward testing their strategy with Market Replays or just simulating on live data after they do some preliminary backtests. These forward tests provide more conclusive results that are more accurate than backtests, but take more time to conduct.
-
Thank you very much for your help!
Now everything is clear.
I assume then that I will never be able to backtest a rule like "buy if today's open is higher than yesterday's close), as the order should be executed in the same day's bar.
Thanks so much!
----------------------------------------
Edited: I think this is what I need:
Last edited by eswap0; 06-05-2008, 01:40 PM.
Leave a comment:
-
Hi eswap0,
The first thing you would need to do is debug your code as per these tips: http://www.ninjatrader-support.com/v...ead.php?t=3418
I also suspect you may be running into this issue: http://www.ninjatrader-support.com/v...ead.php?t=3170
Please check the error log in the Control Center for anything fishy.
In regards to CalculateOnBarClose, historical data will always be assessed as if CalculateOnBarClose = true. This is the nature of backtesting because you cannot look into the future thus you cannot place trades on the same bar since you already know the closing price of that bar. You can only place a trade on the next bar. In realtime it is a different story.
Please read this article from the Help Guide: http://www.ninjatrader-support.com/H...sBacktest.html
To print time you can use Time[0].
Code:Print(Time[0] + " Enter Long Here");
Leave a comment:
-
Thank you very much for your help.Originally posted by Josh View PostI would use Close[0] instead of Open[0]. This is the case because when the new bar starts, the Close[0] price would reflect the latest change in price. Especially when running with CalculateOnBarClose = false.
You may need to debug your code a little. Try some prints to see what value you are getting out of GetProfitLoss. This will help you better determine the behavior you are experiencing.
I started again from zero, and tried to understand how the systrem works, and followed your suggestion of printing the outputs.
I am using 1 day bars, and try this simple order:
If today's open value is above yesterday close, then buy.
I wrote:
As you can imagine, it didn't work: the check is ok, but the EnterLong order is excecuted not today after checking the opening but tomorrow.Code:if (Open[0] > Close[1]) { EnterLong(DefaultQuantity, ""); }
Aha! it must be the CalculateOnBarClose, I thought...
Ok, then I set: CalculateOnBarClose = false
But the behavior is exactly the same.
At this point I exactly don't understand the following:- Is there any way to simulate within the bar, instead of "in following bar"?
- What exactly "CalculateOnBarClose" means?
Thank you very much for your patience.
jm
PS: by the way, I could't find the way to print the bar date (or time) in the output, in order to easilly check the calculations...Last edited by eswap0; 06-04-2008, 11:30 AM.
Leave a comment:
-
I would use Close[0] instead of Open[0]. This is the case because when the new bar starts, the Close[0] price would reflect the latest change in price. Especially when running with CalculateOnBarClose = false.
You may need to debug your code a little. Try some prints to see what value you are getting out of GetProfitLoss. This will help you better determine the behavior you are experiencing.
Leave a comment:
-
Thank you very much for your help.Originally posted by Josh View PostYou can do this by running a check against the PnL of your current position. If it is positive then you can do a ExitLong() or ExitLongLimit().
To check your unrealized PnL you can use this: GetProfitLoss()
I did this:
But I am afraid all long positions are exited at the Open, no matter if I get a profit or loss exit...Code:[SIZE=2][FONT=Courier New][COLOR=#008000]// Condition set 2[/COLOR][/FONT][/SIZE] [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Position.GetProfitLoss(Open[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]], PerformanceUnit.Percent) > [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT] [SIZE=2][FONT=Courier New]{[/FONT][/SIZE] [SIZE=2][FONT=Courier New]ExitLong([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT] [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]

Thanks!
Leave a comment:
-
You can do this by running a check against the PnL of your current position. If it is positive then you can do a ExitLong() or ExitLongLimit().
To check your unrealized PnL you can use this: GetProfitLoss()
Leave a comment:
-
Sell at opening with profit
I am pretty newbie, trying to develope my first script, and find problems trying to write:
" exit long at the firsts open price with profit"
Any clue?
Thanks a lot!
Tags: None
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
602 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
347 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
559 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Leave a comment: