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!!!
Comment