PDA

View Full Version : Multi instrument


roonius
02-20-2009, 02:29 PM
Hello NT,

There is a simple strategy code. What it does it simply wants to fade the main instrument when instrument's in background added via Add() method, price moves specified amount of points-ticks within specified number of bars. And it is simple reversal - enters when conditions are met and reverses when conditions met for opposite direction.

Let's say I load a strategy on ES 03-09 chart and via Add i want to add 'MSFT'. As soon as MSFT price moves up 10 cents within last 2 bars, I want to short ES and hold it until MSFT price will do 10 cent downmovement, then reverse.

Also I want MSFT price check on bar close, and enter ES intrabar.


protected override void Initialize()
{
CalculateOnBarClose = false;
Add(bsym, bperiodtype, bvalue);
}

protected override void OnBarUpdate()
{
if (BarsInProgress == 1 && FirstTickOfBar)
{
if (High[1] >= MIN(Low, lookback)[2] + priceoffset && Close[1] >= Median[1])
{
DrawDot(CurrentBar.ToString()+"s", true, 0, Highs[0][0] + 2*TickSize, Color.Red);
if (entryOrder == null) entryOrder = EnterShort(0,tradingsize,"sell");
}
if (Low[1] <= MAX(High, lookback)[2] - priceoffset && Close[1] <= Median[1])
{
DrawDot(CurrentBar.ToString()+"b", true, 0, Lows[0][0] - 2*TickSize, Color.Green);
if (entryOrder == null) entryOrder = EnterLong(0,tradingsize,"buy");
}
}
}
protected override void OnOrderUpdate(IOrder order)
{
if (entryOrder != null && entryOrder.Token == order.Token)
{
Print(order.ToString());
if (order.OrderState == OrderState.Filled)
entryOrder = null;
}
}

The problem I am getting is that strategy does not process any orders "real time" and I am getting such a printout:

Order='NT-00270/Sim101' Name='sell' State=PendingSubmit Instrument='ES 03-09' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='ChrisFade' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='565260144e0a412394871ca578b301ed' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00270/Sim101' Name='sell' State=Accepted Instrument='ES 03-09' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='ChrisFade' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='565260144e0a412394871ca578b301ed' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00270/Sim101' Name='sell' State=Working Instrument='ES 03-09' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='ChrisFade' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='565260144e0a412394871ca578b301ed' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00270/Sim101' Name='sell' State=Filled Instrument='ES 03-09' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='ChrisFade' Type=Market Tif=Gtc Oco='' Filled=1 Fill price=768 Token='565260144e0a412394871ca578b301ed' Gtd='12/1/2099 12:00:00 AM'

Order='NT-00272/Sim101' Name='buy' State=PendingSubmit Instrument='ES 03-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='ChrisFade' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d41927a62477439b941db2ca375bd61a' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00272/Sim101' Name='buy' State=Accepted Instrument='ES 03-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='ChrisFade' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d41927a62477439b941db2ca375bd61a' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00272/Sim101' Name='buy' State=Working Instrument='ES 03-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='ChrisFade' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d41927a62477439b941db2ca375bd61a' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00272/Sim101' Name='buy' State=PendingCancel Instrument='ES 03-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='ChrisFade' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d41927a62477439b941db2ca375bd61a' Gtd='12/1/2099 12:00:00 AM'
Order='NT-00272/Sim101' Name='buy' State=Cancelled Instrument='ES 03-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='ChrisFade' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d41927a62477439b941db2ca375bd61a' Gtd='12/1/2099 12:00:00 AM'
What am I missing? Am I looking for my phone while I am talking on it?

As you can see from attached pictures, it receives a lot of buy and sell signals, but at some point just stops executing.

Usually tthat happens as soon as real time data start coming in, sometimes even before - still on historical data

Thank you much.

NinjaTrader_Ben
02-21-2009, 10:06 AM
Hello,

After looking at your code briefly, I do not see anything that stands out.

Try adding some Print()'s and print out key values to be sure they are what you think the should be.

Also, try commenting out some of your conditions to see if they are holding things up.

The above may give you clues as to what it going on. Sorry, I am not much more help here. You will need to debug it. This link may help:
http://www.ninjatrader-support2.com/vb/showthread.php?t=3418

roonius
02-21-2009, 01:38 PM
Ben,

The conditions are working fine.
My question was why orders are canceled?
It enters condition otherwise it would not paint the dots.

See my previous posts part with Green font.

thanks

NinjaTrader_Ben
02-21-2009, 07:38 PM
Hello,

OK, sorry about that. I think I understand now. All working orders need to be resubmitted each bar. They are automatically cancelled each bar if you do not. This link has more detail on this:
http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?Overview36

roonius
02-22-2009, 04:33 PM
Ben, I am placing market orders. They shoud be filled immediately.
Could you please please investigate this? What causes canceling of orders?
Is FirstTickOfBar working as expected when multiple symbols are loaded?

NinjaTrader_Ben
02-22-2009, 11:34 PM
Hello,

I am not sure what is causing this. I will have someone take a look at this Monday morning.

NinjaTrader_Bertrand
02-23-2009, 11:08 AM
Hi roonius, FirstTickOfBar should work for multiple symbols.

Did you try moving the FirstTickOfBar check out of the BarsInProgress one...


if (BarsInProgress == 1)
if (FirstTickOfBar)
{
do some trades
}

roonius
02-23-2009, 11:10 AM
Hi roonius, FirstTickOfBar should work for multiple symbols.

Did you try moving the FirstTickOfBar check out of the BarsInProgress one...


if (BarsInProgress == 1)
if (FirstTickOfBar)
{
do some trades
}


Bertrand,
Yes I have tried that and I get same results

NinjaTrader_Bertrand
02-23-2009, 01:02 PM
I'm out of ideas here roonius, sorry. But I can test this on my end if you like, please forward me the strategy zip to support at ninjatrader dot com Attn Bertrand - Thanks!

roonius
02-23-2009, 01:12 PM
I'm out of ideas here roonius, sorry. But I can test this on my end if you like, please forward me the strategy zip to support at ninjatrader dot com Attn Bertrand - Thanks!

Email sent
Thanks in advance