Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need little help

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

    Need little help

    Hello programer masters

    Last edited by Jakub; 07-19-2024, 11:14 AM.

    #2
    Hello,

    thank you for the question.

    Error on calling 'OnBarUpdate' method for indicator 'M5b' on bar 0: Mother50back.DrawText: startBarsAgo out of valid range 0 through 0, was 1.
    This first message is letting you know that in your call to DrawText, the amount of bars ago you are requesting is not yet loaded on the chart.

    For example you call this DrawText on bar 0, and it is trying to start 5 bars ago. 5 bars have not yet been loaded so this would be looking for an index location of -5 which will never exist and causes the error.

    You will need to check for bars before executing this code, for example:

    Code:
    [B]if(CurrentBar < 10) return;[/B]
    DrawText("MyText", "Sample text", [B]10[/B], High[0], Color.Blue);
    Because in this example I am requesting the drawtext 10 bars ago, I prevent the script from processing until I have 10 bars.

    For your next question:
    Failed to get property 'AnotherChart' for indicator '': Object reference not set to an instance of an object.
    This indicates that something is not set when you are checking it, this more than likely would be related to the line of code that contains "AnotherChart". If you would like to post the section of code or whole code I could take a look and see if I can see the error on this.
    Otherwise you need to ensure the object you are checking has a value before you are checking it.

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

    Comment


      #3
      Hello,

      Thank you for the script.

      I copied what you have and placed this in the OnBarUpdate of a blank indicator and did get the error you were.

      This is related to what I had previously posted about.

      In your code you are referencing prior bars in your conditions, these prior bars will not exist when you start the script up initially. You need to check for this otherwise you get the error you are listing.

      All I have done is added the following to the top of OnBarUpdate after the brace you have in your example. I have included the // Condition set 1 so you can see exactly where in the script I am speaking of.
      Code:
      {	
       if (CurrentBar < BarsRequired) return;
      // Condition set 1
      This tells the script, if the CurrentBar is less than the BarsRequired (defaults to 20) then do not do anything.

      This will prevent the error because now on bar 20, bar 19 will exist, you are looking back 1 bar in your conditions so at least 1 bar needs to be loaded before doing your check.

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

      Comment


        #4
        Yes, It works . Thank you very much. There is one more question I would like write my self code for %. I mean if current candle close 50% below previous candle. Where can I study or find how to write this code ? I mean is there any written lines already or I have to ask programmers for complete this request ? anything

        Thank you very much
        jake

        Comment


          #5
          Originally posted by Jakub View Post
          Yes, It works . Thank you very much. There is one more question I would like write my self code for %. I mean if current candle close 50% below previous candle. Where can I study or find how to write this code ? I mean is there any written lines already or I have to ask programmers for complete this request ? anything

          Thank you very much
          jake
          Very quickly because I'm in a rrrrrrrush but is this what you're looking for?

          Code:
          double p = (Close[0] - Low[1]) / (High[1] - Low[1]) * 100;
          This should give you a positive or negative %, with the previous Low[1] = 0% and the previous High[1] = 100%.

          (Substitute Close and Open or High and Low if this is what you want.)

          Hope this helps.
          Last edited by arbuthnot; 02-01-2015, 12:08 PM.

          Comment


            #6
            Hello Jakub,

            Thank you for your post.

            You could use the following code to check the current close is less than the previous low minus half the range of the previous bar.
            Code:
            			if(Close[0] < (Low[1]-(High[1]-Low[1]/2)))
            			{
            				// Do something.
            			}

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            574 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            332 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X