PDA

View Full Version : I can't introduce a stoploss order, help!


julen
09-10-2008, 10:54 AM
First of all sorry about my english if i introduce some mistakes,
I have just begun with the Ninja few days ago and I'm trying to program an estrategy I think so easy.
I want to open a long/short position if Max/Min of a determinate Bar is crossed (Bar that ends at 16:00), first of all I can't introduce the long and short position in the same estrategy.
But I managed to create an estrategy that open the long position if 16barMax is crossed , and now I want to exit the long position if price turns 4% from my entry price, How can I do it?

Here I let you the probisional Code, which errors you find 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.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
///<summary>
/// Estrategia del libro Guia del Trader de Petitjean
///</summary>
[Description("Estrategia del libro Guia del Trader de Petitjean")]
publicclass RRHlong : Strategy
{
#region Variables
// Wizard generated variables
privatedouble stop = 4.000; // Default setting for Stop
// 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()
{
SetStopLoss("enterlong", CalculationMode.Percent, Stop, false);
CalculateOnBarClose = true;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Condition set 1
if (ToTime(Time[0]) == ToTime(16, 0, 0))
{
Variable0 = High[0] + 1 * TickSize;
}
// Condition set 2
if (Variable0 != 0)
{
EnterLongStop(DefaultQuantity, Variable0, "enterlong");
}
}
#region Properties
[Description("")]
[Category("Parameters")]
publicdouble Stop
{
get { return stop; }
set { stop = Math.Max(10.00, value); }
}
#endregion
}
}
#region Wizard settings, neither change nor remove

Help please!!!

NinjaTrader_Josh
09-10-2008, 11:20 AM
Hi julen,

One of our NinjaScript trainees will respond to you later in the day. Thank you for your patience.

NinjaTrader_Ben
09-10-2008, 03:22 PM
Hello,

Sorry for the delay.

You will want to use something like this:

SetStopLoss("enterlong", CalculationMode.Percent, Stop, false);

And make sure the stop value is 0.04, not 4. 4 means 400%.

This will help:

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

julen
09-10-2008, 04:33 PM
Thanks a lot, my really problem was the 0,04; I thought that 4 means 4% not 400%!