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 bill2023, Yesterday, 08:51 AM
|
8 responses
43 views
0 likes
|
Last Post
by bill2023
Today, 09:27 PM
|
||
Started by yertle, Today, 08:38 AM
|
6 responses
25 views
0 likes
|
Last Post
by ryjoga
Today, 09:17 PM
|
||
Started by algospoke, Yesterday, 06:40 PM
|
2 responses
24 views
0 likes
|
Last Post
by algospoke
Today, 07:04 PM
|
||
Started by ghoul, Today, 06:02 PM
|
3 responses
16 views
0 likes
|
Last Post Today, 06:43 PM | ||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
46 views
0 likes
|
Last Post
by jeronymite
Yesterday, 10:10 PM
|
Comment