NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 03-30-2008, 08:09 AM   #1
yoramva
Junior Member
 
Join Date: Mar 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default Simple Strategy question

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
}
}
yoramva is offline  
Reply With Quote
Old 03-30-2008, 01:20 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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.
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-01-2008, 12:51 AM   #3
yoramva
Junior Member
 
Join Date: Mar 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default Determine the timrframe for bars to be used in strategy

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.
yoramva is offline  
Reply With Quote
Old 04-01-2008, 02:35 AM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

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.
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-03-2008, 06:28 AM   #5
Fecdzo
Junior Member
 
Join Date: Feb 2008
Posts: 28
Thanks: 0
Thanked 0 times in 0 posts
Default

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?
Fecdzo is offline  
Reply With Quote
Old 04-03-2008, 07:25 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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
NinjaTrader_Ray is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 11:37 PM.