PDA

View Full Version : How to write a time period in wizard?


Jenny
06-13-2007, 10:53 AM
http://www.ninjatrader-support.com/vb/images/icons/icon1.gif
I have problem to write a time period in wizard. For example, I would like to enter long position between 17:00 to 21:00. But it would enter long position in any time.

// Condition set 1
if (ToTime(Time[Buy]) > ToTime(17, 0, 0)
&& ToTime(Time[Buy]) < ToTime(21, 0, 0)
&& ToDay(Time[0]) > ToDay(2007, 6, 13))
{
EnterLong(DefaultQuantity, "");
}

Would you please tell me what I should do?
Thanks
http://www.ninjatrader-support.com/vb/images/statusicon/user_online.gif http://www.ninjatrader-support.com/vb/images/buttons/report.gif (http://www.ninjatrader-support.com/vb/report.php?p=11299) http://www.ninjatrader-support.com/vb/images/misc/progress.gif

NinjaTrader_Ray
06-13-2007, 11:17 AM
Instead of Time[Buy] try Time[0].

Jenny
06-13-2007, 01:33 PM
I had tried to change the Time[0], but the same result, it enter long anytime. Is the time series including the date? If how add this restriction?
Thanks

NinjaTrader_Ray
06-13-2007, 02:19 PM
Hi Jenny,

Please see the attached strategy. This strategy will only enter a long position on the first bar after 10 AM and between 12:00 PM. I just verified that this works as expected.

You can save this in the following folder and open it and compile.

Jenny
06-13-2007, 02:40 PM
Whick folder I should save to? It is a .php file, can I compile using NinjaTrader? It look much different from Ninjarscript.
Thanks

NinjaTrader_Ray
06-13-2007, 02:43 PM
My Documents\NinjaTrader 6\bin\Custom\Strategy

Jenny
06-13-2007, 03:53 PM
I can't compile it, it is .php file, not the same as .cs file.
thanks

NinjaTrader_Ray
06-13-2007, 04:20 PM
If you click on the file, you should be able to save as a .cs file.

Jenny
06-14-2007, 12:45 PM
In the wizard, is "Enter optional stop loss and...." the same as function as "Enter Long/short position by a stop limid order"?
How can I set up 2 trailling stop triggered by 2 kind of profit (like in SuperDOM)?

Thanks

NinjaTrader_Ray
06-14-2007, 01:35 PM
No this is not the same.

Enter() methods submit orders to enter a position. Exit() method submit orders to exit a position.

The optional Stop Loss/Profit Target orders are used to submit orders on the opening of a position. They are just a different form of Exit() methods since they submit orders immediately instead of on the close of a bar.

Creating a multi-stop trail stop needs to be done programmatically instead of through the wizard. However, you can use a SetTrailStop() which trails immediately.

Jenny
06-14-2007, 01:57 PM
Could you please write the code for "multi-stop trail stop " for us? So that we can copy and paste after we finish program using wizard?

I really appreciate that.
Jenny

NinjaTrader_Ray
06-14-2007, 02:05 PM
Hi Jenny,

Thats a good idea and I will put that on our list of actions. Unfortunately I can not provide this sample any time soon as we are restricted right now on resource bandwidth. Thanks for understanding.

Jenny
06-14-2007, 02:20 PM
I would like to try by myself if you are too busy. But I couldn't find any information about the function SetTrailStop() from here http://www.ninjatrader-support.com/HelpGuide/helpguide.html?ManagingOrders

Can you tell me where I can find it?

Thanks

NinjaTrader_Ray
06-14-2007, 02:33 PM
No problem.

http://www.ninjatrader-support.com/HelpGuideV6/SetTrailStop.html

Jenny
06-14-2007, 03:04 PM
I just try a code after your link, thanks.
I couldn't compile this one, can you tell me why,
#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")]
[Gui.Design.DisplayName("SeptStop2")]
public class SeptStop2 : 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()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Sets a trail stop of 12 ticks
SetTrailStop(CalculationMode.Ticks, 12);
if (Position.MarketPosition != MarketPosition.Flat)
&& if (Position.GetProfitLoss(Close[0], PerformanceUnit.Points) )>= 4;
{
int stopLoss = 2;
Print("Setting stop to "+stopLoss+" in "+instrumentName+" at "+Time[0]);
SetTrailStop(OrderName, CalculationMode.Ticks, stopLoss, false);
}
#region Properties
[Description("")]
[Category("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
#endregion
}
}

NinjaTrader_Ray
06-14-2007, 04:19 PM
There are several coding errors I see at first glance. You will always see error messages at the bottom of the NinjaScript Editor that you can double click on that will take you to the location of the error. Sometimes these error message are cryptic....I do understand this.

Its good to see you are making a good effort to learn this stuff. I would take a look on the internet for some begginer C# tutorials or even a book. Some of the errors you made are programming syntax errors. Unfortunately we can not provide this level of support. I can provide a correction on part of your code below.

if (Position.MarketPosition != MarketPosition.Flat && Position.GetProfitLoss(Close[0], PerformanceUnit.Points) >= 4)
{
// Do something here
}

Jenny
06-15-2007, 08:14 PM
Dear Ray,
I couldn't make this work, Only the Trigger1 works, the Trigger never has any action, could you please have a look,

// Condition set 3 B1

if (((Position.GetProfitLoss(Close[0], PerformanceUnit.Points)) >= Triger1)
&&((Position.GetProfitLoss(Close[0], PerformanceUnit.Points)) < Triger2))

{

Print(("Stop is ").ToString());
SetTrailStop("",CalculationMode.Ticks, B1, false);
}
// Condition set 4 B2

Print(("STOP IS" ).ToString());

if ((Position.GetProfitLoss(Close[0], PerformanceUnit.Points)) > Triger2)
{

Print(("Stop is " ).ToString());

SetTrailStop("",CalculationMode.Ticks, B2, false);

}

NinjaTrader_Ray
06-16-2007, 08:27 AM
Hi Jenny,

Welcome to the wonderful world of debugging. I would add Print() statements tracing out information at each level. Then from this information you can get an idea what is wrong with your logic.

Jenny
06-17-2007, 07:51 PM
Hi,Ray,

I did add this statment, but nothing has been printed out,

Print(Position.GetProfitLoss(Close[0], PerformanceUnit.Points).ToString())

I don't know why, can you tell?

Thanks

NinjaTrader_Ray
06-18-2007, 07:04 AM
If nothing is printed out then likely this code is not called. Syntax looks fine.