I am now running version 7.0.1000.2
#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>
/// Reference sample demonstrating how to plot from within a strategy
/// </summary>
[Description("Reference sample demonstrating how to plot from within a strategy")]
public class ScaleInOrderLOOPwCANCELS : Strategy
{
#region Variables
private int Sma = 20;
private double LongLevel = .0010;
private double ShortLevel = -.0010;
private int ordercount = 5;
private int takeprofit = 100;
private int stoploss = 100;
#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;
// Create a multi-time frame strategy
// Add(PeriodType.Minute, 3);
/* Add our blank placeholder indicators. The parameter we pass in is used to distinguish the two
indicators from each other. */
// Add(StrategyPlot(0));
// Add(StrategyPlot(1));
Add(StrategyPlot(2));
Add(StrategyPlot(3));
Add(StrategyPlot(4));
int orderID = 1;
Add(SMA(Close, Sma));
Add(DistancefromSMA(Sma));
// Set the color for the indicator plots
// StrategyPlot(0).Plots[0].Pen.Color = Color.Blue;
// StrategyPlot(1).Plots[0].Pen.Color = Color.YellowGreen;
StrategyPlot(2).Plots[0].Pen.Color = Color.DarkGreen;
StrategyPlot(3).Plots[0].Pen.Color = Color.DarkRed;
StrategyPlot(4).Plots[0].Pen.Color = Color.DarkCyan;
// Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc.
// StrategyPlot(0).PanelUI = 1;
// StrategyPlot(1).PanelUI = 1;
StrategyPlot(2).PanelUI = 2;
StrategyPlot(3).PanelUI = 3;
StrategyPlot(4).PanelUI = 4;
// For more options please see the forum tip titled "Adding Indicators to Strategies"
// http://www.ninjatrader-support.com/v...ead.php?t=3228
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
/* Set the values of our indicators. One of them is set to the High of the primary bar series while the
other is set to the High of the secondary bar series. This effectively creates a multi-time frame plot. */
// StrategyPlot(0).Value.Set(High[0]);
// StrategyPlot(1).Value.Set(Highs[1][0]);
double profitloss = Position.GetProfitLoss(Close[0], PerformanceUnit.Currency);
double realized = Performance.AllTrades.TradesPerformance.Currency.C umProfit;
int position = Position.Quantity / 1000;
StrategyPlot(2).Value.Set(profitloss);
StrategyPlot(3).Value.Set(realized);
StrategyPlot(4).Value.Set(position);
double distance = Close[0] - SMA(Close, Sma)[0];
double scale = 10*TickSize;
int orderID = 1;
if (Close[0] > SMA(Close, Sma)[0])
// (CrossAbove(Close, SMA(Close, Sma), 5))
// &&
// Open[3] > Close[3] && Open [2] > Close[2]
// && Open[1] > Close[1] && Open[0] > Close[0])
{
distance = Close[0] - SMA(Close, Sma)[0];
scale = 10*TickSize;
orderID = 1;
IOrder myorder = null;
while(scale <= distance)
{
EnterLongLimit(1000,SMA(Close, Sma)[0] + distance, "OrderID " + orderID.ToString());
distance = distance - scale;
orderID++;
}
SetProfitTarget(CalculationMode.Ticks, 80);
SetStopLoss(CalculationMode.Price, SMA(Close, Sma)[0] - 40*TickSize);
}
// if (Close[0] < SMA(Close, Sma)[0] && Position.MarketPosition == MarketPosition.Long)
// {
// ExitLong();
// }
//Start of Short Algorithm
if (Close[0] < SMA(Close, Sma)[0])
// (CrossAbove(Close, SMA(Close, Sma), 5))
// &&
// Open[3] > Close[3] && Open [2] > Close[2]
// && Open[1] > Close[1] && Open[0] > Close[0])
{
distance = SMA(Close, Sma)[0] - Close[0];
scale = 10*TickSize;
orderID = 100;
while(scale <= distance)
{
EnterShortLimit(1000,SMA(Close, Sma)[0] - distance, "OrderID " + orderID.ToString());
distance = distance - scale;
orderID++;
}
SetProfitTarget(CalculationMode.Ticks, 80);
SetStopLoss(CalculationMode.Price, SMA(Close, Sma)[0] + 40*TickSize);
}
// if (Close[0] > SMA(Close, Sma)[0] && Position.MarketPosition == MarketPosition.Short)
// {
// ExitShort();
// }
//
// orderID = 1;
// while(orderID <= 100)
// {
// SetProfitTarget("OrderID" + orderID, CalculationMode.Ticks, 10);
// orderID++;
// }
// if (SMA(Close, Sma)[0] < Close[0] && Open[0] < Close[0] && Position.MarketPosition == MarketPosition.Long && Position.Quantity >= 5000)
// {
// orderID = 1;
// scale = 10*TickSize;
// distance = Close[0] - SMA(Close, Sma)[0];
// while(scale <= distance)
// {
// ExitLongLimit(0, true, 1000,SMA(Close, Sma)[0] + distance + 10*TickSize, "ScaleOut", "OrderID" + orderID.ToString());
// ExitLongLimit(SMA(Close, Sma)[0] + distance + 10*TickSize, "OrderID" + orderID.ToString());
// orderID++;
// }
// }
}
#region Properties
#endregion
}
}
Comment