I would like to enter on a market and/or limit order when price trades through an indicator value, such as the 20 ema. How would this be done in ninjascript?
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
How to enter on an indicator value in ninjascript
Collapse
X
-
Hello wooofad,
You could create a condition where the Close price is crossing above the SMA(20)..
if (CrossAbove(Close, SMA(20), 1))
{
EnterLong();
}
Below are public links to the help guide on CrossAbove, Close, and SMA.
Also, below is a link to a forum post with helpful information about getting started with NinjaScript.
I recommend the Strategy Builder 301 course linked in that forum post.Chelsea B.NinjaTrader Customer Service
-
Hello wooofad,
Is this a different separate inquiry that no longer uses the cross of the close price with an sma?
You can update the price of a limit to the price of an SMA.
EnterLongLimit(SMA(20)[0]);
You can run this with Calculate on bar close set to false to have OnBarUpdate update with each tick in real-time.
If you want this to work historically, you would want intra-bar granularity.
Below is a link to a post on intra-bar granularity.
If you are wanting to place a limit order when a cross has occurred, you would first need to detect the cross to find the price at which the two series crossed. This means you would have to place the order (or adjust the price of a working order) after the cross has occurred.
A limit order fills at the specified price or better.
A buy limit order placed after a cross above at the price of the cross may fill immediately or may not fill at all until the market comes back to it.
A sell limit placed after a cross above at the price of the cross would fill immediately at the market price.
The rules would be reversed for a cross below. (i.e. a buy limit would fill immediately at market and a sell might sit until the market comes back)Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
3 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
18 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
1 view
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
6 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
||
Started by timmbbo, Today, 08:59 AM
|
2 responses
10 views
0 likes
|
Last Post
by bltdavid
Today, 04:10 PM
|
Comment