Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Stop market by bar close
Collapse
X
-
Hello gadyair,
Thank you for your post.
We would be more than happy to assist however I am unsure of what you are looking for.
So that we may assist could you please clarify you inquiry further? If possible could you provide an example?
Do you want the order to execute when, for example, a minute bar closes?
What price would you want it to be placed on?
How many ticks from the current market price?
Spencer F.NinjaTrader Customer Service
Comment
-
Hello, Thank you for you respone.
I want to set a stop market, but I want it's sell just if the 5 min bar close below the price I set.
For example, my long position is at 100, the stop that I want is at the low of the candle(or the previous candle), lets says it 98 - But I decide to sell just if the 5 min candle close bellow 98. if it touches 95 but close 98.5 its not sell.
Hope I clarified myself better.
Comment
-
Hello gadyair,
Thank you for your post.
This should be possible using a custom NinjaScript Strategy.
If you have a programming background, our NinjaScript team may provide you links to samples that would help you write the script yourself. For information on getting started with NinjaScript, please see the tips and resources in the following forum post:
https://forum.ninjatrader.com/forum/...pts#post786040
Otherwise, we can provide you with resources to find a programmer to create the add-on for you. Please let me know if this option interests you so I may follow up accordingly.Spencer F.NinjaTrader Customer Service
Comment
-
Hello gadyair,Originally posted by gadyair View PostI want to set a stop market, but I want it's sell just if the 5 min bar close below the price I set.
For example, my long position is at 100, the stop that I want is at the low of the candle(or the previous candle), lets says it 98 - But I decide to sell just if the 5 min candle close bellow 98. if it touches 95 but close 98.5 its not sell.
Hope I clarified myself better.
If someone had a similar template I will be grateful.
Thank you for your patience.
As you already had an existing thread on this same topic, I merged the two threads together. Please refrain from opening new threads for the same topic in the future in order to prevent duplicating efforts by our support team. Thank you for your understanding in this matter.
What you are requesting should be possible with a custom NinjaScript strategy. You could set a condition that checks if the 5-minute bar closes below a set price. This could be done in the Strategy Builder or in an unlocked NinjaScript strategy. We have a webinar video overview of the Strategy Builder as well as examples of common conditions and actions used in the builder at the following links:- https://youtu.be/VxU4FR6GWNA
- https://ninjatrader.com/support/help...on_builder.htm
- https://ninjatrader.com/support/help...t8/actions.htm
You can get price information for a bar using a series such as Open, High, Low, Close, etc. Since you referred to the low price or the candle, you could use Low[int barsAgo] in your script to get the low of a specific bar and then use that value for your SetStopLoss() method.
Please let us know if we may be of further assistance.
Comment
-
I would like a little help.
I want an exit strategy- so I need it to adopt my account position, but it doesn't open that option.
It's compiled successfully.
(The profit will be at the mid-Bollinger band of 30 candles with 2 stv.
if it is long The stop should save just once the lowest price of 15 previous candles before the strategy run. it close just if one of the next candles close below it low.
if it is short The stop should save just once the highest price of 15 previous candles before the strategy run. it close just if one of the next candles closes up it high.)
using System;
using System.Collections.Generic;
using System.Linq;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Strategies;
using System.Text;
using System.Threading.Tasks;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Indicators;
namespace NinjaTrader.NinjaScript.Strategies
{ public class ExitStrategyAnyPosition : Strategy
{
private Bollinger _bollinger;
private Series<double> bollingerMid;
private double stopPrice;
private bool stopPriceSet = false;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Exit strategy for any position.";
Name = "ExitStrategyAnyPosition";
Calculate = Calculate.OnBarClose;
IsAdoptAccountPositionAware = true;
StartBehavior = StartBehavior.AdoptAccountPosition;
}
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Day, 1);
else if (State == State.DataLoaded)
{
bollingerMid = Bollinger(BarsArray[0], 30, 2).Middle;
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (Position.MarketPosition == MarketPosition.Long || Position.MarketPosition == MarketPosition.Short)
{
// Set stop price only once for long positions.
if (Position.MarketPosition == MarketPosition.Long && !stopPriceSet && CurrentBars[1] >= 15)
{
stopPrice = Low[1];
for (int i = 1; i <= 15; i++)
{
if (Low[i] < stopPrice)
stopPrice = Low[i];
}
stopPriceSet = true;
}
// Set stop price only once for short positions.
if (Position.MarketPosition == MarketPosition.Short && !stopPriceSet && CurrentBars[1] >= 15)
{
stopPrice = High[1];
for (int i = 1; i <= 15; i++)
{
if (High[i] > stopPrice)
stopPrice = High[i];
}
stopPriceSet = true;
}
// Exit long position if one of the next candles closes below the stop price.
if (Position.MarketPosition == MarketPosition.Long && CurrentBars[0] >= 1 && Low[0] < stopPrice)
{
ExitLong();
return;
}
// Exit short position if one of the next candles closes above the stop price.
if (Position.MarketPosition == MarketPosition.Short && CurrentBars[0] >= 1 && High[0] > stopPrice)
{
ExitShort();
return;
}
// Exit if price reaches the mid Bollinger band.
if (Position.MarketPosition == MarketPosition.Long && Close[0] >= bollingerMid[0])
{
ExitLong();
}
else if (Position.MarketPosition == MarketPosition.Short && Close[0] <= bollingerMid[0])
{
ExitShort();
}
}
}
}
}
Comment
-
Hello gadyair,
Thank you for your reply.
A Strategy script may only manage positions and orders generated from that same strategy instance. If you would like to apply an exit strategy to a position that was manually entered, you would need to utilize the Account class to subscribe to account-related events and information. This would allow you to see account-specific information rather than information only specific to a strategy. The methods and properties for the account class are listed here:- https://ninjatrader.com/support/help...ount_class.htm
- Submit() may be used to submit order objects; this would be in line with the more advanced unmanaged approach rather than the managed approach that is available for strategies:
Please let us know if we may be of further assistance.
Comment
- https://ninjatrader.com/support/help...ount_class.htm
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
39 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment