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 judysamnt7, 03-13-2023, 09:11 AM
|
4 responses
55 views
0 likes
|
Last Post
by DynamicTest
Today, 08:25 PM
|
||
Started by ScottWalsh, Today, 06:52 PM
|
4 responses
35 views
0 likes
|
Last Post
by ScottWalsh
Today, 07:40 PM
|
||
Started by olisav57, Today, 07:39 PM
|
0 responses
7 views
0 likes
|
Last Post
by olisav57
Today, 07:39 PM
|
||
Started by trilliantrader, Today, 03:01 PM
|
2 responses
19 views
0 likes
|
Last Post
by helpwanted
Today, 07:25 PM
|
||
Started by cre8able, Today, 07:24 PM
|
0 responses
8 views
0 likes
|
Last Post
by cre8able
Today, 07:24 PM
|
Comment