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

Bar/ EMA Crossover Indicator

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

    Bar/ EMA Crossover Indicator

    Hello everybody. This is my first post on this forum, so please be gentle;
    I am trying to create an indicator which will be used in Market Analyzer to trigger an alert when conditions specified are present: previous bar crossing three EMA's. Calculated on bar close. Relationship between EMA's, their shape or slope irrelevant. Following the teachings in the help manual I wrote the script:
    // plot below by replacing 'Close[0]' with your own formula.

    Plot0.Set((Close[1] > Open[1]
    && Open[1] < EMA(4)[1]
    && Close[1] > EMA(4)[1]
    && Open[1] < EMA(8)[1]
    && Close[1] > EMA(8)[1]
    && Open[1] < EMA(21)[1]
    && Close[1] > EMA(21)[1]) ? 1 : 0);
    It went smoothly thru compile process and indicator shows in indicator list, however it will not plot on chart nor trigger alert in Market Analyzer. In MA it just prints current price instead 1's for true, 0's for false. I've attached two screen images to illustrate.Kindly please advise...
    Attached Files
    Last edited by peter@cleaniq; 02-22-2010, 05:23 PM.

    #2
    Hello Peter,

    Welcome to our forums.

    Most likely you are running into the issue below:
    Make sure you have enough bars in the data series you are accessing

    Try adding this statement in the OnBarUpdate() method.
    if (CurrentBar <= 22)
    return;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Bar/ EMA Crossover Indicator

      Thank you Ryan for your help. Is the # of bars arbitrary? I noticed that Moving Averages and Volume don't print for the first 20 bars unless "show unstable.." is true. I need EMA(4),(8),(21) so, at least EMA(4) should start printing after first 4 bars and then EMA(8) should appear after 8 bars etc..It does happen only when "Show Unstable..." is true, that they print from the very first bar. So, there are three EMA's printing while there is not enough bar data to calculate them.After 20 bars there is plenty of data to calculate at least EMA(20) but it also means that on 10' chart we need 3hrs and 20' into the trading day to see real EMA shape and slope. That makes my indicator useless. Again, Thank you for your help and guidance.

      Comment


        #4
        Hi Peter,

        You need the CurrentBar check when NinjaScript will try to access bar objects that don't exist at the beginning of the series. The bar count isn't arbitrary but rather depends on the periods of indicators.

        Show Unstable period will allow you to plot indicators while they are developing, but you still need statements in your code so that NinjaTrader won't try to access non-existing objects.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Christopher_R, Today, 12:29 AM
        0 responses
        9 views
        0 likes
        Last Post Christopher_R  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        166 responses
        2,235 views
        0 likes
        Last Post sidlercom80  
        Started by thread, Yesterday, 11:58 PM
        0 responses
        3 views
        0 likes
        Last Post thread
        by thread
         
        Started by jclose, Yesterday, 09:37 PM
        0 responses
        8 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,415 views
        0 likes
        Last Post Traderontheroad  
        Working...
        X