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-22-2010, 02:31 PM   #1
subrock
Junior Member
 
Join Date: Feb 2010
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default Seeking help with simple strategy

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
    }
subrock is offline  
Reply With Quote
Old 03-22-2010, 02:56 PM   #2
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

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
NinjaTrader_Tim is offline  
Reply With Quote
Old 03-22-2010, 03:11 PM   #3
subrock
Junior Member
 
Join Date: Feb 2010
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

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
subrock is offline  
Reply With Quote
Old 03-22-2010, 03:31 PM   #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

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.
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-22-2010, 03:59 PM   #5
subrock
Junior Member
 
Join Date: Feb 2010
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

thanks I will check this out.
subrock 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
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


All times are GMT -6. The time now is 02:44 AM.