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

Help with Indicator Development

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

    Help with Indicator Development

    I need to shade the background of the chart to provide visual indication for favorable entry environment for long and short trades. I have modified another custom indicator in an attempt to do this. However, when the conditions are true, the indicator does not shade the background as I want it. Can anybody help fix this for me?

    protectedoverridevoid OnBarUpdate()
    {
    if(indSMAFast[0] > indSMAFast[5]
    && indSMAMedium[
    0] > indSMAMedium[20]
    && Close[
    0] > indSMAVSlow[0]
    && Close[
    0] > indSMAFast[0]
    )
    {
    BackColor = Color.LawnGreen;
    }

    if(
    indSMAFast[
    0] < indSMAFast[5]
    && indSMAMedium[
    0] < indSMAMedium[20]
    && Close[
    0] < indSMAVSlow[0]
    && Close[
    0] < indSMAFast[0]

    )

    {
    BackColor = Color.LightSalmon;
    }

    #2
    Hello sandeshrai,

    Thank you for your post.

    If you place Print() statements after the conditions do you see the prints in the Output Window (Tools > Output Window)?
    Code:
    protectedoverridevoid OnBarUpdate()
    {
    if(indSMAFast[0] > indSMAFast[5]
    && indSMAMedium[0] > indSMAMedium[20]
    && Close[0] > indSMAVSlow[0]
    && Close[0] > indSMAFast[0]
    ) 
    {
    [B]Print(Time[0] + " Background should be LawnGreen.");[/B]
    BackColor = Color.LawnGreen;
    }
    
    if(
    indSMAFast[0] < indSMAFast[5]
    && indSMAMedium[0] < indSMAMedium[20]
    && Close[0] < indSMAVSlow[0]
    && Close[0] < indSMAFast[0]
    
    )
    
    {
    [B]Print(Time[0] + " Background should be LightSalmon.");[/B]
    BackColor = Color.LightSalmon;
    }
    For information on Print() please visit the following link: http://www.ninjatrader.com/support/h.../nt7/print.htm

    Please let me know if you have any questions.

    Comment


      #3
      Attempted adding Print statement

      Hi Patrick,

      I added the Print statements, but that doesn ot print either. Additionally, I tried to have the SMA to be visible on the chart by adding the line :Add (indSMAFast);. I get the error messages

      The best overloaded method match for 'NinjaTrader.Indicator.IndicatorBase.Add(NinjaTrad er.Gui.Chart.Line)' has some invalid arguments

      and

      Argument '1': cannot convert from 'NinjaTrader.Indicator.SMA' to 'NinjaTrader.Gui.Chart.Line'

      I have attached a text file with the entire code
      Attached Files

      Comment


        #4
        Hello sandeshrai,

        Thank you for your response.

        If possible, can you send me the indicator and any required indicators so I may test this matter on my end? If you prefer you can send these files to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 852139' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=58054

        I look forward to your response.

        Comment


          #5
          Indicator attached

          Thanks Patrick.

          I am not using any indicators other than what is in the text file that I have sent. My logic will be based on SMA and other standard indicators availbale in NinjaTrader. I have exported my entire file and am attaching here.
          Attached Files

          Comment


            #6
            Hello sandeshrai,

            Thank you for your response.

            I will investigate further and follow up with you shortly.

            Comment


              #7
              Hello sandeshrai,

              Thank you for your response.

              I am receiving the following error when applying the indicator to a chart:
              Error on calling 'OnBarUpdate' method for indicator 'StopTarget' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
              You will need to make sure you have enough bars on the chart before accessing the values. For information on this matter please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170

              Please let me know if I may be of further assistance.

              Comment


                #8
                Patrick, I do have enough bars on the chart. At anytime, I have at least 30 days of candle loaded.

                Comment


                  #9
                  Hello sandeshrai,

                  You would need to check inside of your Indicator to make sure you have enough data loaded, not just inside of your Data Series.

                  So NinjaTrader will start calculating the indicator from the start of the data series but if you are trying to access the last 50 bars of data when there is only 20 bars so far then you may get an error like this. You may add a check via code just like in the thread that Patrick linked above.

                  Example:
                  Code:
                  protected override void OnBarUpdate()
                  {
                      // Make sure that there is at least 50 bars of data before starting to calculate the Indicator
                      if (CurrentBar < 50)
                          return;
                      // Rest of code
                  JCNinjaTrader Customer Service

                  Comment


                    #10
                    Updated number of bars

                    Thanks JC/Patrick,

                    I took care of the minimum # of bars as suggested by Patrick. My indicator still does not do what it is supposed to do though.

                    Regards,

                    Sandesh Rai

                    Comment


                      #11
                      Hello Sandesh Rai,

                      Could you clarify what your indicator is doing, and what you expect your indicator to do?
                      JCNinjaTrader Customer Service

                      Comment


                        #12
                        Hello JC/Patrick,

                        The indicator is supposed to shade the background different colors depending on the favorability for long trading or short trading. I have attached the entire code with my second post below. Here is an example of the logic:

                        if(
                        indSMAFast[
                        0] > indSMAFast[5]
                        && indSMAMedium[
                        0] > indSMAMedium[20]
                        && Close[
                        0] > indSMAVSlow[0]
                        && Close[
                        0] > indSMAFast[0]

                        )

                        {
                        Print(Time[
                        0] + " Background should be LawnGreen.");
                        BackColor = Color.LawnGreen;
                        }

                        if(
                        indSMAFast[
                        0] > indSMAFast[5]
                        && indSMAMedium[
                        0] > indSMAMedium[20]
                        && Close[
                        0] < indSMAVSlow[0]
                        && Close[
                        0] > indSMAFast[0]

                        )

                        {
                        Print(Time[
                        0] + " Background should be LightCyan.");
                        BackColor = Color.LightCyan;
                        }

                        Comment


                          #13
                          Hello sandeshrai,

                          Thank you for your response.

                          Can you send me the updated code since you added the check to ensure you have enough bars on the chart?

                          Comment


                            #14
                            Updated code attached

                            Please find attached updated code
                            Attached Files

                            Comment


                              #15
                              Hello sandeshrai,

                              Thank you for your response.

                              I will need to review your code not the strategy protected. If you do not want to provide all of your code please just provide the beginning of the OnBarUpdate() method and how you are ensuring you have enough bars on your chart before accessing the values.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              11 responses
                              39 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by FrazMann, Today, 11:21 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post FrazMann  
                              Started by geddyisodin, Yesterday, 05:20 AM
                              8 responses
                              52 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by DayTradingDEMON, Today, 09:28 AM
                              4 responses
                              26 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by George21, Today, 10:07 AM
                              1 response
                              22 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Working...
                              X