Easiest way to count bars from X to Current Time? -
1 2

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

  1. #11
    quote Thank you. That is actually closer to what I had been attempting to accomplish. For your DH and DL it's exactly what I was attempting to do however, it made the rest of the lines harder. I included a couple of lines of code into what you did. You may see what I had been hoping to do with the code, I had been attempting to add concurrent lines at one third above the DL and one third under the DH, one third is random, it could be half or even a quarter or all. Concurrent and accurate is your secret. I managed to get it to draw some lines at what I thought were at only one third...
    You're attempting to compute the third with the indices of the high and low, not the value of the high and low.
    Inserted Code #property stringent #property indior_chart_window #property indior_buffers 4 dual dayHigh#91;#93;, dayLow#91;#93;, upper3#91;#93;, lower3#91;#93;; int OnInit() SetIndexBuffer(0,dayHigh); SetIndexBuffer(1,dayLow); SetIndexBuffer(2,upper3); SetIndexBuffer(3,lower3); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID); SetIndexStyle(2,DRAW_LINE,STYLE_DASH); SetIndexStyle(3,DRAW_LINE,STYLE_DASH); return(INIT_SUCCEEDED); int OnCalculate(const int rates_total, const int prev_calculated, const datetime time#91;#93;, const double open#91;#93;, const double top #91;#93;, const double non #91;#93;, const double close#91;#93;, const long tick_volume#91;#93;, const long volume#91;#93;, const int spread#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 shift = 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; = Low#91;indexLow#93;; dual range = (dayHigh#91;I#93;-dayLow#91;I#93;-RRB-/3; upper3#91;I#93; = dayHigh#91;I#93;-range; lower3#91;I#93; = dayLow#

  2. #12
    Junior Member phexom's Avatar
    28
    quote You are attempting to compute the third with the indices of the high and low, not the value of the low and high
    Thank you for that. I'd used the code below before you finished posting the new example. Got it to work with...

    Inserted Code dayU3#91;I#93; = dayHigh#91;I#93;--LRB-(dayHigh#91;I#93;-dayLow#91;I#93;-RRB-/3); dayL3#91;I#93; = dayLow#91;I#93; ((dayHigh#91;I#93;-dayLow#91;I#93;-RRB-/3);

  3. #13
    quote Thanks for that. I'd used the code below before you completed submitting the new case. Got it to use... dayU3[I] = dayHigh[I]-((dayHigh[I]-dayLow[I])/3); dayL3[I] = dayLow[I] ((dayHigh[I]-dayLow[I])/3);

  4. #14
    Junior Member phexom's Avatar
    28
    I have been attempting to include 3 more lines to the visuals and just have had minor success.

    #1. OK - I have included:

    dayOpen[I] = Open[change ];

    It works as planned with concurrent lines during each session revealing the session's receptive.

    #2. NOT OK - I'm also attempting to include yesterday's close to this mix drawn today, and each previous day's close drawn the day after too.

    #3. If I could get #2 added, then I can even add ((yesterday's close today's open) / 2) as the next extra line.


    #2 and #3 are much more challenging than I'd have believed. I am able to get yesterday's close line to look today but I can not get it to change appropriately, so the problem I assume is at the index setup.

    DayPrevClose[I] = Close[shift 1]; does not operate as planned and dayPrevClose[I] = Close[change ] pulls the close of the 1st bar of this day.

    How can I accomplish this in order that the previous day's close is drawn across today's intraday data and shifted appropriately?

  5. #15
    I have been attempting to add 3 more lines to the visuals and only have had minor success. #1. OK - I have included: dayOpen = Open[shift]; It functions as planned with concurrent lines throughout every session showing the session's open. #2. NOT OK - I'm also attempting to add yesterday's near this mixture drawn today, and every preceding day's close attracted the day after as well. #3. If I could get #2 additional, then I can even add ((yesterday's close today's open) / 2) as the next extra line. #2 and #3 are considerably more challenging than I would have believed. I can get yesterday's...
    I envision you are having an array out of range error message on your Experts log (if change is currently the oldest bar in the chart, you can not add it)
    Inserted Code #property stringent #property indior_chart_window #property indior_buffers 7 double dayHighNumber 91;#93;, dayLowNumber 91;#93;, upper3#91;#93;, lower3#91;#93;, dayOpen#91;#93;, prevClose#91;#93;, closeopen2#91;#93;; int OnInit() SetIndexBuffer(0,dayHigh); SetIndexBuffer(1,dayLow); SetIndexBuffer(2,upper3); SetIndexBuffer(3,lower3); SetIndexBuffer(4,dayOpen); SetIndexBuffer(5,prevClose); SetIndexBuffer(6,closeopen2); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID); SetIndexStyle(two,DRAW_LINE,STYLE_DASH); SetIndexStyle(3,DRAW_LINE,STYLE_DASH); SetIndexStyle(4,DRAW_LINE,STYLE_SOLID); SetIndexStyle(5,DRAW_LINE,STYLE_SOLID); SetIndexStyle(6,DRAW_LINE,STYLE_DOT); yield (INIT_SUCCEEDED); int OnCalculate(const int rates_total, const int prev_calculated, const datetime time#91;#93;, const double open#91;#93;, const double high#91;#93;, const double non #91;#93;, const double close#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;= High#91;indexHigh#93;; dayLow#91;I#93; = Low#91;indexLow#93;; double range = (dayHigh#91;I#93;-dayLow#91;I#93;-RRB-

  6. #16
    Junior Member phexom's Avatar
    28
    quote I imagine you're receiving an array out of range error message on your Pros log (if shift is currently the oldest bar in the chart, you can not add it) shift ; if(shiftgt;=rates_total) continue; prevClose[I] = Open[shift]; closeopen2[I]= (dayOpen[I] prevClose[I])/2; } return(rates_total); }
    Would have never figured out the additional shift . Thank you.
    You are very very good at coding. I've seen lots of yours is tight and effective and incredibly logical.

    I did one little alteration...

    prevClose[I] = Open[shift]; changed to
    prevClose[I] = Close[shift];

    appears to work flawlessly.

  7. #17
    {quote{} Would|}'d} have never figured out the additional shift . Thank you. You're very very good in coding. I have seen lots of code, yours is tight and effective and incredibly logical. I did one little modifiion... prevClose[I] = Open[shift]; changed to prevClose[I] = Close[shift]; appears to function flawlessly.
    Good spot on the Open / Close ... it must have been too early in the morning to begin programming

    I am glad you've got it working

  8. #18
    iBarShift(...)

  •