The code below counts the number ticks received/sec
Can someone add an external parameter (in sec) so we get ticks counted for that time.
Ex:
Parameter = 30, So it will count the number of ticks for the last 30 sec and will update every sec.
Code: Select all
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Property SaveAs Script
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#property show_inputs
extern string Symbolx="";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void init(){
if(Symbolx==""){Symbolx=Symbol();}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void start(){
while(!IsStopped()){
static int SavLstSecond=0;
static int RuningVolCount=0;
static int SavLstVolCnt=0;
int CurSecond=TimeSeconds(TimeCurrent());
if(CurSecond!=SavLstSecond){
static int StartTickCount=0;
StartTickCount=GetTickCount();
RuningVolCount=0;
}
int CurVolCount=iVolume(Symbolx,PERIOD_M1,0);
if(SavLstVolCnt>CurVolCount) SavLstVolCnt=0;
if(SavLstVolCnt>0
&& GetTickCount()<StartTickCount+1000){
RuningVolCount+=(CurVolCount-SavLstVolCnt);
}
if(StartTickCount<1)
Comment(Symbolx+": Waiting For New Second To Begin...");
if(StartTickCount>0)
Comment(Symbolx+": Ticks Per Second="+RuningVolCount);
SetGlobalVariables(); static int LstFresherTme=0;
int Trigger=GlobalVariableGet("GV_SetOffAltCnt");
int Fresher=GlobalVariableGet("GV_DelaySeconds");
if(RuningVolCount>=Trigger){
if(GetTickCount()>LstFresherTme+(Fresher*1000)){
Alert(Symbolx+": Ticks Per Second == "+RuningVolCount);
LstFresherTme=GetTickCount();
} }
SavLstSecond=CurSecond;
SavLstVolCnt=CurVolCount;
Sleep(1); RefreshRates();
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void deinit(){
GlobalVariableDel("GV_SetOffAltCnt");
GlobalVariableDel("GV_DelaySeconds");
Comment("");
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void SetGlobalVariables(){
if(!GlobalVariableCheck("GV_SetOffAltCnt"))
GlobalVariableSet("GV_SetOffAltCnt",5);
if(!GlobalVariableCheck("GV_DelaySeconds"))
GlobalVariableSet("GV_DelaySeconds",30);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Cheers