![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jan 2008
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
|
hello, i am using the market simulation data, and have a very simple strategy developed for testing purposes only. the buy order goes off, but i can not, for the life of me, get any stop loss or profit target to trigger when running this strategy.
Please advise: // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { ///<summary> /// 4 ///</summary> [Description("4")] [Gui.Design.DisplayName("My custom strategy4")] publicclass MyCustomStrategy4 : Strategy { #region Variables // Wizard generated variables privateint myInput0 = 1; // Default setting for MyInput0 // User defined variables (add any user defined variables below) #endregion ///<summary> /// This method is used to configure the strategy and is called once before any strategy method is called. ///</summary> protectedoverridevoid Initialize() { SetStopLoss("buy", 1); SetProfitTarget("buy", 1); CalculateOnBarClose = true; } ///<summary> /// Called on each bar update event (incoming tick) ///</summary> protectedoverridevoid OnBarUpdate() { // Condition set 1 if (Close[0] >= 150) { EnterLong(DefaultQuantity, "Buy"); } } #region Properties [Description("")] [Category("Parameters")] publicint MyInput0 { get { return myInput0; } set { myInput0 = Math.Max(1, value); } } #endregion } } |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Jul 2007
Location: Fairfax, VA
Posts: 216
Thanks: 0
Thanked 0 times in 0 posts
|
Does that code even compile? I didn't think there was a SetStopLoss() with that signature. In any case, the default mode for SetStopLoss is currency, which means it will trigger when the price goes below one. These are the lines of code from my strategy I use for those two calls in percentage mode; I specify the parameters as whole numbers (e.g. 5 for 5%).
Code:
if (MyProfit > 0)
SetProfitTarget("", CalculationMode.Percent, MyProfit/100.0);
if (MyStop > 0)
SetStopLoss("", CalculationMode.Percent, MyStop/100.0, false);
Last edited by Pete S; 01-24-2008 at 06:52 AM.
Reason: Typo
|
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jan 2008
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
|
i used part of your code like this:
protectedoverridevoid Initialize() { SetProfitTarget("", CalculationMode.Percent, 0.50); SetStopLoss("", CalculationMode.Percent, 0.50, false); } and still no stop loss or profit target gets executed. getting very frustrated since i can not begin trading until i can get stop losses and profit targets to actually execute along with the buy/sell order. i have many strategies ready to implement, and this is the only part that doesn't work....all my long/short strategies actually execute the order as programmed, but i can't seem to get a stop loss or profit target to go along with it. am i the only one with this issue? is it because i'm using the market replay simulator? will i have this issue with a live $$ account? lord knows i don't want to try that as a test... |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
C# is case sensitive. Your entry signal name used when submitting an order ("Buy") is different than what you are using when calling SetStopLoss() ("buy"). Also, your syntax is incorrect.
Please try this: SetStopLoss("Buy", CaclulationMode.Ticks, 20, false); SetProfitTarget("Buy", CaclulationMode.Ticks, 40); CalculateOnBarClose = true;
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jan 2008
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
|
Ray, still not executing a stop loss or profit target. here's my whole strategy....i am apply this for the ticker symbol AAPL...as you can see, it's a very simple strategy...simply buy when price over 125...that executes at the end of the minute bar. but i never get a stop loss or profit target execution...what else can it be??
#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { ///<summary> /// 4 ///</summary> [Description("4")] [Gui.Design.DisplayName("My custom strategy4")] publicclass MyCustomStrategy4 : Strategy { #region Variables // Wizard generated variables privateint myInput0 = 1; // Default setting for MyInput0 // User defined variables (add any user defined variables below) #endregion ///<summary> /// This method is used to configure the strategy and is called once before any strategy method is called. ///</summary> protectedoverridevoid Initialize() { SetStopLoss("Buy", CaclulationMode.Ticks, 40, false); SetProfitTarget("Buy", CaclulationMode.Ticks, 40); CalculateOnBarClose = true; } ///<summary> /// Called on each bar update event (incoming tick) ///</summary> protectedoverridevoid OnBarUpdate() { // Condition set 1 if (Close[0] >= 125) { EnterLong(DefaultQuantity, "Buy"); } } protectedoverridevoid OnBarUpdate() #region Properties [Description("")] [Category("Parameters")] publicint MyInput0 { get { return myInput0; } set { myInput0 = Math.Max(1, value); } } #endregion } } |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jul 2007
Location: Fairfax, VA
Posts: 216
Thanks: 0
Thanked 0 times in 0 posts
|
.5 = 50%
You want to use .05 if you mean 5%. |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Jan 2008
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
|
ticks...price...percent...no matter what i use, don't get executed.
in latest example, i tried 40 ticks...tried 10 ticks, 1 tick, 100 ticks tried price of 0.50, 0.005, 0.05, 5, 10, 1, 100 tried percent... 0.01, 0.001, 0.05, 0.005, 0.50, 1, 5, 10, 100. doesn't matter what i use, no execution. maybe there is another setting i need to check? it could just be the code is correct but something else isn't selected? |
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Please check your syntax.
SetStopLoss("Buy", CaclulationMode.Ticks, 40, false); It should be "CalculationMode.Ticks".
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Sep 2008
Posts: 483
Thanks: 0
Thanked 2 times in 2 posts
|
|
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Hello,
This will not compile. You are correct.
Ben
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stop Losses not working? | zoltran | General Programming | 2 | 11-08-2007 04:00 AM |
| Splitting Profit Targets | fifty2aces | Strategy Development | 1 | 10-10-2007 08:00 AM |
| Profit Targets & 'Exit on Close' | dgregor5 | General Programming | 2 | 07-15-2007 01:35 PM |
| Printing Current StopLoss & Profit Targets | Jim-Boulder | Strategy Analyzer | 1 | 06-25-2007 11:16 AM |
| Profit Targets in Strategy Wizard | gregw | Strategy Development | 3 | 01-24-2007 09:30 AM |