NexusFi: Find Your Edge


Home Menu

 





Convert Custom MACD Script To Work With Ninja Trader API


Discussion in NinjaTrader

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




 
Search this Thread

Convert Custom MACD Script To Work With Ninja Trader API

  #1 (permalink)
conord
Ireland
 
Posts: 3 since Feb 2013
Thanks Given: 1
Thanks Received: 0

Hi All,

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.

Many thanks in advance.

Conor.

<-------------------------------------------------------------------------------------------------------->
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = {SMA, default EMA};

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));

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
What broker to use for trading palladium futures
Commodities
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Quant vue
Trading Reviews and Vendors
ZombieSqueeze
Platforms and Indicators
 
  #2 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,103

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.

MACD > 0 && histogram > 0 -> uptrend
MACD > 0 && histogram < 0 -> no trend
MACD < 0 && histogram > 0 -> no trend
MACD < 0 && histogram < 0 -> downtrend

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.


Attached Files
Elite Membership required to download: MACDUniversalX2.zip
Reply With Quote
Thanked by:
  #3 (permalink)
conord
Ireland
 
Posts: 3 since Feb 2013
Thanks Given: 1
Thanks Received: 0


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.

Best regards,
Conor.

Reply With Quote
  #4 (permalink)
conord
Ireland
 
Posts: 3 since Feb 2013
Thanks Given: 1
Thanks Received: 0

Many thanks again for the feed back, this thread is now closed. Best regard conord

Reply With Quote




Last Updated on February 20, 2013


© 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