Get weekly and monthly pivots at the same time as daily pivot

 

Hello

I have an EA that much of it I learnt to code myself, but for one part I had to get a coder to write as it was a little out of my depth here is the code below, it dowloads pivots from my webserver that are provided by my broker:

bool  PivotsTromTheFile(int lev){
        static int prewTime,prewLev = -1;static double cPivots[5];
        bool found=false;
if(IsTesting()||IsOptimization() || Symbol()=="AUS200" || Symbol()=="FRA40" || Symbol()=="GER30" || Symbol()=="SPX500" || Symbol()=="UK100" || Symbol()=="XAUJPYFXF"){return(false);}
        int i,hd,err,pos,time,stime;
        string url,sym,request,fn,prom,out,ext,prefix;
        if(prewLev == lev){
                if(prewTime == StrToTime("00:00")){
                        if(cPivots[0]==pivot[0]&&
                                cPivots[1]==pivot[2]&&
                                cPivots[2]==pivot[3]&&
                                cPivots[3]==pivot[5]&&
                                cPivots[4]==pivot[6]){return(true);}
                }
                prewTime = StrToTime("00:00");
        }
        sym = Symbol();
        ext = ".csv";
        url = "http://tributetothem.com/result/";

 if(GlobalVariableCheck(daily)){prefix = "daily_";   //for daily pivots
        if(DayOfWeek()==0){
      time = iTime(sym,PERIOD_D1,1);
      }
//+------------------------------------------------------------------+      
        if(DayOfWeek()==1){
   if(TimeToStr(TimeCurrent(),TIME_MINUTES)>="21:04"){
        time = iTime(sym,PERIOD_D1,0);} 
   if(TimeToStr(TimeCurrent(),TIME_MINUTES)<"21:04"){
        time = iTime(sym,PERIOD_D1,2);} 
        }
//+------------------------------------------------------------------+      
      if(DayOfWeek()>=2){
   if(TimeToStr(TimeCurrent(),TIME_MINUTES)>="21:04"){
        time = iTime(sym,PERIOD_D1,0);}  
   if(TimeToStr(TimeCurrent(),TIME_MINUTES)<"21:04"){
        time = iTime(sym,PERIOD_D1,1);}
        }       
 }  
//+------------------------------------------------------------------+          
 if(GlobalVariableCheck(weekly)){prefix = "weekly_";     //for weekly pivots
        time = iTime(sym,PERIOD_W1,0)+(50*3600);
}
//+------------------------------------------------------------------+          
 if(GlobalVariableCheck(monthly)){prefix = "monthly_";  //for monthly pivots
      time = iTime(sym,PERIOD_MN1,0)+(2*3600);
   }    
//+------------------------------------------------------------------+   
   prefix = StringSubstr(TimeToStr(time),0,10)+"_"+prefix;
   fn = prefix + sym + ext;
   hd = FileOpen(fn,FILE_CSV|FILE_READ,"#");
   if(hd > 0){
        while(!FileIsEnding(hd)){
                prom = FileReadString(hd);
                stime= StrToInteger(StringSubstr(prom,0,10));
                if(stime == time){found = true; break;}
        }
   FileClose(hd);       
        if(found){
                for(i=0;i<8;i++){
                        pos = StringFind(prom,",",0);
                        res = StringSubstr(prom,0,pos);
                        prom = StringSubstr(prom,pos+1);
                                double fPiv = NormalizeDouble(StrToDouble(res),Digits);
                                switch(i){
                                        case 1 : pivot[0] = fPiv; break;
                                        case 2 : pivot[5] = fPiv; break;
                                        case 3 : pivot[6] = fPiv; break;
                                        case 4 : pivot[7] = fPiv; break;
                                        case 5 : pivot[2] = fPiv; break;
                                        case 6 : pivot[3] = fPiv; break;
                                        case 7 : pivot[4] = fPiv; break;//identify each pivot in the file
                                }                       
                }
                        cPivots[0]=pivot[0];
                        cPivots[1]=pivot[2];
                        cPivots[2]=pivot[3];
                        cPivots[3]=pivot[4];
                        cPivots[4]=pivot[5]; 
                        cPivots[5]=pivot[6];
                        cPivots[6]=pivot[7];            
                return(true);// check if file has already been downloaded
        }
   }
        
   pos = StringFind(sym,"FXF",0);
   if(pos>=0){sym = StringSubstr(sym,0,pos);}
   request = url + prefix + sym + time + ext;//prepare request to server
err = InetToString(request,res);//request server

        if(err == 404){
                request = url + prefix + sym + ext;
                err = InetToString(request,res);
                if(err == 404){
                        return(false);
                }  
        }   
   if(err > 0){
        return(false);
   }
   string hRes = StringSubstr(res,0,StringFind(res,"\n",0));
   string dRes = StringSubstr(res,StringFind(res,"\n",0)+1);
   for(i=0;i<7;i++){
        int hPos = StringFind(hRes,",",0);
        if(prom == "R3" || prom == "S3"){
                int dPos = StringFind(dRes,",",0);
                dRes = StringSubstr(dRes,dPos+1);
                hRes = StringSubstr(hRes,hPos+1);
                continue;
        }

        hRes = StringSubstr(hRes,hPos+1);
                dPos = StringFind(dRes,",",0);
                string  dNm  = StringSubstr(dRes,0,dPos);
                dRes = StringSubstr(dRes,dPos+1); 
                out = out + dNm + ",";
                double dPiv = NormalizeDouble(StrToDouble(dRes),Digits);                
   }
        cPivots[0]=pivot[0];
        cPivots[1]=pivot[2];
        cPivots[2]=pivot[3];
        cPivots[3]=pivot[4];
        cPivots[4]=pivot[5];
        cPivots[5]=pivot[6];
        cPivots[6]=pivot[7];
        hd = FileOpen(fn,FILE_CSV|FILE_WRITE);
        if(hd < 1){
                return(false);
        }
        FileClose(hd);     
   hd = FileOpen(fn,FILE_CSV|FILE_READ|FILE_WRITE);
   while(!FileIsEnding(hd)){
        if(StrToInteger(StringSubstr(FileReadString(hd),0,10)) == time){
                        FileClose(hd);    
                        return(true);                   
        }
   }
        FileWrite(hd,time+","+out);
        FileClose(hd);    
        return(true);
}

At the moment the code will only read/process one file at a time (ie daily pivots or weekly pivots or monthly pivots) it cant read or display all sets of pivots. I have spent a lot of time with no success on this, perhaps a fresh pair of eyes will give a good pointer?

I have tried adding extra prefixes for each set of pivots and of course extra server requests.

Thanks

Antony

 

How is it displaying the Pivots? By Comments. By Print. By Alerts. By Objects, By Indicator?

Reason: