protected override void OnBarUpdate()
{
if (Historical)return;
if (CurrentBar < 1)return;
#region Seek Type
if (Trend().TrendSlopeLong > 0 && Trend().TrendSlopeShort > .0025 && SeekType != true)
{
SeekType = true;
Print("Seek = Long, " + Trend().TrendSlopeShort);
}
else SeekType = null;
if (Trend().TrendSlopeLong < 0 && Trend().TrendSlopeShort < -.0025 && SeekType != false)
{
SeekType = false;
Print("Seek = Short, " + Trend().TrendSlopeShort);
}
if (SeekType == null)Print("Trend weak, " + Trend().TrendSlopeShort);
#endregion
#region Entry Triggers
Lower = Fibs().CurrentChannelLower;
Upper = Fibs().CurrentChannelUpper;
Status = MACDBBLines(period,Fast,Slow,Smooth,numStdDev).Status;
if (Status == true)Print("Status = Long");
if (Status == false)Print("Status = Short");
if (Upper - Lower > ((Hide + .5) * TickSize))
{
if (MACDBBLines(period,Fast,Slow,Smooth,numStdDev).Status == null)
{
if (Clear != true)Print("Clear = true");
Clear = true;
}
if (Status == true && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == true && Clear == true)
{
StopLong = Lower - (Hide * TickSize);
EntryPriceLong = Lower + (2 * TickSize);
SetProfitTarget("LongBank",CalculationMode.Price,EntryPriceLong + (Bank * TickSize));
SetStopLoss(CalculationMode.Price,StopLong);
LongRunner = EnterLongLimit(0,true,1,EntryPriceLong,"LongRunner");
LongBank = EnterLongLimit(0,true,2,EntryPriceLong,"LongBank");
OrderPending = true;
Clear = false;
}
if (Status == false && Position.MarketPosition == MarketPosition.Flat && OrderPending == null && SeekType == false && Clear == true)
{
StopShort = Upper + (Hide * TickSize);
EntryPriceShort = Upper - (2 * TickSize);
SetProfitTarget("ShortBank",CalculationMode.Price,EntryPriceShort - (Bank * TickSize));
SetStopLoss(CalculationMode.Price,StopShort);
ShortRunner = EnterShortLimit(0,true,1,EntryPriceShort,"ShortRunner");
ShortBank = EnterShortLimit(0,true,2,EntryPriceShort,"ShortBank");
OrderPending = false;
Clear = false;
}
}
#endregion
#region Order Maintenance
if ((Position.MarketPosition == MarketPosition.Flat && OrderPending == true && Input[0] > EntryPriceLong + (Chase * TickSize)))
{
[COLOR=red]Print("Cancel, No retrace");[/COLOR]
[COLOR=red]CancelOrder(LongRunner);[/COLOR]
[COLOR=red]CancelOrder(LongBank);[/COLOR]
[COLOR=red]OrderPending = null;[/COLOR]
[COLOR=red]}[/COLOR]
[COLOR=red]if ((Position.MarketPosition == MarketPosition.Flat && OrderPending == false && Input[0] < EntryPriceShort - (Chase * TickSize)))[/COLOR]
[COLOR=red]{[/COLOR]
[COLOR=red]Print("Cancel, No retrace");[/COLOR]
[COLOR=red]CancelOrder(ShortRunner);[/COLOR]
[COLOR=red]CancelOrder(ShortBank);[/COLOR]
[COLOR=red]OrderPending = null;[/COLOR]
[COLOR=red]}[/COLOR]
if(Position.MarketPosition == MarketPosition.Long && StopLong < Lower - (Hide * TickSize))
{
StopLong = Lower - (Hide * TickSize);
SetStopLoss(CalculationMode.Price,StopLong);
}
if(Position.MarketPosition == MarketPosition.Short && StopShort > Upper + (Hide * TickSize))
{
StopShort = Upper + (Hide * TickSize);
SetStopLoss(CalculationMode.Price,StopShort);
}
#endregion
}
protected override void OnOrderUpdate(IOrder order)
{
if (LongBank != null && LongBank.Token == order.Token)
{
if (LongBank.OrderState == OrderState.Filled)
{
OrderPending = null;
}
}
if (ShortBank != null && ShortBank.Token == order.Token)
{
if (ShortBank.OrderState == OrderState.Filled)
{
OrderPending = null;
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
This strat does great until cancel and then goes idle.
Collapse
X
-
This strat does great until cancel and then goes idle.
This is the code, the part in red cancels the orders, but then script stops.
Code:Tags: None
-
Hmmm... The first time it cancelled an order it quit printing to output, since I restarted the strategy it has not occured again...
I guess I will standby until I have more evidence, thx.
Yes I am using trace, last activity was a print() that immediately precedes the cancel.
Aha!, I have a reference error in log!
Must be a "FirstTick" issue, I think if(FirstTickOfBar)return; should do it.Last edited by Sleeping Troll; 05-03-2010, 02:14 PM.
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
63 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
35 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
54 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
61 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
48 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment