I am attempting my first Ninja Script , with very no programming background .
Objective is to create a simple script that will flatten and close pending orders once unrealized PL target is reached .
The position( with Stop and target bracket) is opened by a custom NT dll API .
Example : If unrealized PL is >= 100 flatten the position . Assuming only one instrument will be open at a time.
I used the NT wizard to create a script , refer the screenshots:

Then I manually edited the script.
Based on the research on this forum. ExitShort () was replaced with
NinjaTrader.Gui.SuperDom.SuperDom.FlattenEverythin g() ;
I keep NT Super DOM running because above command has that word in it .
Custom API does not need DOM to be running , though order and bracket created by API are displayed on NT dom.
Complete script 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>
/// Flatten Script L tgt
/// </summary>
[Description("Flatten Script L tgt")]
public class zLtargetexit : Strategy
{
#region Variables
// Wizard generated variables
private double ltargetUip = 100; // Default setting for LtargetUip
// 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()
{
// Condition set 1
if (Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) >= LtargetUip)
{
NinjaTrader.Gui.SuperDom.SuperDom.FlattenEverythin g() ;
}
}
#region Properties
[Description("Tgt L user define input")]
[GridCategory("Parameters")]
public double LtargetUip
{
get { return ltargetUip; }
set { ltargetUip = Math.Max(1, value); }
}
#endregion
}
}
Not surprisingly the script is not working

please help !
Thanks in advance .


Comment