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 1,735 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 1 attachments




 
Search this Thread

Two Independent Crossovers / Timing Check

  #1 (permalink)
 zeller4 
Orlando Florida
 
Experience: Intermediate
Platform: NT8
Trading: CL, NQ, ES, RTY
Posts: 477 since Jun 2009
Thanks Given: 1,416
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:	211
Size:	83.4 KB
ID:	1233  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
22 thanks
GFIs1 1 DAX trade per day journal
17 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,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603

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 Twitter 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,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


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 Twitter Reply With Quote
Thanked by:




Last Updated on June 6, 2010


© 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