NexusFi: Find Your Edge


Home Menu

 





Two Independent Crossovers / Timing Check


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Big Mike with 1 posts (1 thanks)
    2. looks_two zeller4 with 1 posts (0 thanks)
    3. looks_3 sam028 with 1 posts (1 thanks)
    4. looks_4 diverdan with 1 posts (0 thanks)
    1. trending_up 2,229 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 478 since Jun 2009
Thanks Given: 1,419
Thanks Received: 404

Hello,
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:
 
Code
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
 
Code
 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
Click image for larger version

Name:	CL 09-09  8_13_2009 (4 Range).jpg
Views:	288
Size:	83.4 KB
ID:	1233  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Penalties in Budapest, Peace Deadline in Tehran: Arsenal …
Prediction Markets & Event Contracts
OneChronos Launches First Combinatorial Auction FX Venue …
Currencies
The May 31 Binary: 60% Trump Declares Iran Ops Over, Onl …
Prediction Markets & Event Contracts
CME Cuts Precious Metals Margins Up to 21% Starting Toda …
Commodities
The Feds Stagflation Trap -- Negative Payrolls, $91 Oil, …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
2026 Fire Horse
5 thanks
  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,557

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.

 
Code
                            
#variables
int eventa_bar 0;
int eventb_bar 0;

#onbarupdate
if (eventA)
  
eventa_bar CurrentBar;

if (
eventB)
  
eventb_bar CurrentBar;

int barsapart Math.Abs(eventa_bar eventb_bar);

if (
barsapart 6)
  
doSomething() 
Mike




We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
 diverdan 
Singapore
 
Experience: Beginner
Platform: Multicharts, R
Trading: EUR / USD
Posts: 185 since Feb 2010
Thanks Given: 106
Thanks Received: 99


Hi Mike

Why is the "Maths.Abs" needed?

Thanks


Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,756 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,632


diverdan View Post
Hi Mike

Why is the "Maths.Abs" needed?

Thanks

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

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

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


Success requires no deodorant! (Sun Tzu)
Follow me on X Reply With Quote
Thanked by:




Last Updated on June 6, 2010


© 2026 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 - Downloads - Top
no new posts