![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Junior Member
Join Date: Mar 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
|
Hi, i would like to sell 2 contract once the last price is 10 ticks above the low of the previous bar , take profit at 9 tiicks and stop loss at 10 ticks, would this be the correct code for it:
#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> /// Enter the description of your strategy here ///</summary> [Description("Enter the description of your strategy here")] publicclass Yoram1 : 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() { SetProfitTarget("", CalculationMode.Ticks, 9); SetStopLoss("", CalculationMode.Ticks, 10, false); CalculateOnBarClose = true; } ///<summary> /// Called on each bar update event (incoming tick) ///</summary> protectedoverridevoid OnBarUpdate() { // Condition set 1 if (GetCurrentBid() + -10 * TickSize == Low[1]) { EnterShort(2, ""); } } #region Properties [Description("")] [Category("Parameters")] publicint MyInput0 { get { return myInput0; } set { myInput0 = Math.Max(1, value); } } #endregion } } |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
At a quick glance that should work. If you don't care about the "bid" price and want to just use the last closing price you can use Close[0] with CalculateOnBarClose set to false.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Mar 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
|
Ok, thanks for the answer, however i did not fnd where i can tell the analyzer to backtest my strategy using 1 day bar timeframe.
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
You can choose that when you are loading the strategy. In the dialog window that pops up for you to choose which strategy to backtest on there is a section near the top that allows you to choose timeframe. You can choose Daily from there.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Feb 2008
Posts: 28
Thanks: 0
Thanked 0 times in 0 posts
|
I have a set of rules for two strategies. I wonder if I can do it in the condition builder. I managed to do some part but not all. Is here someone who can help me how to do them in the condition builder?
Here are the rules: Strategy1: Should be run on a 5min chart. The first 5 min candle of the day will provide a range. If the current price ONE HOUR LATER is grater than the first candle's high, then enter a long position. If the current price is lower than the first candle's low then enter a short position. Close any position 30 minutes before the market closes. Example: first candle of the day on 5min chart: High:60 Low:55 One hour later (lets say that the market opens at 8.00AM that would mean 9.00AM just to clear it) the price is at 61,23. That is grater then the high so it should enter a long position. If the price is at 54,80 then it would enter a short position. If the price is in between the high and low, there is no trade that day! The market closes at 4.30 PM. So the strategy should close any position at 4PM! Only one trade per day.Strategy2: I am looking for a bar that is: Its high is LOWER than the high of the previous bar. Its low is HIGHER than the previous bar's low.Lets name this bar X. So, bar "X"'s high-low should be the smallest amount. For example the high is 50;the low is 45.That would mean 5 for bar "X". I do this calculation for the past three bars. That would made the "X" bar the smallest among these for bars including the "X" bar. Now, when the current price is above the high of the "X" bar than enter long. If the current price is lower than the low of the "X" bar it should enter short. Closing price should be the low of the current bar and it should move up as the price does. High for short and it should move down with the price. Can someone help me to generate these two strategies? |
|
|
|
|
|
#6 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
If someone does not provide some help you can always -
- Check with a NinjaScript Consultant - Attend our upcoming training class for strategy wizard development - http://www.ninjatrader.com/webnew/ev...evelopment.htm
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Simple MACD signal crossover question | altrader | Strategy Development | 17 | 05-24-2011 07:10 AM |
| simple charting question | z32000 | Charting | 3 | 11-30-2007 01:07 AM |
| simple charting question | z32000 | Charting | 1 | 11-22-2007 01:44 PM |
| A simple question from a new NT programmer | elemento-portador | Indicator Development | 1 | 11-05-2007 08:00 AM |
| A simple question about performance. | MGDavid | Miscellaneous Support | 2 | 06-21-2007 08:47 AM |