![]() |
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: Feb 2010
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
I am new to this and tried to create a strategy to backtest the following-
1. buy 500 shares if the price reaches 3% above the open 2. sell 500 shares if the price increases to 3% above the purchase price(or 6% above the open) 3. sell 500 shares if the price drops back down to the opening price just a simple breakout strategy I would like to play around with, when I try to backtest I get no results ![]() here is what I have, any help would be greatly appreciated. Code:
#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.Gui.Chart;
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")]
public class Test : Strategy
{
#region Variables
// Wizard generated variables
private int 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>
protected override void Initialize()
{
SetStopLoss("", CalculationMode.Percent, -0.03, false);
SetProfitTarget("", CalculationMode.Percent, 0.03);
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if ((GetCurrentBid()) * (1 + 0.03) > Open[1])
{
EnterLongStop(500, 0, "");
}
}
#region Properties
[Description("")]
[Category("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion
}
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
|
Hi subrock,
Thank you for your note. In the SetStopLoss() there is no need to put a negative value, you can just use 0.03 More info at - http://www.ninjatrader-support.com/H...ml?SetStopLoss With that change, you will also need a exemption for avoid the error discussed at the following link. http://www.ninjatrader-support2.com/...ead.php?t=3170
Tim
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Feb 2010
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
Removing the negative value wouldnt make the stoploss the same amount as the profittarget?
I wasnt receiving errors prior to the change suggested but I did following the link and modified this portion: protected override void OnBarUpdate() { // Condition set 1 if ((GetCurrentBid()) * (1 + 0.03) > Open[Math.Min(CurrentBar, 1)]) { EnterLongStop(500, 0, ""); } } I still cant seem to get any results good or bad when i try to backtest. Thanks for your time |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
No, when you use SetStopLoss() it is already negative and will always be applied in the correct direction depending on the entry order. All you need to do is say I want 3% as my stop loss and it will handle the rest.
If you aren't getting any trades then I suggest you debug your if-statement. Use Print() and print out the individual components and evaluate it by hand to see if it should ever be true.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Feb 2010
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
thanks I will check this out.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Auto Trendline n Horizontal Support and Resistences.Seeking Help from Programmers | vrathee | NinjaScript File Sharing Discussion | 7 | 01-19-2011 08:30 AM |
| Seeking beta testers | Modern Indicators | NinjaScript File Sharing Discussion | 1 | 01-04-2010 09:28 PM |
| Seeking coding assistance / collaboration | JackWittaker | Indicator Development | 0 | 09-18-2009 09:53 AM |
| Seeking Programmer for Hire for complex project | ctrlbrk | General Programming | 9 | 05-09-2009 11:43 AM |
| Simple question about a simple strategy. | shakira | Strategy Development | 1 | 02-14-2009 10:56 AM |