How can this be done?
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
entering 1 second before close of candle
Collapse
X
-
entering 1 second before close of candle
I am running automated strategy that is set to "OnBarClose". As we know when a strategy takes positons between crossovers, the close of the candle triggers the entry. using the same concept I want to setup entry at the 1 second mark before the ball closes. EX: 1 min candle crosses over SMA and bar timer says candle closes in five seconds. When the bar timer goes to 1 second before close I want to enter there.
How can this be done?Tags: None
- Likes 1
-
Hello Teebone21,
Thanks for your post.
With Calculate.OnBarClose your strategy code is executed once at the end of the bar and if a cross condition is true the order is placed and then filled on the subsequent bar (assuming market order type).
What you want to do is possible. You would need to change your strategy to Calculate.OnPriceChange or Calculate.OnEachTick and you would need to add a 1-second data series. The Calculate change is need so that your strategy can detect an intrabar cross event and then check the second bars for the 59th second.
You will be faced with some difficult choices as intrabar calculations mean that a cross can occur in one tick and then can uncross in another tick and this can occur potential 1000's of times in one bar depending on the bar size and the price movement and in the end (bar close) it may end up that no cross occurred. This is the advantage of waiting until bar Close to run your calculations as the data at that point does not change, however, the downside is that the order is placed/filled on the next bar.
Paul H.NinjaTrader Customer Service
- Likes 1
-
Hi, I need to enter positions with StopLimit orders. In order to avoid getting the error: "order cannot be placed below market level", I want to place the orders 1 or 2 seconds before the 1-minute bar close. Can I call the BarTimer-Counter developed and shared by PaulH from my strategy to achieve this?
Thank you. BobPerez
Comment
-
Hello bobperez,
Thanks for your note.
The error message "order cannot be placed below market level" means that the order you are trying to place cannot be placed below the current market price. Submitting the order 1-2 seconds before the close of the bar would not prevent the order from submitting to a price below the current market price.
To resolve this, you would need to make sure that your strategy submits that order above the current market price. Note if this is due to market volatility then there isn't really a way to 100% avoid this occurring, as in volatile markets the market could move so far and fast that this would occur.
You could add prints to your strategy that print out the Close[0] price to see the current market price at the time the order is placed and prints the price that your order is being submitted to. These values could be compared in the New > NinjaScript Output window to see if your order is placed below the market price. Once you know those values, you could modify your order to submit to a price that is above the current market price.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121
A simple explanation of four basic Order types:- BUY LIMIT is a Buy Order where the desired ENTRY price is BELOW the Current Ask price. Ask price must move DOWN to the Entry price for the order to execute as a Market Order.
- BUY STOP is a Buy Order where the desired ENTRY price is ABOVE the Current Ask price. Ask price must move UP to the Entry price for the order to execute as a Market Order.
- SELL LIMIT is a Sell Order where the desired ENTRY price is ABOVE the Current Bid price. Bid price must move UP to the Entry price for the order to execute as a Market Order.
- SELL STOP is a Sell Order where the desired ENTRY price is BELOW the Current Bid price. Bid price must move DOWN to the Entry price for the order to execute as a Market Order.
Let me know if I may assist further.Brandon H.NinjaTrader Customer Service
Comment
-
Thanks Brandon,
I inserted the following code, but the error message still appears:
if ( GetCurrentAsk() < (High[0] + 1*TickSize))
EnterLongStopLimit(0,false,DefaultQuantity, (High[0] + 1*TickSize),Stop,"");
else
EnterLongStopLimit(0,false,DefaultQuantity, GetCurrentAsk(),Stop,"");
Comment
-
Hello bobperez,
Thanks for your note.
To understand why the script is behaving as it is, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.
In the strategy, add prints (outside of any conditions) that print the values of every variable used in every condition that places an order, the price of the order being submitted, the current Close[0] price and the time of that bar.
Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).
Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121
Let me know if I may assist further.Brandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by trilliantrader, 04-18-2024, 08:16 AM
|
4 responses
18 views
0 likes
|
Last Post Today, 10:33 PM | ||
Started by mgco4you, Today, 09:46 PM
|
1 response
10 views
0 likes
|
Last Post Today, 09:56 PM | ||
Started by wzgy0920, Today, 09:53 PM
|
0 responses
10 views
0 likes
|
Last Post
by wzgy0920
Today, 09:53 PM
|
||
Started by Rapine Heihei, Today, 08:19 PM
|
1 response
10 views
0 likes
|
Last Post Today, 08:30 PM | ||
Started by Rapine Heihei, Today, 08:25 PM
|
0 responses
10 views
0 likes
|
Last Post Today, 08:25 PM |
Comment