NexusFi: Find Your Edge


Home Menu

 





X Bars ago


Discussion in NinjaTrader

Updated
    1. trending_up 1,374 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

X Bars ago

  #1 (permalink)
 
ryangillespie's Avatar
 ryangillespie 
london, England
 
Experience: Intermediate
Platform: Ninjatrader
Trading: CL, ES
Posts: 41 since Nov 2011
Thanks Given: 10
Thanks Received: 2

Hi All,

Can someone please assist, I need to say that "MACD Cross Up"

if (strxav2 == "UT" && strxav1 == "UT" && strsignal == "MACD Cross UP") signal should have happened within X bars, help appreciated

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
About a successful futures trader who didnt know anythin …
Psychology and Money Management
Cheap historycal L1 data for stocks
Stocks and ETFs
Quantum physics & Trading dynamics
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
  #2 (permalink)
 asfax 
Prague, Czech Republic
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: NQ
Posts: 57 since Sep 2009
Thanks Given: 34
Thanks Received: 79

Hi @ryangillespie
try CrossAbove() / CrossBelow() https://ninjatrader.com/support/helpGuides/nt7/?crossabove.htm
Some samples for MACD: https://forum.ninjatrader.com/forum/ninjatrader-8/indicator-development/109058-macd-cross-above-indicator-with-draw-arrow-need-some-help

Reply With Quote
  #3 (permalink)
 zr6bcm 
Heidelberg, Germany
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Stocks
Posts: 12 since Jun 2014
Thanks Given: 9
Thanks Received: 12


I suspect the "have happened within X bars" is the part that is the core of your question.

The way I do it, is that I add a class variable:
 
Code
const int maxSignalDays = 10;
int signalAvailable = 0;
Then somewhere in my OnBarUpdate I will have roughly this code sequence:

 
Code
....
// If we have a signal, then let us reduce the day count. 
if (signalAvailable > 0) signalAvailable--;
if (signalAvailable < 0) signalAvailable++;

// Do we have a new signal ON THIS DAY?
if (...MACD logic == LONG...)  signalAvailable = +1 * maxSignalDays;
if (...MACD logic == SHORT...) signalAvailable = -1 * maxSignalDays;


....
// Do we want to trade over the next days on this signal
if (... conditions A-Z ... && signalAvailable >0)
{
    ... enter long ...
}
if (... conditions A-Z ... && signalAvailable <0)
{
    ... enter short ...
}

Reply With Quote




Last Updated on May 3, 2020


© 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