Troubleshooting multi time frame strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


Troubleshooting multi time frame strategy
Updated: Views / Replies:1,819 / 4
Created: by jperales Attachments:1

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you dont need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Troubleshooting multi time frame strategy

  #1 (permalink)
Elite Member
Durham, NC
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: YM
 
Posts: 2 since Jul 2012
Thanks: 6 given, 0 received

Troubleshooting multi time frame strategy

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.
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Mobile, Alabama
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
Favorite Futures: Stocks
 
Posts: 29 since Sep 2011
Thanks: 6 given, 4 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
 
  #4 (permalink)
Trading Apprentice
Dallas Texas United States
 
Futures Experience: Intermediate
Platform: Ninja Trader
Favorite Futures: Futures, TF, ES, YM, 6E
 
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
 
  #5 (permalink)
Trading Apprentice
Dallas Texas United States
 
Futures Experience: Intermediate
Platform: Ninja Trader
Favorite Futures: Futures, TF, ES, YM, 6E
 
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
Troubleshooting multi time frame strategy-ninjascriptcapture.png  
Reply With Quote

Reply



futures io > > > > > Troubleshooting multi time frame strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Time Frame Strategy Cancellation jthom NinjaTrader Programming 2 October 9th, 2014 12:00 PM
ADX Multi Time Frame bellair NinjaTrader 9 November 10th, 2011 11:14 AM
Close bar recognization in multi time frame strategy pinto552 NinjaTrader Programming 6 September 6th, 2011 10:07 AM
Back to the Future! Back testing multi time frame strategy trades occuring in future mrticks The Elite Circle 10 April 2nd, 2011 10:54 AM
Multi-time frame strategy with periods of different size pequemec NinjaTrader Programming 2 February 24th, 2010 01:41 PM


All times are GMT -4. The time now is 11:24 PM.

Copyright © 2017 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
Page generated 2017-12-17 in 0.13 seconds with 20 queries on phoenix via your IP 54.221.73.186