Page 1 of 502 1 2 LastLast
Results 1 to 10 of 18

Thread: Easiest way to count bars from X to Current Time?

  1. #1

    Easiest way to count bars from X to Current Time?

    What is the easiest way to count bars from the start of the afternoon 00:00:01 till the current pub?

    I want to chart the live daily high low HHLL since it occurs and have the data stay in a buffer so that I can see the historical intra day motion, PERIOD_D1 merely allows the current day's price action, and using a 1mn chart and using 1440 comprises yesterday's data.

  2. #2
    Quote Originally Posted by ;
    iBarShift(...)
    Thanks for that.

    How is possible to define datetime as 00:00:00 automatically so that iBarShift could count in the current bar to the first 1 minute bar of each day?

    Without using iBarShift what I have is this but it is still counting bars into the last trading session.

    When I will count the precise number of bars back to 00:00:00 of each day's session, then the factor MinutesBack below may be the count of this shift exactly back to the start of 00:00:00 of each day just.

    Inserted Code int MinutesInHours = (Hour() - 0)*60; int Minutes = Minute() - 0; int MinutesBack = MinutesInHours Minutes; DH = High#91;iHighest(NULL,PERIOD_M1,MODE_HIGH,MinutesB ack,I)Number 93;; DL = Low#91;iLowest(NULL,PERIOD_M1,MODE_LOW,MinutesBack ,I)#93;;

  3. #3
    To find the Change of the first bar of the day
    Inserted Code int midnight_shift=iBarShift(Symbol(),0,TimeCurrent()-(TimeCurrent()%(PERIOD_D1*60)),true); if(midnight_shift==-1) midnight_shift=iBarShift(Symbol(),0,TimeCurrent()-(TimeCurrent()%(PERIOD_D1*60)),false)-1;

  4. #4
    Inserted Code iBarShift(_Symbol,0,iTime(_Symbol,PERIOD_D1,0))
    ... is the one thing you need to loe the number of candles since the day start.

  5. #5
    Quote Originally Posted by ;
    iBarShift(_Symbol,0,iTime(_Symbol,PERIOD_D1,0))... is the one thing you want to loe the amount of candles as the day begin.
    That is ideal and efficient. Thank you.

  6. #6
    Quote Originally Posted by ;
    quote That is perfect and productive. Thank you.
    Great!

  7. #7
    Quote Originally Posted by ;
    quote That's perfect and productive. Thank you.
    Just a simple hint: remember that pubs are numbered from 0.
    If iBarShift returns 12, there are actually 13 pubs.

  8. #8
    Quote Originally Posted by ;
    quote Just a simple tip: remember that bars are numbered from 0. If iBarShift yields 12, there are really 13 bars.
    Example:

    1st 1min bar of day is 00:00

    now is 15:28

    Shift = iBarShift(NULL,0,iTime(NULL,PERIOD_D1,0))

    shift = 928 ferrufx
    or my formulation (15Hour*60 28min) = 928

    DH = High[iHighest(NULL,PERIOD_M5,MODE_HIGH,Shift,I)] = High because 00:00 or High because 1st bar of this afternoon


    that I believe I have the right formula here otherwise from what you've said, we're calculating from 15:28 back to the 2nd bar of this day.

  9. #9
    Try this out, see Whether the visuals help:
    Inserted Code #property strict #property indior_chart_window #property indior_buffers 2 Dual dayHigh#91;#93;, dayLow#91;#93;; int OnInit() SetIndexBuffer(0,dayHigh); SetIndexBuffer(1,dayLow); SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); return(INIT_SUCCEEDED); int OnCalculate(const int rates_total, const int prev_calculated, const datetime Period #91;#93;, const double Available #91;#93;, const double Top #91;#93;, const double low#91;#93;, const double Shut #91;#93;, const long tick_volume#91;#93;, const long volume#91;#93;, const int Disperse #91;#93;-RRB- for(int I=rates_total-fmax(prev_calculated,1); igt;=0; I--) datetime midnight = Time#91;I#93;-(Time#91;I#93;?400); int Change = iBarShift(NULL,0,midnight), cnt = shift-i 1, indexHigh = iHighest(NULL,0,MODE_HIGH,cnt,I), indexLow = iLowest (NULL,0,MODE_LOW,cnt,I); dayHighNumber 91;I#93;=Large #91;indexHigh#93;; dayLow#91;I#93; =Reduced #91;indexLow#93;; return(rates_total);

  10. #10
    Quote Originally Posted by ;
    Try this out, see whether the visuals help
    Thank you. That's actually closer to what I had been attempting to accomplish. For the DH and DL it is exactly what I was attempting to do nevertheless, it made the rest of the lines harder. I added a couple of lines of code into everything you did. You may see what I had been trying to do by the code, I had been attempting to include concurrent lines in one third above the DL and one third below the DH, one third is arbitrary, it might be half or even a quarter or all. Concurrent and accurate is the secret. I was able to get it to draw some lines in exactly what I believed were in one third intervals but my maths or logic is way off. I added the code and the additional buffers below. What could I do wrong here?

    Inserted Code for(int I=rates_total-fmax(prev_calculated,1); igt;=0; I--) datetime midnight = Time#91;I#93;-(Time#91;I#93;?400); int change = iBarShift(NULL,0,midnight), cnt = shift-i 1, indexHigh = iHighest(NULL,0,MODE_HIGH,cnt,I), indexLow = iLowest (NULL,0,MODE_LOW,cnt,I), indexU3 = indexHigh-((indexHigh-indexLow)/3), indexL3 = indexLow ((indexHigh-indexLow)/3); dayHighNumber 91;I#93;=High#91;indexHigh#93;; dayLow#91;I#93; =Low#91;indexLow#93;; dayU3#91;I#93; =Closing #91;indexU3#93;; dayL3#91;I#93; =Closing #91;indexL3#93;;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners. Read more.