Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
help code
Collapse
X
-
deleted previous codes ,as they were causing confusion
I want to set my stop below current day open - 10 ticks ,Why am I not getting desired result
HTML Code:{ #region Variables private int stoplossticks = 10; private int profittargetticks = 20; #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { /* There are several ways you can use SetStopLoss and SetProfitTarget. You can have them set to a currency value or some sort of calculation mode. Calculation modes available are by percent, price, and ticks. SetStopLoss and SetProfitTarget will submit real working orders unless you decide to simulate the orders. */ SetStopLoss(CalculationMode.Ticks, stoplossticks); SetProfitTarget(CalculationMode.Ticks, profittargetticks); CalculateOnBarClose = false; Add(CurrentDayOHL()); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Resets the stop loss to the original value when all positions are closed if (Position.MarketPosition == MarketPosition.Flat) { SetStopLoss(CalculationMode.Ticks, stoplossticks); } // If a long position is open, set stoploss below current day open - 10 ticks else if (Position.MarketPosition == MarketPosition.Long) { // Once the price is greater than entry price set stoploss below current day open if (High[0] > (Position.AvgPrice-CurrentDayOHL().CurrentOpen[0] )+ 10 * TickSize) { SetStopLoss(CalculationMode.Ticks, (Position.AvgPrice-CurrentDayOHL().CurrentOpen[0] )+ 10 * TickSize); } } // Condition set 1 if (Close[0] > CurrentDayOHL().CurrentOpen[0] && High[0] > High[1]) { EnterLong(); } // Condition set 2 if (Close[0] < CurrentDayOHL().CurrentOpen[0] && Low[0] < Low[1]) { EnterShort(); } } #region Properties #endregion } }
Comment
-
Hi as per condition i am getting Dots at the correct bars why am i getting long signal on the next bar
http://i.imgur.com/39blV.jpg
HTML Code:protected override void OnBarUpdate() { // Condition set 1 if (Close[1] > CurrentDayOHL().CurrentOpen[0] && Close[1]>Open[1] && High[0]>Open[0] && High[0] > High[1]) { Print(""); DrawDot("My Dot"+ CurrentBar,false,0,High[0],Color.Blue); EnterLong(); } // Condition set 2 if (Close[1] < CurrentDayOHL().CurrentOpen[0] && Close[1]<Open[1] && Low[0]<Open[0] && Low[0] < Low[1]) { Print(""); DrawDot("My Dot"+ CurrentBar,false,0,Low[0],Color.Red); EnterShort(); } }
Comment
-
plz see pic below marked with arrow ,why am I getting lot size everywhere as 100@,when I have not given this in my strategy, how can I change it ? I want target 1=50,target2=25 and target3=25
http://i.imgur.com/lJD7v.png
Comment
-
Ninja,
This is a plot of some execution that occurred in the past. If you want to see the live orders with stop loss and take profits, I would suggest opening a new chart, and then enabling chart trader on this chart. You cannot have chart trader on a chart that has a strategy active on it.Adam P.NinjaTrader Customer Service
Comment
-
Thanks for helping me
I want to break even by partially booking some lots for that my calculation is this
private int target1 = 4; ( I am considering for commission etc)
private int stop =2; ( the stop value ,below current day open for long and above current day open for short)
so if current day open is at 5000 and my Position.AvgPrice is 5005
my risk in this trade is : 5005-5000= 5
so total points 4+2+5 =11 points
if lot size is 50 and I buy 10 lots so risk is (50*10)=500*11= 5500 INR
To cover this risk I have sell 60% out of total 500 lots so 5500/300=18.33 points
Now how can I SetProfitTarget to cover these 18.33 points
how do I book these 18.33 points with 6 lots ?what changes should I make in above Target1 profit booking ?HTML Code:SetProfitTarget("target1", CalculationMode.Price, (Position.AvgPrice+(Position.AvgPrice-current day open+stop) + (Target1*TickSize));
plz look at the codes below
HTML Code:public class test3 : Strategy { #region Variables private int target1 = 4; private int target2 = 10; private int target3 = 10; private int stop =2; #endregion protected override void Initialize() { Add(CurrentDayOHL()); CalculateOnBarClose = true; EntryHandling = EntryHandling.UniqueEntries; } private void GoLong() { SetStopLoss("target1", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] - (Stop*TickSize), false); SetStopLoss("target2", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] - (Stop*TickSize), false); SetStopLoss("target3", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] - (Stop*TickSize), false); SetProfitTarget("target1", CalculationMode.Price, (Position.AvgPrice+(Position.AvgPrice-stop)) + (Target1*TickSize)); SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize)); SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize)); EnterLong("target1"); EnterLong("target2"); EnterLong("target3"); } private void GoShort() { SetStopLoss("target1", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] + (Stop*TickSize), false); SetStopLoss("target2", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] + (Stop*TickSize), false); SetStopLoss("target3", CalculationMode.Price, CurrentDayOHL().CurrentOpen[0] + (Stop*TickSize), false); SetProfitTarget("target1", CalculationMode.Price, (Position.AvgPrice-(stop-Position.AvgPrice)) - (Target1*TickSize)); SetProfitTarget("target2", CalculationMode.Price, Close[0] - ((Target1+Target2)*TickSize)); SetProfitTarget("target3", CalculationMode.Price, Close[0] - ((Target1+Target2+Target3)*TickSize)); EnterShort("target1"); EnterShort("target2"); EnterShort("target3"); } protected override void OnBarUpdate() { EntryHandling = EntryHandling.UniqueEntries; if (Position.MarketPosition != MarketPosition.Flat) return; // Condition set 1 if ( (Close[1] > CurrentDayOHL().CurrentOpen[0] && Close[1]>Open[1] && High[0]>Open[0] && High[0] > High[1]) || // Condition set 2 (CrossAbove(High, CurrentDayOHL().CurrentOpen, 1)) && Close[1]>Open[1] && High[0]>Open[0] && High[0] > High[1] ) { GoLong(); { PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\OrderFilled.wav"); } } // Condition set 3 else if ((Close[1] < CurrentDayOHL().CurrentOpen[0] && Close[1]<Open[1] && Low[0]<Open[0] && Low[0] < Low[1]) || // Condition set 4 (CrossBelow(Low, CurrentDayOHL().CurrentOpen, 1)) && Close[1]<Open[1] && Low[0]<Open[0] && Low[0] < Low[1] ) { GoShort(); { PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\OrderFilled.wav"); } } }Last edited by SLASH; 05-08-2012, 01:18 PM.
Comment
-
-
ninja hattori, the scale out of a position you would need to scale in first it the desired quantities -
For the target value needed to get 'risk free' you can dynamically calculate either a price or tick value in your OnBarUpdate and adjust the SetProfitTarget to it -
Comment
-
Vol alert
Hi please help me with indicator,editing this post because I am not able to post new thread
Check the following code ,i want to edit this indicator I want to Draw a rectangle ,Whenever specific high volume occur.
HTML Code:// This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// Enter the description of your new custom indicator here /// </summary> [Description("Enter the description of your new custom indicator here")] public class aa : Indicator { #region Variables // Wizard generated variables private int highVolume = 1000; // Default setting for HighVolume private int rectWidth = 0; private Color highAlert = Color.Black; // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { // Add(new Plot(new Pen(Color.Blue, 2), PlotStyle.Bar, "Volume")); //Add(new Line(Color.DarkGray, 0, "Zero line")); { CalculateOnBarClose = true; Overlay = true; } } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { Value.Set(Volume[0]); if (Volume[0] >= HighVolume) { DrawRectangle("Rectangle", false, rectWidth+ CurrentBar,true, 0, High[0] + 20*TickSize, highAlert, Color.Blue, Color.BlueViolet, 5); } } #region Properties [Description("Enter volume threshold")] [Category("Parameters")] public int HighVolume { get { return highVolume; } set { highVolume = Math.Max(1, value); } } /// <summary> /// </summary> [Description("Select Color")] [Category("Colors")] [Gui.Design.DisplayName("highAlert")] public Color HighAlert { get { return highAlert; } set { highAlert = value; } } // Serialize Color object [Browsable(false)] public string highAlertSerialize { get { return NinjaTrader.Gui.Design.SerializableColor.ToString(highAlert); } set { highAlert = NinjaTrader.Gui.Design.SerializableColor.FromString(value); } } #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private aa[] cacheaa = null; private static aa checkaa = new aa(); /// <summary> /// Enter the description of your new custom indicator here /// </summary> /// <returns></returns> public aa aa(int highVolume) { return aa(Input, highVolume); } /// <summary> /// Enter the description of your new custom indicator here /// </summary> /// <returns></returns> public aa aa(Data.IDataSeries input, int highVolume) { if (cacheaa != null) for (int idx = 0; idx < cacheaa.Length; idx++) if (cacheaa[idx].HighVolume == highVolume && cacheaa[idx].EqualsInput(input)) return cacheaa[idx]; lock (checkaa) { checkaa.HighVolume = highVolume; highVolume = checkaa.HighVolume; if (cacheaa != null) for (int idx = 0; idx < cacheaa.Length; idx++) if (cacheaa[idx].HighVolume == highVolume && cacheaa[idx].EqualsInput(input)) return cacheaa[idx]; aa indicator = new aa(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.HighVolume = highVolume; Indicators.Add(indicator); indicator.SetUp(); aa[] tmp = new aa[cacheaa == null ? 1 : cacheaa.Length + 1]; if (cacheaa != null) cacheaa.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheaa = tmp; return indicator; } } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { /// <summary> /// Enter the description of your new custom indicator here /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.aa aa(int highVolume) { return _indicator.aa(Input, highVolume); } /// <summary> /// Enter the description of your new custom indicator here /// </summary> /// <returns></returns> public Indicator.aa aa(Data.IDataSeries input, int highVolume) { return _indicator.aa(input, highVolume); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// Enter the description of your new custom indicator here /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.aa aa(int highVolume) { return _indicator.aa(Input, highVolume); } /// <summary> /// Enter the description of your new custom indicator here /// </summary> /// <returns></returns> public Indicator.aa aa(Data.IDataSeries input, int highVolume) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.aa(input, highVolume); } } } #endregion
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
671 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
379 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
111 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
582 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment