Troubleshooting multi time frame strategy - futures io
futures io



Troubleshooting multi time frame strategy


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Troubleshooting multi time frame strategy

(login for full post details)
  #1 (permalink)
 jperales 
Durham, NC
 
Experience: Intermediate
Platform: NinjaTrader
Trading: YM
 
Posts: 2 since Jul 2012
Thanks: 6 given, 0 received

Hi,

I'm new to Big Mike's Forum and was hoping to find help with a multi time frame strategy I am trying to create. When I back test my strategy no trades are taken. The code compiles without a problem and the strategy is run, it's just that no trades are taken. The previous version of this strategy did not have multi time frame bars and the code ran as expected. This is my first attempt at creating a multi time frame strategy so I suspect that perhaps my mistake might be in referencing the secondary bar series, but I'm not certain of this. Since my code has no compilation errors and it does seem to run I have no idea how to troubleshoot this problem.

Please help.

Joe

The strategy runs on 3 min bars and assigns the highest high and lowest low, between the times 9:30 and 9:36 to the variables "ORhigh" and "ORlow" respectively.

The strategy then looks to make only 1 entry per day in a secondary bar series (currently 1 min bars) after 9:36. The entry is either long if price goes n ticks over the variable ORhigh or short if price goes n ticks below the variable ORlow. n ticks are user defined variables named "Buyticks" and "Sellticks" for long and short respectively. The number of contracts/shares in the trade are determined by the User Defined Variable "Shares".

The position is exited after so many bars, on the primary bar series, have passed. The number of bars is determined by the User Defined Variable "Exitbars".

The stop for the long is triggered if price drops n ticks below the variable ORlow and the stop for the short is triggered if price goes n ticks above the variable ORhigh. The number of ticks representing n are determined by the User Defined Variables "stopticks4long" and "stopticks4short".

Below is the code I have so far:

public class ORangeBreakout1 : Strategy
{
#region Variables
// Wizard generated variables
private int buyticks = 2; // Default setting for Buyticks
private int sellticks = 2; // Default setting for Sellticks
private int stopticks4long = 2; // Default setting for Stopticks4long
private int stopticks4short = 2; // Default setting for Stopticks4short
private int exitbars = 1; // Default setting for Exitbars
private int shares = 100; // Default setting for Shares
// User defined variables (add any user defined variables below)
#endregion

// variable to keep count of how many trades are taken per day
int count = 1;
double ORhigh;
double ORlow;
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
// Adding a minute Bars object to strategy
Add(PeriodType.Minute, 1);
CalculateOnBarClose = false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Checks to ensure all Bars objects contain enough bars before beginning
if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
return;

// Conditon 1 finds opening range high and low, in the primary bar series, and resets variable count to 0
if (BarsInProgress == 0) // Checks if OnBarUpdate() is called from an update on the primary Bars
{

if (ToTime(Time[0]) == 93600)
{ count = 0;
ORhigh = MAX(High,2)[0];
ORlow = MIN(Low,2)[0];
}
}

// Condition 2 enters trades, after 9:36, in the secondary bar series when price breaks opening range of day. Allows only 1 trade per day

// Checks if OnBarUpdate() is called from an update on the secondary Bars
if (BarsInProgress == 1)
{
// Restrict trading to after 9:36:00 AM and only allows 1 trade per day
if (ToTime(Time[0]) >= 93600 && count == 0)
{
if (High[0] >= ORhigh + Buyticks * TickSize)
{
count = count + 1;
EnterLong(Shares, "BLong");
}
else
{
if (Low[0] <= ORlow - Sellticks * TickSize)
{
count = count + 1;
EnterShort(Shares, "SShort");
}
}
}
}

// After entry in the secondary bar series switch back to the primary bar series

if (BarsInProgress ==0)
{
if (CurrentBars[0] <= BarsRequired)
return;

// Condition 3 stoploss for long position
SetStopLoss("BLong", CalculationMode.Price, ORlow - stopticks4long * TickSize, false);

// Condition 4 stoploss for short postion
SetStopLoss("SShort", CalculationMode.Price, ORhigh + stopticks4short * TickSize, false);

// Condition 5 exit from long position
if (BarsSinceEntry() == Exitbars - 1)
ExitLong("BLongExit", "BLong");
// Condition 6 exit from short position

if (BarsSinceEntry() == Exitbars - 1)
ExitShort("SShortExit", "SShort");
}

}

#region Properties
[Description("# Ticks over OR high for entry buy stop")]
[GridCategory("Parameters")]
public int Buyticks
{
get { return buyticks; }
set { buyticks = Math.Max(1, value); }
}

[Description("# Ticks below OR low for entry sell stop")]
[GridCategory("Parameters")]
public int Sellticks
{
get { return sellticks; }
set { sellticks = Math.Max(1, value); }
}

[Description("#Ticks below OR low for stop on long pos")]
[GridCategory("Parameters")]
public int Stopticks4long
{
get { return stopticks4long; }
set { stopticks4long = Math.Max(1, value); }
}

[Description("#Ticks over OR high for stop on short pos")]
[GridCategory("Parameters")]
public int Stopticks4short
{
get { return stopticks4short; }
set { stopticks4short = Math.Max(1, value); }
}

[Description("Bar number that will signal exit of position")]
[GridCategory("Parameters")]
public int Exitbars
{
get { return exitbars; }
set { exitbars = Math.Max(1, value); }
}

[Description("# of shares to trade in a position")]
[GridCategory("Parameters")]
public int Shares
{
get { return shares; }
set { shares = Math.Max(1, value); }
}
#endregion
}
}

"Everyday your competition is either catching up to or further surpassing you. So if you're not getting stronger, then you're getting weaker." Former strength coach.
Started this thread Reply With Quote

Journal Challenge April 2021 results (now extended!):
Competing for $1800 in prizes from Jigsaw
looks_oneMaking a Living with the Microsby sstheo
(96 thanks from 15 posts)
looks_twoSalao's Journalby Salao
(32 thanks from 7 posts)
looks_3Deetee’s DAX Trading Journal (time based)by Deetee
(26 thanks from 10 posts)
looks_4Learning to Profit - A journey in algorithms and optionsby Syntax
(13 thanks from 8 posts)
looks_5Maybe a little bit different journalby Malykubo
(9 thanks from 7 posts)
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Would You Sell Your System?
71 thanks
The Crude Dude Oil Trading System
39 thanks
Big Mike in Ecuador
36 thanks
futures io site changelog and issues/problem reporting
27 thanks
The New Micro Contract - MICRO BITCOIN coming May 2021
23 thanks
 
(login for full post details)
  #3 (permalink)
 jordis 
Mobile, Alabama
 
Experience: Beginner
Platform: NinjaTrader, TOS
Trading: Stocks
 
Posts: 29 since Sep 2011
Thanks: 6 given, 3 received


Did you ever receive a reply to this issue? I am having the same problem with minute and daily bars. if I run my code without the line "Add(PeriodType.Day, 1);" then it runs fine, but as soon as I add that line of code (even when it's not even referenced further in the strategy) then nothing happens and no trades are executed.

Reply With Quote
 
(login for full post details)
  #4 (permalink)
kconradbell
Dallas Texas United States
 
 
Posts: 5 since Apr 2014
Thanks: 1 given, 0 received

Were you able to fix? If so, could you share how please?

Thanks,
Conrad

Reply With Quote
 
(login for full post details)
  #5 (permalink)
kconradbell
Dallas Texas United States
 
 
Posts: 5 since Apr 2014
Thanks: 1 given, 0 received

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:	46
Size:	38.9 KB
ID:	160821  
Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Troubleshooting multi time frame strategy


Last Updated on October 9, 2014


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1,800 in prizes!

April

Seven Trading Mistakes Solved With Smart Trading Tools w/Brannigan Barrett

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts