Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
This submits an order when Setup is CurrentBar, and stays active until I cancel it. How do I set a cancel order to a pending order?
I want to cancel this Limit order if the price touches SetupStop before SetupEntry.
Keep in mind, my SetupStop is the value of High[1] when it is CurrentBar, in other words it will change after each new bar.
How do I cancel the "pending order" when the price is trading at or above SetupStop? (The price that was High[1] when Setup was true)?
Can you help answer these questions from other members on NexusFi?
Thanks for the reply. Tried the code. Didn't work. Getting errors on intellisense. All my code was under OnBarUpdate() method, I have no variables, or anything else, if that makes a difference.
strategy not enabling. Error in log: Error on calling 'onbarupadate' object reference not set to an instance of an object
problem was in the initial code
it was executing on historical data
now it runs
#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>
/// TwoTargetBull
/// </summary>
[Description("TwoTargetBull")]
public class TwoTargetBull : Strategy
{
#region Variables
private IOrder myEntryOrder=null;
public bool myNotExecuted;
#endregion
protected override void Initialize()
{
CalculateOnBarClose = true;
myEntryOrder = null;
myNotExecuted = true;
}
// this method is called everytime there is an execution
protected override void OnExecution(IExecution execution)
{
// order can not be cancelled any more, we are in the trade....
if (myEntryOrder != null && myEntryOrder == execution.Order)
myNotExecuted=false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(Historical)
return;
double SetupStop = Low[1];
double SetupEntry = Close[1];
double T1 = SetupEntry + (5 * TickSize);
double T2 = SetupEntry + (8 * TickSize);
bool OrderInvalidated = false;
if (Close[0] < Close[1] && Low[1] == Low[2] && myNotExecuted == false)
{
myEntryOrder = EnterLongStopLimit(0, true, 2, SetupEntry, SetupEntry, "T1");
SetStopLoss("T1", CalculationMode.Price, SetupStop, false);
SetProfitTarget("T1", CalculationMode.Price, T1);
// SetProfitTarget2("T2", CalculationMode.Price, T2);
myNotExecuted = true;
}
/// write your code that will trigger the cancel of the order
// whatever condition goes next :
if (1 == 2)
{
OrderInvalidated = true;
}
// if OrderInvaldiate true and order not yet executed, cancel it
if (OrderInvalidated && myNotExecuted)
{
AtmStrategyCancelEntryOrder("T1");
myNotExecuted = false;
myEntryOrder = null;
}
}
#region Properties
#endregion
}
}
you might be interested to study a live strategy i wrote on :
I have been trading for some time the Alpha Trading Method (and been posting trades to both the thread ATM Trading Method Vendor Free ( and my personal trading journal (.
Credit for the initial posting of the ATM method goes to JDNeeman and …
problem was in the initial code
it was executing on historical data
now it runs
#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>
/// TwoTargetBull
/// </summary>
[Description("TwoTargetBull")]
public class TwoTargetBull : Strategy
{
#region Variables
private IOrder myEntryOrder=null;
public bool myNotExecuted;
#endregion
protected override void Initialize()
{
CalculateOnBarClose = true;
myEntryOrder = null;
myNotExecuted = true;
}
// this method is called everytime there is an execution
protected override void OnExecution(IExecution execution)
{
// order can not be cancelled any more, we are in the trade....
if (myEntryOrder != null && myEntryOrder == execution.Order)
myNotExecuted=false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(Historical)
return;
double SetupStop = Low[1];
double SetupEntry = Close[1];
double T1 = SetupEntry + (5 * TickSize);
double T2 = SetupEntry + (8 * TickSize);
bool OrderInvalidated = false;
if (Close[0] < Close[1] && Low[1] == Low[2] && myNotExecuted == false)
{
myEntryOrder = EnterLongStopLimit(0, true, 2, SetupEntry, SetupEntry, "T1");
SetStopLoss("T1", CalculationMode.Price, SetupStop, false);
SetProfitTarget("T1", CalculationMode.Price, T1);
// SetProfitTarget2("T2", CalculationMode.Price, T2);
myNotExecuted = true;
}
/// write your code that will trigger the cancel of the order
// whatever condition goes next :
if (1 == 2)
{
OrderInvalidated = true;
}
// if OrderInvaldiate true and order not yet executed, cancel it
if (OrderInvalidated && myNotExecuted)
{
AtmStrategyCancelEntryOrder("T1");
myNotExecuted = false;
myEntryOrder = null;
}
}
#region Properties
#endregion
}
}
you might be interested to study a live strategy i wrote on :
I have been trading for some time the Alpha Trading Method (and been posting trades to both the thread ATM Trading Method Vendor Free ( and my personal trading journal (.
Credit for the initial posting of the ATM method goes to JDNeeman and …
Thank you. I fixed that error// but ill test this new code.