NexusFi: Find Your Edge


Home Menu

 





highest bar close occuring within the last X number of bars . . . .


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Loukas with 16 posts (0 thanks)
    2. looks_two forrestang with 12 posts (8 thanks)
    3. looks_3 jmejedi with 6 posts (0 thanks)
    4. looks_4 Fat Tails with 2 posts (1 thanks)
    1. trending_up 23,413 views
    2. thumb_up 10 thanks given
    3. group 4 followers
    1. forum 37 posts
    2. attach_file 5 attachments




 
Search this Thread

highest bar close occuring within the last X number of bars . . . .

  #21 (permalink)
Loukas
London
 
Posts: 27 since Jun 2011
Thanks Given: 4
Thanks Received: 2

Hi forrestang, Many thanks for your usefull imput.
I would like to ask you something else regarding the break out strategy. I am seeking to code the same idea about a monthly and 6 month break out. However, instead of increasing the execution number of trades they are decreasing. I was expecting ( all trades= weekly trades+monthly trades+6 month trades - the same breakout trades ) but the all trades < weekly trades. Do you know how this is happen ?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
How to apply profiles
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
45 thanks
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Bigger Wins or Fewer Losses?
24 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
  #22 (permalink)
Loukas
London
 
Posts: 27 since Jun 2011
Thanks Given: 4
Thanks Received: 2

if(CurrentBar < barCount+1 || CurrentBar < monthCount+1 || CurrentBar < month6Count+1 )
return;

temp[0] = MAX(High, barCount)[0];
temp1[0] = temp[1];

month[0] = MAX(High, monthCount)[0];
month1[0] = month[1];

m6onth[0] = MAX(High, month6Count)[0];
m6onth1[0] = m6onth[1];

if (CrossAbove(Close, temp1, 1) || CrossAbove(Close, month1, 1)|| CrossAbove(Close, m6onth1, 1))
{
EnterLong(DefaultQuantity, "");
}

temp2[0] = MIN(Low, barCount)[0];
temp3[0] = temp2[1];


month2[0] = MIN(Low, monthCount)[0];
month3[0] = month2[1];

m6onth2[0] = MIN(Low, month6Count)[0];
m6onth3[0] = m6onth2[1];

if (CrossBelow(Close, temp3, 1)|| CrossBelow(Close, month3, 1)
|| CrossBelow(Close, m6onth3, 1) )
{
EnterShort(DefaultQuantity, "");
}

Reply With Quote
  #23 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


Sorry, but I'm not sure what it is you are asking?

What I scripted will buy/sell the break beyond the prior 5 bars. This doesn't matter if it's on a 5min, 60min, 1 day, 1 week or 1 month chart.

So if you want to have this work on say a weekly breakout of the prior 4 weeks(1 month), then put the strategy on a chart with bars constructed of 1 week, and set the variable I put in there called barNumber to 4.

If you want to buy/sell the breakdown of the prior 6 months, put the study on a chart of bars constructed of monthly values, and set the barNumber to 5.

The strategy doesn't care what bar interval/resolution you use.

Reply With Quote
  #24 (permalink)
Loukas
London
 
Posts: 27 since Jun 2011
Thanks Given: 4
Thanks Received: 2

I want the strategy to go long/short either when there is a breakout at 4, 22, 127 bars. So if there is a breakout one of those bars then it should execute a trade. For example, in a daily chart the startegy is going to check if there are 3 different break outs; if there is a breakout of the previous week (bar numeber 5) or breakout last month ( 22 ) or the last 6 months ( 127). If one of these breakout exist then it will execute a trade. However, in the code below instead of the number of trades through these 3 different bars increase they are decreaced.
All trades= weekly trades+monthly trades+6 month trades - the same breakout trades
The strategy with the 5 bars is executed more trades than the strategy which is include 5, 22 and 127 bars.

Reply With Quote
  #25 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047

I am lost. I'm gonna need some visual examples or something?

Reply With Quote
  #26 (permalink)
Loukas
London
 
Posts: 27 since Jun 2011
Thanks Given: 4
Thanks Received: 2

This new strategy should execute more trades compared to the strategy that you sent me but it doesnt!

#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// buys the break above 5 bars high
/// </summary>
[Description("buys the break above 5 bars high")]
public class LoukasBarBreakout : Strategy
{
#region Variables

private int barCount = 5; // Default setting for BarCount
private int monthCount = 22; // Default setting for Monthly
private int month6Count = 127; // Default setting for 6 Months

private DataSeries temp;
private DataSeries temp1;
private DataSeries temp2;
private DataSeries temp3;

private DataSeries month;
private DataSeries month1;
private DataSeries month2;
private DataSeries month3;

private DataSeries m6onth;
private DataSeries m6onth1;
private DataSeries m6onth2;
private DataSeries m6onth3;

private int target = 8;
private int stop = 16;
#endregion


protected override void Initialize()
{
temp = new DataSeries(this);
temp1 = new DataSeries(this);
temp2 = new DataSeries(this);
temp3 = new DataSeries(this);

month = new DataSeries(this);
month1 = new DataSeries(this);
month2 = new DataSeries(this);
month3 = new DataSeries(this);

m6onth = new DataSeries(this);
m6onth1 = new DataSeries(this);
m6onth2 = new DataSeries(this);
m6onth3 = new DataSeries(this);




SetStopLoss("", CalculationMode.Ticks, stop, false);
SetProfitTarget("", CalculationMode.Ticks,target);

CalculateOnBarClose = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(CurrentBar < barCount+1 || CurrentBar < monthCount+1 || CurrentBar < month6Count+1 )
return;

temp[0] = MAX(High, barCount)[0];
temp1[0] = temp[1];

month[0] = MAX(High, monthCount)[0];
month1[0] = month[1];

m6onth[0] = MAX(High, month6Count)[0];
m6onth1[0] = m6onth[1];

if (CrossAbove(Close, temp1, 1) || CrossAbove(Close, month1, 1)|| CrossAbove(Close, m6onth1, 1))
{
EnterLong(DefaultQuantity, "");
}

temp2[0] = MIN(Low, barCount)[0];
temp3[0] = temp2[1];


month2[0] = MIN(Low, monthCount)[0];
month3[0] = month2[1];

m6onth2[0] = MIN(Low, month6Count)[0];
m6onth3[0] = m6onth2[1];

if (CrossBelow(Close, temp3, 1)|| CrossBelow(Close, month3, 1)
|| CrossBelow(Close, m6onth3, 1) )
{
EnterShort(DefaultQuantity, "");
}

}

#region Properties
[Description("Number of Bars back to use in calculation")]
[GridCategory("Parameters")]
public int BarCount
{
get { return barCount; }
set { barCount = Math.Max(1, value); }
}
[Description("Number of Bars back to use in calculation")]
[GridCategory("Parameters")]
public int Month6Count
{
get { return month6Count; }
set { month6Count = Math.Max(1, value); }
}
[Description("Number of Bars back to use in calculation")]
[GridCategory("Parameters")]
public int MonthCount
{
get { return monthCount; }
set { monthCount = Math.Max(1, value); }
}
[Description("Target Size (in tics)")]
[GridCategory("Parameters")]
public int Target
{
get { return target; }
set { target = Math.Max(1, value); }
}
[Description("Stop Size (in tics)")]
[GridCategory("Parameters")]
public int Stop
{
get { return stop; }
set { stop = Math.Max(1, value); }
}
#endregion
}
}

Reply With Quote
  #27 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047

A few things.

Have you tried running each one of these periods you want to use independently of one another? And then seeing how many trades should be taken by each one alone? That would be the first thing to check via process of elimination.

Next, when you set this up to run, when you add it to a chart or when you start the back tester, did you hit the box to allow it to take more than one trade at a time?

Reply With Quote
  #28 (permalink)
Loukas
London
 
Posts: 27 since Jun 2011
Thanks Given: 4
Thanks Received: 2

Yes I have already run the strategy of each one of these periods independently. It is executed 127 trades for 5 bars and 58 for 22 bars but the aggregate strategy execute ony 115 trades which is not looks logical. I was not aware about the box which allow it to take more than one trade at a time, where is it?

Reply With Quote
  #29 (permalink)
 
forrestang's Avatar
 forrestang 
Chicago IL
 
Experience: None
Platform: Ninja, MT4, Matlab
Broker: CQG, AMP, MB, DTN
Trading: E/U, G/U
Posts: 1,329 since Jun 2010
Thanks Given: 354
Thanks Received: 1,047


Loukas View Post
Yes I have already run the strategy of each one of these periods independently. It is executed 127 trades for 5 bars and 58 for 22 bars but the aggregate strategy execute ony 115 trades which is not looks logical. I was not aware about the box which allow it to take more than one trade at a time, where is it?

I'm not in front of NT right now, but it's a user input when you add the strategy to a chart.

Or if you are running this in strategy analyzer, it is in the setup window as you set it up to run.

Reply With Quote
  #30 (permalink)
Loukas
London
 
Posts: 27 since Jun 2011
Thanks Given: 4
Thanks Received: 2


I am running this in strategy analyzer, I think your are speaking about Order Properies which has 3 options 1. By default quantity 2. by strategy 3. by account size. I selected By Default quantity and then at the default quuantity box I entered 2 but it doesnt execute more trades.

Reply With Quote




Last Updated on October 6, 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