NexusFi: Find Your Edge


Home Menu

 





MultiTimeFrame getting wierd backtest results


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one rymonroe with 3 posts (0 thanks)
    2. looks_two Quick Summary with 1 posts (0 thanks)
    3. looks_3 vvhg with 1 posts (0 thanks)
    4. looks_4 kconradbell with 1 posts (0 thanks)
    1. trending_up 1,524 views
    2. thumb_up 0 thanks given
    3. group 5 followers
    1. forum 5 posts
    2. attach_file 1 attachments




 
Search this Thread

MultiTimeFrame getting wierd backtest results

  #1 (permalink)
 
rymonroe's Avatar
 rymonroe 
Los Angeles, CA
 
Experience: Beginner
Platform: NT
Trading: ES, ZN
Posts: 15 since Nov 2012
Thanks Given: 5
Thanks Received: 4

I am creating a multi time-frame strategy with four time frames and two indicators
 
Code
                        Add(PeriodType.Minute,15);
			Add(PeriodType.Minute,30);
			Add(PeriodType.Minute,60);
			Add(PeriodType.Day, 1);
			Add(LongIndicator());
			Add(ShortIndicator);
In the onBarUpdate, I check for the primary bars (barsinprogress==0 return) and ignore it. When I backtest in 1 min ticks, I only get long trades. When I switch to 15 min, I get both. My questions is, are there 4 instances of each indicator running (5 if you count primary bars) when my strategy is active? I'm missing something but I just don't know what it is?

[NOTE]The Long and Short Indicators are not optimized in any way for multi-time frames. They were meant to be run in one time frame[/NOTE]

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Request for MACD with option to use different MAs for fa …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
67 thanks
Battlestations: Show us your trading desks!
48 thanks
NexusFi site changelog and issues/problem reporting
47 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
31 thanks

  #3 (permalink)
 
vvhg's Avatar
 vvhg 
Northern Germany
 
Experience: Intermediate
Platform: NT
Trading: FDAX, CL
Posts: 1,583 since Mar 2011
Thanks Given: 1,016
Thanks Received: 2,824



rymonroe View Post
I am creating a multi time-frame strategy with four time frames and two indicators
 
Code
                        Add(PeriodType.Minute,15);
			Add(PeriodType.Minute,30);
			Add(PeriodType.Minute,60);
			Add(PeriodType.Day, 1);
			Add(LongIndicator());
			Add(ShortIndicator);
In the onBarUpdate, I check for the primary bars (barsinprogress==0 return) and ignore it. When I backtest in 1 min ticks, I only get long trades. When I switch to 15 min, I get both. My questions is, are there 4 instances of each indicator running (5 if you count primary bars) when my strategy is active? I'm missing something but I just don't know what it is?

[NOTE]The Long and Short Indicators are not optimized in any way for multi-time frames. They were meant to be run in one time frame[/NOTE]

There will only be one instance, this method of adding indicators will just display them on the chart afaik.

vvhg

Hic Rhodos, hic salta.
Reply With Quote
  #4 (permalink)
 
rymonroe's Avatar
 rymonroe 
Los Angeles, CA
 
Experience: Beginner
Platform: NT
Trading: ES, ZN
Posts: 15 since Nov 2012
Thanks Given: 5
Thanks Received: 4


vvhg View Post
There will only be one instance, this method of adding indicators will just display them on the chart afaik.

vvhg

I don't think this is the case because when I call

 
Code
LongIndicator().BarsPeriod.Value
I get different results depending on what BarsInProgress is.

Started this thread Reply With Quote
  #5 (permalink)
 
rymonroe's Avatar
 rymonroe 
Los Angeles, CA
 
Experience: Beginner
Platform: NT
Trading: ES, ZN
Posts: 15 since Nov 2012
Thanks Given: 5
Thanks Received: 4

I have found and solved the problem. I was setting avariable in the Short indicator, as seen below...

 
Code
                        Add(PeriodType.Minute,15);
			Add(PeriodType.Minute,30);
			Add(PeriodType.Minute,60);
			Add(PeriodType.Day, 1);
			Add(LongIndicator());
			Add(ShortIndicator());

                        ShortIndicator().shortVal = true;

From what I gather by debugging it, there were 5 instances of LongIndicator and 5 instances of ShortIndicator running in my strategy at any given time. The code you see above is from the Initialize method method and it turns out that I was changing the value of shortVal in only the primary bars (which is what called the Initialize method) and not the 15/30/60/day bars. This was causing my unexpected results and once I changed the default value of shortVal to true, everything worked fine.

Started this thread Reply With Quote
  #6 (permalink)
kconradbell
Dallas Texas United States
 
Posts: 5 since Apr 2014
Thanks Given: 1
Thanks Received: 0

Clearly I'm screwing something up. The code below works partially. It appears to do everything except account for the EMA positions on the primary bars [0]. EMA 21 > EMA 34 for example.

It also freaks out and floods with placing and cancelling orders when I change the EnterLong or EnterShort to a limit order. The limit order is to be placed at the 13 MA, if that makes any difference.

/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(PeriodType.Tick, 2584);
Add(PeriodType.Second, 30);
Add(Swing(SwingStrength));

CalculateOnBarClose = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired || CurrentBars[2] <= BarsRequired)
return;
if(BarsInProgress !=0)
return;
if (EMA(BarsArray[1],8)[0] > EMA(BarsArray[1],13)[0] + 1 * TickSize && Stochastics(BarsArray[2],7, 23, 2).K[0] < 80)
{
if (EMA(21)[0] > EMA(34)[0]
&& ToTime(Time[0]) >= ToTime(7, 00, 0)
&& ToTime(Time[0]) < ToTime(15, 00, 0)
&& Close[0] > Swing(SwingStrength).SwingHigh[0] + 3 * TickSize)
EnterLong(OrderQty, "MA1");
DrawTriangleUp("My triangle up" + CurrentBar, false, 0, EMA(13)[0], Color.Green);
}

if(EMA(BarsArray[1],8)[0] < EMA(BarsArray[1],13)[0] + -1 * TickSize && Stochastics(BarsArray[2],7, 23, 2).K[0] > 20)
{
if (EMA(21)[0] < EMA(34)[0]
&& ToTime(Time[0]) >= ToTime(7, 00, 0)
&& ToTime(Time[0]) < ToTime(15, 00, 0)
&& Close[0] < Swing(SwingStrength).SwingLow[0] + -3 * TickSize);
EnterShort(OrderQty, "MA1");
DrawTriangleDown("My triangle down" + CurrentBar, false, 0, EMA(13)[0], Color.Crimson);
}

The flood of cancels also occurs when I attempt to add more exit and entry commands below the preceding script.

if (Position.MarketPosition == MarketPosition.Long
&& CrossBelow(Stochastics(BarsArray[2],7, 23, 2).K, 21, 1))
{
DrawTriangleUp("My triangle up" + CurrentBar, false, 0, Low[0] + -1 * TickSize, Color.Lime);
EnterLong(OrderQty, "O1");

Thank you in advance for any help.

Conrad
Skype: kconradbell

Attached Thumbnails
Click image for larger version

Name:	NinjaScriptCapture.PNG
Views:	125
Size:	38.9 KB
ID:	160818  
Reply With Quote





Last Updated on October 9, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts