Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Convert Custom MACD Script To Work With Ninja Trader API
I'm new to Ninja Trader and have been really struggling to convert a short MACD scrip to use as a custom indicator with the Ninja Trader API. The script below if for a MACD crossover and histogram chart similar to Ninja Trader's default one, however the histogram is color coded to indicate if the %K line is positive or negative and also indicates if %K is trending higher or lower, any assistance would be very much appreciated as my frustration has reached boiling point.
plot Value;
plot Avg;
switch (AverageType) {
case SMA:
Value = Average(close, fastLength) - Average(close, slowLength);
Avg = Average(Value, MACDLength);
case EMA:
Value = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);
Avg = ExpAverage(Value, MACDLength);
}
plot Diff = Value - Avg;
plot ZeroLine = 0;
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
Can you help answer these questions from other members on NexusFi?
The MACD does not have a %K line, but I suppose you talk about the histogram.
When I use the MACD what is most important to me is whether the MACD itself is positive. This is a proxy for momentum. You can basically use the MACD as follows
raw MACD = proxy for momentum = proxy for price change
histogram = proxy for momentum change = proxy for curvature of price move
slope of histogram = proxy for curvature of momentum
If you only look at the histogram and its slope, you are missing the essential point, which is the direction of momentum. I would therefore suggest to build a trendfilter based on the MACD and the histogram, but not take into account the slope of the histogram, or at least underweigh it for the purpose of determining the trend.
The attached indicator is an MACD that can be calculated from 27 different moving averages. It has an integrated trendfilter, which is based on the direction of the raw MACD and the histogram.
You could try to modify it in order to suit your needs. Please save the modified version under a new name, and also replace enums, because otherwise the new indicator will not compile.
Hi Fat Tails, many thanks for your feedback, I am in agreement with your comments regarding interpretation of the MACD, I guess I could of been a little more specific in my initial post. I trade daily charts and find the histogram re-tracement a useful exit signal, but sometimes the histogram will publish similar 2 or 3 similar values consequently which can makes it difficult to interpret by glancing at the histogram. Nevertheless I'm looking forward to having a play about with your attached file.