PDA

View Full Version : multi time frame does not take a trade


ceesvh
09-13-2007, 02:47 AM
Hi

I am trading from a 5 min or 10 min barchart with CalculateOnBarClose=true.
In order to be able to play around with stops and profits during the trade I changed the same strategy to CalculateOnBarClose=false. This is working after some difficulties, but it is not possible to backtest this strategy.
So I was thinking of using 2 timeframes in the strategy – with CalculateOnBarClose=true. A 5 min and an 1 min timeframe. The entry signal is taken from the 5 min and the close/high/etc of the 1 min bars is used for playing with stops and profits.
According to the documentation orders can only be taken at the barclose of the primary timeframe, in Ninjascript the condition if(BarsInProgress==0). So the 1 min timeframe has to be the primary timeframe.

I developed a very small test script
It is a sma crossover with only an entry and some kind of trailing.
In the script I count the 1 min bars and at bar 5 the entry signal of the 5 min timeframe is checked.
In order to check the progress of the script the value of some variables is written to the output window.

- I have observed the following
- The strategy does not take any entry trade
- The exit is working but as no entry trade is taken there is no exit trade
- The boolean Long changes from false to true the next 1 min bar after it has become false, independently of the value of Barcount.

The last item I really do not understand as Long can only change to true when eg the condition if(Barcount==5) is met.

I really should appreciate if any one could could shed some light on this problem.
I have attached a part of a screenshot of the output window.
(The strategy is running on the Dax with european times)
The script follows below.

SCRIPT

Variables
double Max=0;
bool Long=false;
int Barcount=0;


if(BarsInProgress==0)
{
Barcount=Barcount+1;

if(Barcount==5
&& CrossAbove(Closes[1][0], SMA(BarsArray[1],5), 1)
&& Long==false)
{
EnterLong("Test");
Long=true;
}

//*******************Trailing
if(Long=true)
{
if(Close[0]>Max)
{
Max=Close[0];
}
if(Close[0]<=(Max-10*TickSize))
{
ExitLong("Test");
Long=false;
Max=0;
}
}
if(Barcount==5) // reset barcount to 0
Barcount=0;
Print(Time.ToString()+" "+ Close[0].ToString()+" "+Max.ToString()+" "+Barcount.ToString()+" "+Long.ToString());
}
if(BarsInProgress==1)
Print(Time.ToString()+" "+ Close[0].ToString()+" "+Max.ToString()+" "+Barcount.ToString()+" "+Long.ToString()+" "+"5min");

NinjaTrader_Josh
09-13-2007, 10:49 AM
Are you sure it is not entering trades? I copied your code and it is executing trades for me. The reason your bool value changes from independent of your Barcount value is because the condition to change doesn't require a Barcount check. You are only checking if your Close is less than equal to Max-10*TickSize.

ceesvh
09-13-2007, 01:03 PM
Josh,

I am sure that it does not take any trade. I am running it now on live data- ER2 december contract.
It does not take an entry trade.
The entry conditions are

if(Barcount==5
&& CrossAbove(Closes[1][0], SMA(BarsArray[1],5), 1)
&& Long==false)
{
EnterLong("Test");
Long=true;
}

When the boolean runs into false it turns into true the next 1 min bar.
It looks like that all the entry conditions do not work.
Below is a part of the output window. the boolean turns true at the second 1 min bar (european time)

13-9-2007 20:55:00 791,5 792,2 0 True
13-9-2007 20:55:00 791,5 792,2 0 True 5min
13-9-2007 20:56:00 791,2 0 1 False
13-9-2007 20:57:00 790,8 790,8 2 True
13-9-2007 20:58:00 791,1 791,1 3 True


I attach the script so that you are sure to have an exact copy of the strategy.

NinjaTrader_Josh
09-13-2007, 01:18 PM
Here is the problem:

In your trailing code you have
//*******************Trailing
if(Long=true)

It should be
if(Long==true)

ceesvh
09-14-2007, 05:58 AM
Josh

Thanks
How stupid of me.
It is working fine now.

ctrlbrk
11-15-2008, 11:54 AM
I have a similar issue. My multi-time frame strategy will only enter a trade on the bip0 and not on bip3 like I also want. If I comment out the entry on bip0, then it will enter on bip3 but it will never exit.

I simply want to enter/exit two instruments at same time.


Add(PeriodType.Minute, 2); // bip 1
Add("$USDJPY", PeriodType.Minute, 2); // bip2
Add("NQ 12-08", PeriodType.Minute, 2); // bip3

.
.
.

if (BarsInProgress == 0 && FirstTickOfBar)
{
if (Position.MarketPosition == MarketPosition.Flat)
{
EnterLong(DefaultQuantity, "long 1 es");
EnterLong(3, DefaultQuantity, "long 1 nq");
}
Above enters long1 es, does not enter long1 nq.

Now elsewhere, to exit:


if (BarsInProgress == 0)
{
ExitLong("Get out", "long 1 es");
ExitLong(3, "Get out", long 1 nq");
}

I believe I've shown relevant code. Again, it will enter bip0 (long 1 es) and exit bip0 (long 1 es) no problem. But, it will not enter/exit bip3 (long 1 nq) on the next line.

If I comment out the entry/exit bip0 line, it will neter long 1 nq (bip3) but it will never exit (forced exit, market close).

Thanks for help.

Mike

NinjaTrader_Ray
11-15-2008, 02:19 PM
Someone will follow up on this post on Monday.

ctrlbrk
11-15-2008, 02:35 PM
Someone will follow up on this post on Monday.

Thanks Ray, as always. When's the last time you took a vacation!? I hope after NT7 you can go off to some far away island and relax some :)

NinjaTrader_Josh
11-17-2008, 08:01 AM
ctrlbrk,

Have you increased your EntriesPerDirection setting? Or changed your EntryHandling setting?

ctrlbrk
11-17-2008, 05:47 PM
OK wow I need some sleep. Entries per direction was it... duh...