Can seem to figure out whats going on here...

 

Hi

I have this code running in my EA to scan for the lowest and highest price in each session.

it runs fine on the sunday market open, then all of a sudden when 0000gmt on the monday comes, it seems to display the high and low from a week ago :( when it hits the next session open (London) it is fine the for the rest of the week, can anyone spot anything obvious? as I am fairly new to coding, all times are GMT -1

: You can see I have added conditions to try and sort the issue at the week start I think its the <7 statement.

void Hi_Lo_inTime(double&hi_lo[]){int tf =0,start,end,bar;
//----
  if(TimeHour(TimeCurrent())<21){//13:00-22:00
      start = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,0)+(4*3600)),false);//scan from 05:00
      end   = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,0)+(12*3600)),false);//at 13:00
      bar   = start-end;      
   }
   if(TimeHour(TimeCurrent())<12){//08:00-13:00
      start = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,0)),false);//scan from 00:00
      end   = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,0)+(7*3600)),false);//at 08:00
      bar   = start-end;    
   }
   if(TimeHour(TimeCurrent())<7){//22:00(day before)-08:00
      if(DayOfWeek()==1){
      start = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,2)+(12*3600)),false);//scan from 12:00
      end   = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,2)+(21*3600)),false);//
      }else{
      start = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,1)+(12*3600)),false);//scan from 12:00
 end   = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,1)+(21*3600)),false);//      
      }
      bar   = start-end;     
   }
   if(TimeHour(TimeCurrent())>=21){//after 22:00
        if(DayOfWeek()==0){
      start = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,1)+(12*3600)),false);//scan from 22:00
      end   = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,1)+(21*3600)),false);//
      }else{
      start = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,0)+(12*3600)),false);//
      end   = iBarShift(Symbol(),Period(),(iTime(Symbol(),1440,0)+(21*3600)),false);//
      }
      bar   = start-end;     
   }       
//----   
   hi_lo[0] = MathMax(
    (MathMax(iClose(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_OPEN,bar,end)),
            iOpen(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_OPEN,bar,end)))),
    (MathMax(iClose(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_CLOSE,bar,end)),
            iOpen(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_CLOSE,bar,end)))));
   hi_lo[1] = MathMin(
    (MathMin(iClose(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_OPEN,bar,end)),
            iOpen(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_OPEN,bar,end)))),
    (MathMin(iClose(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_CLOSE,bar,end)),
            iOpen(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_CLOSE,bar,end)))));

Thanks

Antony

 
tonyjms2005:

Hi

I have this code running in my EA to scan for the lowest and highest price in each session.

it runs fine on the sunday market open, then all of a sudden when 0000gmt on the monday comes, it seems to display the high and low from a week ago :( when it hits the next session open (London) it is fine the for the rest of the week, can anyone spot anything obvious? as I am fairly new to coding, all times are GMT -1

: You can see I have added conditions to try and sort the issue at the week start I think its the <7 statement.

Thanks

Antony

Anthony,

This indicator which I wrote some time ago, draws a Frame(rectangle) around each of the 4 Sessions. The left side is the Beginning of the Session, the right side the end of Session, and the Top and Bottom are High and Low for the Session(p1,p2). Look in the DrawSession function where these coordinates are computed. My broker is is NewYork and this is derived from the MarketWatch time.NewYork Session ends at Midnight Marketwatch time and is followed by Pacific Session and 2 hours later the Asian Session .. etc,etc, etc.. All Session are 9 hours long. Everything is in Arrays, so if youre new at programming this would be a good start to understand the advantage of using arrays instead of hardcoding..

Hope this helps

Guilherme

Files:
 

Hi

Thanks for the help :) that should point me in the right direction.

Thanks again

Antony

Reason: