Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I have basically no experience in C#.. How can I get this to work?

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

    I have basically no experience in C#.. How can I get this to work?

    protected override void OnBarUpdate()
    {
    bool macdline = EMA(12)-EMA(26)
    bool signalline = EMA(9)*macdline

    if (CrossAbove(macdline, signalline, 1))
    EnterLong();


    }
    }
    }​

    Trying to make it so it enters into a long position when MACD line crosses over Signal Line.

    #2
    Hello unpronounceable1700,

    Welcome to the NinjaTrader forums!

    Below I am providing a link to a support article with helpful resources on getting started with learning C# and NinjaScript.


    For the CrossAbove the current bar and previous bar values are needed so this only works with Series<double> objects.


    Save the values to a custom series, and this can be supplied to CrossAbove().

    In the scope of the class:
    private Series<double> macdLine, signalLine;

    In OnStateChange when State is State.DataLoaded:
    macdLine = new Series<double>(this);
    signalLine = new Series<double>(this);

    In OnBarUpdate():
    macdLine[0] = EMA(12)[0] - EMA(26)[0];
    signalLine[0] = EMA(9)[0] - macdLine[0];

    if (CrossAbove(macdLine, signalLine, 1))​
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    66 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    55 views
    0 likes
    Last Post CarlTrading  
    Working...
    X