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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    54 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    72 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X