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
backtesting Buy and sell at limit on daily bar chart
Collapse
X
-
Hello guilhem,
Thank you for your patience.
If you need intrabar resolution, I would recommend running the logic on a 1-minute series so you can check the time of day down to the minute. I have attached a simple example where the strategy goes long at the beginning of the session and exits at the end of the session (CME US Index Futures RTH). This idea can be expanded by setting up two limit orders at the beginning of the session, one to go long and the other to go short. If one of those orders are filled, cancel the other order with CancelOrder. For an example of how to use CancelOrder properly, please see this reference sample on CancelOrder(). At the end of the session, if you are long, exit the long position. If the position is short, close the short position. You may place this file within Documents\NinjaTrader 8\bin\Custom\Strategies to compile and run it.
Please let me know if I can assist further.
-
my issue really is why can t i get an order filled on a daily bar chart on current bar if it is not forward looking ? which order type should i use to do so ?
thanks for your replies ;-)
Best
Guilhem
Leave a comment:
-
-
Let me start over.
Here is what I would like to do.
I want to backtest on daily data the following:
if (high of current bar > Open of current bar + 10 ticks) then, I want to be short 1 lot at Open of current bar + 10 ticks in the current bar.
if (low of current bar < Open of current bar - 10 ticks) then, i want to be long 1 lot at Open of current bar - 10 ticks in the current bar
Whatever happened, I want to close all positions during the current bar at close of market.
I am unable to do this on daily bars.
I suppose the best way to do this therefore has to be using intraday bars ?
But considering that there is not forward looking in my algo, I would have thought there should be a way to get this done on daily bars ?
Best
Guilhem
Leave a comment:
-
Hello guilhem,
Thanks for your patience.
I fixed the link for exporting in my last post. I should have an example for you tomorrow morning.
I look forward to assisting further.
Leave a comment:
-
protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; EnterShortLimit(Open[0] + 0.10); EnterLongLimit(Open[0] - 0.10); } on the strategy analyser, i set the positions to be closed at eod. I was expecting to get filled on both order if High and Low exceeded the limit orders for example. Never more than one trade takes place even if both high and low are further to the open than 10 ticks Also, which is annoying, positions are open on next day rather than current day. And finally, when positions are closed, they are on next bar rather than current bar. I was hoping to get done on the current bar if my buying order was likely to be filled ie Low < Open of current bar - 10 tick i was hoping to get done on the current bar if my selling order was likely to be filled ie High > Open of current bar + 10 tick and I was expecting then all positions to be closed if any order got filled...
Leave a comment:
-
Hello guilhem,
Thank you for your reply.
This should not require the use of the unmanaged approach. The execution is happening on the next bar because the strategy is programmed to exit on the close of the bar. The logic will take place at the first tick of the next bar.
Could you please clarify point 'b'. My test strategy was able to make long and short trades.
To use a limit order instead of a market order, you may use either EnterShortLimit() or EnterLongLimit() These take a limit price as a parameter and will allow you to target a specific price level.
If possible, could you please export your script and post it here so I can review?
I look forward to assisting further.
Last edited by NinjaTrader_ChrisL; 03-18-2019, 02:22 PM.
Leave a comment:
-
My problems are the following:
a - execution happens on next bar
b - i can only enter one of those trades although it is perfectly ok to do both trades in reality
c - i would like to sellbuy at my price with a limit order
should i be using the unmanaged approach therefore ?
Rgds
Leave a comment:
-
Hello guilhem,
Thank you for your post.
The following example demonstrates this:
Code:protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; //if the high > Open + 10 ticks, I should be short //if the Low is < Open + 10 ticks I should be long if(Position.MarketPosition == MarketPosition.Long) { ExitLong(); } if(Position.MarketPosition == MarketPosition.Short) { ExitShort(); } if(High[0] > Open[0] + TickSize*10) { EnterShort(); } if(Low[0] < Open[0] + TickSize*10) { EnterLong(); } }
Please let me know if I can assist further.
Leave a comment:
-
backtesting Buy and sell at limit on daily bar chart
Hello,
I would like to back test a strategy which does the following:
EnterShort at open[0] + 10 ticks
EnterLong at open[0] - 10 ticks
Exit All Positions On Close
if the high > Open + 10 ticks, I should be short
if the Low is < Open + 10 ticks I should be long
whatever happens next, i should be squaring positions on the close.
Could anyone tell me how to create this simple strategy ?
My issue so far is that orders happen on next daily bar only once (meaning i am short or long whichever the system has decided should be first) and the open position is closed only when the system reverse.
I have set the number of positions more than 1
I name all entries with a different name
I apply the backtest on daily bars
Should i be using the unmanaged methodology ?
Thanks for your help
GuilhemTags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
238 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
383 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
||
Started by oviejo, Today, 12:28 AM
|
0 responses
1 view
0 likes
|
Last Post
by oviejo
Today, 12:28 AM
|
||
Started by pechtri, 06-22-2023, 02:31 AM
|
10 responses
125 views
0 likes
|
Last Post Today, 12:03 AM | ||
Started by judysamnt7, 03-13-2023, 09:11 AM
|
4 responses
59 views
0 likes
|
Last Post
by DynamicTest
Yesterday, 08:25 PM
|
Leave a comment: