NexusFi: Find Your Edge


Home Menu

 





Troubleshooting multi time frame strategy


Discussion in NinjaTrader

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




 
Search this Thread

Troubleshooting multi time frame strategy

  #1 (permalink)
 jperales 
Durham, NC
 
Experience: Intermediate
Platform: NinjaTrader
Trading: YM
Posts: 2 since Jul 2012
Thanks Given: 6
Thanks Received: 0

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

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
Are there any eval firms that allow you to sink to your …
Traders Hideout
Deepmoney LLM
Elite Quantitative GenAI/LLM
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #3 (permalink)
 jordis 
Mobile, Alabama
 
Experience: Beginner
Platform: NinjaTrader, TOS
Trading: Stocks
Posts: 29 since Sep 2011
Thanks Given: 6
Thanks Received: 3


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)
kconradbell
Dallas Texas United States
 
Posts: 5 since Apr 2014
Thanks Given: 1
Thanks Received: 0

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

Thanks,
Conrad

Reply With Quote
  #5 (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:	158
Size:	38.9 KB
ID:	160821  
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