highest bar close occuring within the last X number of bars . . . . - NinjaTrader Programming | futures io social day trading
futures io futures trading


highest bar close occuring within the last X number of bars . . . .
Updated: Views / Replies:11,858 / 37
Created: by jmejedi Attachments:5

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 donít 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
 5  
 
Thread Tools Search this Thread
 

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

  #21 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

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
 
  #22 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

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)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received


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)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

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)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received

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

Reply With Quote
 
  #26 (permalink)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

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)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received

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)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received

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)
Urban Samurai
Chicago IL
 
Futures Experience: Intermediate
Platform: Ninja, MT4,TOS, SC, Matlab
Broker/Data: CQG, AMP, MB, DTN
Favorite Futures: E/U, G/U
 
forrestang's Avatar
 
Posts: 1,039 since Jun 2010
Thanks: 226 given, 688 received


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)
Trading Apprentice
London
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Currencies
 
Posts: 27 since Jun 2011
Thanks: 4 given, 2 received


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

Reply



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

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
number of ticks in a bar/ms timestamp ? sam028 NinjaTrader Programming 15 September 21st, 2012 08:50 AM
How to program price cross below a number of previous bars Twiddle NinjaTrader Programming 8 May 17th, 2011 05:58 PM
how to count in nt7 the number of bars that have closed? anniebee321 NinjaTrader 9 April 26th, 2011 12:27 PM
How do I access the bar number under the cursor? koganam NinjaTrader Programming 3 September 6th, 2010 10:25 AM
Close[0] not waiting until bar close dsraider NinjaTrader Programming 4 February 11th, 2010 06:49 PM


All times are GMT -4. The time now is 07:17 AM.

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-16 in 0.15 seconds with 20 queries on phoenix via your IP 54.226.113.250