crossing an indicator for backtesting - NinjaTrader Programming | futures io social day trading
futures io futures trading

crossing an indicator for backtesting
Updated: Views / Replies:636 / 4
Created: by yeshe Attachments:0

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 100,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

Thread Tools Search this Thread

crossing an indicator for backtesting

  #1 (permalink)
Elite Member
San Fransisco Ca
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: IB
Favorite Futures: forex
Posts: 17 since Jan 2014
Thanks: 5 given, 1 received

crossing an indicator for backtesting

Hello forum,

I want to do something very easy but cannot figure it out

I want while BACKTESTING as soon as the price >= upperBowlingerBand go long

I have e-mailed back and forth a lot with Ninjatrader

they came up with the following code

The code seems not logical to me and sometimes it does not work.

In this forum i saw one of Mikes great videos, in which he mentions:

"NinjaTrader is not capable of submitting intrabar orders in backtesting. Live strategies can submit intrabar orders using calculate bar close = false. Trying to simulate IOG within a backtestable strategy in NinjaTrader requires writing custom code to use MTF and try to work-around the problem, and it adds a great deal of complexity, plus MTF doesn't even work in current beta's of NinjaTrader."

Can this simple condition be programmed in Ninjatrader (for Backtesting)?

Would love some expertise from this forum

many tx


protected override void Initialize()
CalculateOnBarClose = true;
// this adds the tick secondary data series
Add(PeriodType.Tick, 1);

protected override void OnBarUpdate()
// this makes sure that the script is processed with tick data
if (BarsInProgress != 1)

if (Closes[1][1] < Bollinger(Closes[0], 2,14).Upper[1] &&
Closes[1][0] >= Bollinger(Closes[0], 2,14).Upper[0])

// enter order on tick series
EnterLong(1, 1, "longOrder");

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
San Fransisco Ca
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: IB
Favorite Futures: forex
Posts: 17 since Jan 2014
Thanks: 5 given, 1 received

Unfortunately no answers yet from this forum

I have something to add since my ongoing investigation on this item.

Ninjatrader confirmed it is not possible:

"I've been getting assistance from our development, however, this is not a very common question. Intra-bar granularity is mostly used for getting proper exits in backtest. Finding a crossover using intra-bar granularity is not a question I've had to answer before."

The final code is

if (Closes[0][0] < Bollinger(Closes[0], 2,14).Upper[0] &&
Closes[1][0] >= Bollinger(Closes[0], 2,14).Upper[0])

This will refer to the Upperbowlinger of the recently closed primary bar. But will not refer to the actual BB value (between two primary bars).

Is it possible within Multicharts?

eagerly awaiting your response

Reply With Quote
  #4 (permalink)
Elite Member
San Fransisco Ca
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: IB
Favorite Futures: forex
Posts: 17 since Jan 2014
Thanks: 5 given, 1 received

Just to update this thread

Ninja trader is submitting a request to have this implemented.

also Multicharts is not able to solve this

I am wondering if i am asking a strange question, also because of no reply in this forum, i must be the only one having this problem? I run into this problem with every indicator used as an entry- or exitsignal during backtesting.

answer from Multicharts:
primary data is weekly
secondary data is daily

"I have consulted once again with our developers regarding your inquiry.
The code is not able to (daily) refer to bb values between 2 (weekly) bars if the indicator is based on the weekly series.
When the indicator is based on the weekly series there are only two values and a connecting line between them for two weekly bars.
There are no values in-between.
If you want to have values on each daily bar then you need to base the study calculation on a daily series (Format->Study->Format->Properties->Base study on)."

Still would love to know how (formerly BMT) members deal with this.. or not??
So i can backtest and optimize correctly what seems only possible to do in real time( for now).

Reply With Quote
  #5 (permalink)
Market Wizard
OC, California, USA
Futures Experience: Advanced
Platform: IB/TWS, NinjaTrader, thinkorswim
Favorite Futures: stocks, options, futures, VIX
shodson's Avatar
Posts: 1,878 since Jun 2009
Thanks: 485 given, 3,309 received

This code will only work if the bar CLOSES above the upper Bollinger band, not if it moves through it within a bar and closes back below it. To backtest that situation, you will need to use EnterLongStopLimit() for order entries. Sorry, I don't have time to write, debug and support a code sample for you at this time but that is something you or your contact at Ninjatrader can look at.

Reply With Quote


futures io > > > > > crossing an indicator for backtesting

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

July Journal Challenge - $500 in Amazon Gift Cards!


Battlestations: $750 in prizes - Show us your trading desk!


TBA: FuturesTrader71 w/Morad Askar

Elite only

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scanning crossing condition Ardian1899 ThinkOrSwim Programming 0 July 15th, 2014 04:57 AM
Backtesting 3rd party indicator? LightWeight NinjaTrader 4 January 2nd, 2014 07:41 PM
Needs help for to program own indicator into backtesting abourgeois Hire a Consultant or Programmer 0 April 7th, 2013 07:59 AM
Counter crossing the horizontal line doitagaitforme NinjaTrader Programming 12 May 3rd, 2012 07:08 PM

All times are GMT -4. The time now is 02:40 PM. (this page content is cached, log in for real-time version)

Copyright © 2018 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432,
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 2018-07-20 in 0.11 seconds with 14 queries on phoenix