Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

MACD crossing zero line

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MACD crossing zero line

    I'm new to programing so I was hoping someone could help me with this problem.

    I developing a strategy with the wizard and want to trigger a buy order when the diff line from the MACD indicator crosses over the "zero line". However, the indicator wizard doesn't allow me to select the zero line because it's not a plot line. (It's just a line.) I tried to change the "new line" code to "new Plot" but that resulted in removing the line all together.

    In other attempts I changed the name "zero line" to just "zeroline" because Ninja doesn't line the space. And got a CS0117 error that sys 'double' does not contain a definition for 'Set'

    Below is some of the MACD indicator code.

    protected override void Initialize()
    {
    Add(new Plot(new Pen(Color.Yellow, 1), PlotStyle.Line, "Diff"));
    Add(new Plot(new Pen(Color.Blue, 2), PlotStyle.Bar, "DiffUp"));
    Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Bar, "DiffDown"));
    Add(new Plot(new Pen(Color.Cyan, 1), PlotStyle.Line, "DiffAvg"));
    Add(new Line(new Pen(Color.Red, 1), 0, "Zero line"));


    I think the strategy code would be something like below where "XXXX" is the zero line.

    // Condition set 1
    if (CrossAbove(MACDScalp(5, 5, 34, 5).Diff, MACDScalp(5, 5, 34, 5).XXXX, 1))
    {
    EnterLong(DefaultQuantity,
    "LONG 1A");


    Does anyone know what is the best solution to this???

    Thanks for your help!!!

    #2
    dewurster, you can just use something like this snippet below and check for a cross of the Diff with a value of 0 -

    if (CrossAbove(MACD(12, 26, 9).Diff, 0, 1))
    {
    }
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by algospoke, Yesterday, 06:40 PM
    2 responses
    19 views
    0 likes
    Last Post algospoke  
    Started by ghoul, Today, 06:02 PM
    3 responses
    14 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    45 views
    0 likes
    Last Post jeronymite  
    Started by Barry Milan, Yesterday, 10:35 PM
    7 responses
    20 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by AttiM, 02-14-2024, 05:20 PM
    10 responses
    180 views
    0 likes
    Last Post jeronymite  
    Working...
    X