Two Independent Crossovers / Timing Check - NinjaTrader Programming | futures trading

Go Back

> Futures Trading, News, Charts and Platforms > Platforms and Indicators > NinjaTrader > NinjaTrader Programming

Two Independent Crossovers / Timing Check
Started:August 14th, 2009 (11:52 PM) by zeller4 Views / Replies:735 / 3
Last Reply:June 6th, 2010 (07:07 AM) Attachments:1

Welcome to

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • 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, and we will never resell your private information.

-- Big Mike

Thread Tools Search this Thread

Two Independent Crossovers / Timing Check

Old August 14th, 2009, 11:52 PM   #1 (permalink)
Elite Member
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: CL, NQ, NG
Posts: 449 since Jun 2009
Thanks: 1,342 given, 376 received

Two Independent Crossovers / Timing Check

I'm attempting to identify two independent crossover events and verify if they both occur within 5 bars of each other. I've started with the following:
in Variables:
private bool crossoverEventLongA = false;
private bool crossoverEventLongB = false;
private bool crossoverLongBoth = false;
private bool crossoverEventShortA = false;
private bool crossoverEventShortB = false;
private bool crossoverShortBoth = false;
private int countDown = 0; 
in OnBarUpdate():
if (CrossAbove(PositiveHolder,EMAPositiveHolder,1)) 
 crossoverEventLongA = true; 
if (CrossAbove(NegativeHolder,EMANegativeHolder,1)) {crossoverEventLongB = true; }
if (crossoverEventLongA && crossoverEventLongB) {crossoverLongBoth = true;}
else crossoverLongBoth = false; 
what I'm not sure how to do is use countdown to prove the the EventB occurred within 6 bars of EventA.
I'm thinking I can use a countdown function somewhere to give a true/false result if the two did occur within the specified time period
 for (countdown = 6; countdown>0; countdown--)
Please help with the missing code / syntax to help me get a qualified result with the timing parameter. I've attached a screenshot to show that these cross sometimes on the same bar and sometimes not.
Thanks in advance!
Kirk (zeller4)

Attached Thumbnails
Two Independent Crossovers / Timing Check-cl-09-09-8_13_2009-4-range-.jpg  
Reply With Quote

Old August 15th, 2009, 12:15 AM   #2 (permalink)
Site Administrator
Manta, Ecuador
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
Big Mike's Avatar
Posts: 45,447 since Jun 2009
Thanks: 28,848 given, 79,601 received

Perhaps when EventA occurs, record that bar number. When EventB occurs, record that bar number. Then do Math.Abs() and see if within 6 bars.

int eventa_bar 0;
int eventb_bar 0;

if (eventA)
eventa_bar CurrentBar;

if (
eventb_bar CurrentBar;

int barsapart Math.Abs(eventa_bar eventb_bar);

if (
barsapart 6)

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following user says Thank You to Big Mike for this post:

Old June 5th, 2010, 04:17 AM   #3 (permalink)
Elite Member
Futures Experience: Beginner
Platform: Multicharts, R
Favorite Futures: EUR / USD
Posts: 185 since Feb 2010
Thanks: 106 given, 96 received

Hi Mike

Why is the "Maths.Abs" needed?


Reply With Quote

Old June 6th, 2010, 07:07 AM   #4 (permalink)
Administrator: Retired Backtester
Rennes France
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB/Kinetick
Favorite Futures: Futures
sam028's Avatar
Posts: 3,188 since Jun 2009
Thanks: 3,430 given, 3,728 received

diverdan View Post
Hi Mike

Why is the "Maths.Abs" needed?


Because it's better/shorter/smarter than writing:

int barsapart;
if (
eventa_bar eventb_bar) >= 0
=eventa_bar eventb_bar;
barsapart=eventb_bar eventa_bar;

if (
barsapart 6)
Remember that we don't know if event A occurs before event B or not.

Usually in trading, those who know don't talk, and those who talk don't know. (Al Brooks)
success requires no deodorant! (Sun Tzu)
Reply With Quote
The following user says Thank You to sam028 for this post:

Reply > Futures Trading, News, Charts and Platforms > Platforms and Indicators > NinjaTrader > NinjaTrader Programming > Two Independent Crossovers / Timing Check

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

NinjaTrader 8: Programming Profitable Trading Edges w/Scott Hodson

Elite only

Anthony Drager: Executing on Intermarket Correlations & Order Flow, Part 2

Elite only

Adam Grimes: Five critically important keys to professional trading

Elite only

Machine Learning Concepts w/FIO member NJAMC

Elite only

MarketDelta Cloud Platform: Announcing new mobile features

Dec 1

NinjaTrader 8: Features and Enhancements

Dec 6

Similar Threads
Thread Thread Starter Forum Replies Last Post
FOMC Minutes Fed Starts Talking Exit Strategy Process, But Not Yet Timing kbit News and Current Events 0 May 18th, 2011 05:18 PM
Timing DAX Futures roll-overs ? Bramhall17 Traders Hideout 6 March 14th, 2011 01:47 PM
SWISS TIMING WITH TRIGGER CHARTS jmuser The Elite Circle 16 February 6th, 2011 12:16 PM
Check out this equity curve! MXASJ NinjaTrader Programming 5 May 29th, 2010 01:09 PM
time of day / trend timing TomBear The Elite Circle 1 May 14th, 2010 09:57 AM

All times are GMT -4. The time now is 02:53 PM.

Copyright © 2016 by 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 2016-10-27 in 0.10 seconds with 20 queries on phoenix via your IP