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

Convert Easy Languabe to Ninja

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

    Convert Easy Languabe to Ninja

    I have this indicator:

    { ***** INPUTs Section *****}
    Inputs: BandDays(28), DevConstant(3.500000);
    { ***** VARs Section ***** }
    Variables: keltnerTop(0), keltnerMid(0), keltnerBot(0), expSmoothPrice(0);
    Variables: expSmoothRange(0);
    { ***** ARRAYs Section *****}
    { ***** CODE Section ***** }
    BEGIN
    IF (CURRENTBAR = 1) THEN
    BEGIN
    expSmoothPrice = CLOSE ;
    expSmoothRange = HIGH-LOW ;
    END ELSE
    BEGIN
    expSmoothPrice = (expSmoothPrice*(BandDays-1)+CLOSE)/BandDays ;
    expSmoothRange = (expSmoothRange*(BandDays-1)+(HIGH-LOW))/BandDays ;
    END ;

    keltnerTop = expSmoothPrice+(expSmoothRange*DevConstant) ;
    keltnerMid = expSmoothPrice ;
    keltnerBot = expSmoothPrice-(expSmoothRange*DevConstant) ;
    PLOT1 (keltnerTop, "TBand Top") ;
    PLOT2 (keltnerMid, "TBand Mid") ;
    PLOT3 (keltnerBot, "TBand Bot") ;
    END ;

    And I convert it like this:

    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    if (CurrentBar == 0)
    {
    expSmoothPrice = Close[0];
    expSmoothRange = High[0] - Low[0];
    }
    else
    {
    expSmoothPrice = (expSmoothPrice * (BandDays - 1) + Close[0]) / BandDays;
    expSmoothRange = (expSmoothRange * (BandDays - 1) + (High[0] - Low[0])) / BandDays;
    }
    KeltnerTop.Set(expSmoothPrice + (expSmoothRange * DevConstant));
    KeltnerMid.Set(expSmoothPrice);
    KeltnerBot.Set(expSmoothPrice - (expSmoothRange * DevConstant));
    }

    There is a problem first n bars paint. How can i fix it? See the attachment please.
    Attached Files

    #2
    Hello there, welcome to the forums! NinjaTrader indicators require 20 bars before they start plotting, so that is probably what we're seeing here. Please try setting BarsRequired = 2 in the Initialize() section of your code and see if that fixes the late plotting.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi Austin,

      Thanks for your friendly welcome and response of course. Sory but i think there is a misunderstanding. Actually my problem is my indicator's formula. If I set BarsRequired 2 or for example BandDays input value, there is nothing changing. Set BarsRequired do only benefit hide bad calculated bars, but of couse result is wrong again.

      Please tell me,
      1.How can i attain first 20 bars that previoues first calculated.
      I mean when CurrentBar == 0 can i access previoues bars?
      2.Most Important if you look my code, I wrote these lines:

      if (CurrentBar == 0)
      {
      expSmoothPrice = Close[0];
      expSmoothRange = High[0] - Low[0];
      }

      .
      .
      .

      KeltnerTop.Set(expSmoothPrice + (expSmoothRange * DevConstant));
      KeltnerMid.Set(expSmoothPrice);
      KeltnerBot.Set(expSmoothPrice - (expSmoothRange * DevConstant));


      How KelterMid plot 0 value different from first bar's close price from???
      3.How can i take previous or next bar any value in OnBarUpdate function?
      Suppose income new thick, at that time CurrentBar value is 35 this mean Close[0] = 35. Bar close value. How can i take 34. or 36. Bar close value?

      Best Regards

      Comment


        #4
        Originally posted by aytacasan View Post
        Hi Austin,

        Thanks for your friendly welcome and response of course. Sory but i think there is a misunderstanding. Actually my problem is my indicator's formula. If I set BarsRequired 2 or for example BandDays input value, there is nothing changing. Set BarsRequired do only benefit hide bad calculated bars, but of couse result is wrong again.

        Please tell me,
        1.How can i attain first 20 bars that previoues first calculated.
        I mean when CurrentBar == 0 can i access previoues bars?
        If CurrentBar == 0, that means there are no bars to the left of that bar, so can't access those missing bars.
        2.Most Important if you look my code, I wrote these lines:

        if (CurrentBar == 0)
        {
        expSmoothPrice = Close[0];
        expSmoothRange = High[0] - Low[0];
        }

        .
        .
        .

        KeltnerTop.Set(expSmoothPrice + (expSmoothRange * DevConstant));
        KeltnerMid.Set(expSmoothPrice);
        KeltnerBot.Set(expSmoothPrice - (expSmoothRange * DevConstant));


        How KelterMid plot 0 value different from first bar's close price from???
        Because the indicator doesn't start plotting until the 20 bars have gone by, the script is not actually reading the first bar - it is looking at the close of the 21st bar. Please try adding this line of code to the very top of your OnBarUpdate() section and see if your issues go away:
        Code:
        OnBarUpdate()
        if (CurrentBar < 21)
            return;
        That code will essentially ignore the first 20 bars on the chart and could stabilize your calculations.
        3.How can i take previous or next bar any value in OnBarUpdate function?
        Suppose income new thick, at that time CurrentBar value is 35 this mean Close[0] = 35. Bar close value. How can i take 34. or 36. Bar close value?

        Best Regards
        The Close, High, Low, Volume, etc arrays are reverse indexed so that means Close[0] references the close of the most current bar. If CurrentBar = 35, then to get the close on the 34th bar, you could use Close[1]. It is not possible for a bar to access a value from a bar in the future.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Thanks for your response,

          1.So my problem will solve if I can access chart first bar's previous bars that there is not visual in the chart? Can I?

          2.I understand clearly what is and how process first 20 bars. Thank you.

          3.Are you mean that when indicator start to work, it's process chart bars left to right. So chart first bar at the same time 0 index bar. BarsRequired only control where is the start of ploting(If you don't change this via code). For each bar OnBarUpdate event calling at the backgroud. At that point suppose CurentBar = 35.So,

          Close = DataSeries that hold 0-34 bars close but reverse order. So,
          Close[0] = Chart most right(last) bar.
          Close[34] = Chart most left bar.

          So i can access any time in OnBarUpdate event previous bar close via Close[1]. But i can't access next bar close. If i need this i must wait to call OnBarUpdate for next bar. If i have misunderstanding please inform me.

          Sory for my poor english and basic questions.

          BEST REGARDS.

          Comment


            #6
            Hello again, I have answered your questions below.
            Originally posted by aytacasan View Post
            Thanks for your response,

            1.So my problem will solve if I can access chart first bar's previous bars that there is not visual in the chart? Can I?
            Unfortunately this is not possible. There are no bars to the left of the left most bar drawn on the chart. For your script, I have a feeling you will have to load up a few (50-100) extra bars on your chart at the beginning to let the calculations stabilize before using the output of the script.
            3.Are you mean that when indicator start to work, it's process chart bars left to right. So chart first bar at the same time 0 index bar. BarsRequired only control where is the start of ploting(If you don't change this via code). For each bar OnBarUpdate event calling at the backgroud. At that point suppose CurentBar = 35.So,

            Close = DataSeries that hold 0-34 bars close but reverse order. So,
            Close[0] = Chart most right(last) bar.
            Close[34] = Chart most left bar.

            So i can access any time in OnBarUpdate event previous bar close via Close[1]. But i can't access next bar close. If i need this i must wait to call OnBarUpdate for next bar. If i have misunderstanding please inform me.
            Your understanding of how this works is perfect.
            Sory for my poor english and basic questions.
            BEST REGARDS.
            Not a problem. Glad I could help. Let us know if you have any other questions.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Hi,

              Ninja's architecture of generating indicators&Strategies is perfect. I was labored many years create indicators&Strategies at the MetaTrader platform. Shame! MetaTrader is very poor and has not collectivity.

              Anyway, You said that "Unfortunately this is not possible". So Ninja has not support work with historical data. Is it true? For example i have a daily EURUSD chart.It has only last 30 day data. And when triger OnBarUpdate() I must look one month ago bars for calculate made up formula.

              OnBarUpdate()
              {
              if(CurrentBar == 0)
              {
              //So you must go past month and look for made up.
              DataSeries dt = Ninja.GetHistoricData("EURUSD", Daily, ThisMonthFirstDate - 30, ThisMonthFirstDate);
              foreach(dt) { dosomething(); }
              }
              else
              {
              //Other bars process
              }

              Have a nice day.

              Comment


                #8
                aytacasan, unfortunately you can't programmatically load additional historical data - if you setup a chart with your 30 days back for example your script simply can't reference a historical bar to the left from the first bar on this chart, as there is no data on it for it. If the maximum you reference back in your script is 20 bars, you would need wait for 20 bars to pass to start the calcs then.
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Option Whisperer, Today, 09:55 AM
                1 response
                11 views
                0 likes
                Last Post bltdavid  
                Started by port119, Today, 02:43 PM
                0 responses
                1 view
                0 likes
                Last Post port119
                by port119
                 
                Started by Philippe56140, Today, 02:35 PM
                0 responses
                3 views
                0 likes
                Last Post Philippe56140  
                Started by 00nevest, Today, 02:27 PM
                0 responses
                2 views
                0 likes
                Last Post 00nevest  
                Started by Jonafare, 12-06-2012, 03:48 PM
                5 responses
                3,986 views
                0 likes
                Last Post rene69851  
                Working...
                X