Custom Function: "GetChartPeriodicity"

 
Custom Function: "GetChartPeriodicity"
/*[[
Name := GetChartPeriodicity
Author := Copyright © 2003, Nikolay Stoychev
]]*/

Var : v1(0), v2(0);

v1 = StrToTime(TimeToStrEx(Time[0], TIME_MINUTES));
v2 = StrToTime(TimeToStrEx(Time[1], TIME_MINUTES));

if v1 - v2 = 0 then
{//Daily, Weekly
v1 = StrToTime(TimeToStrEx(Time[0], TIME_DATE));
v2 = StrToTime(TimeToStrEx(Time[1], TIME_DATE));

if (v1-v2)/604800 >= 1 then return(604800) //Weekly
else if (v1-v2)/86400 >= 1 then return(86400) //Daily
else return (-1);
}
else
{//4h, 1h, 30M, 15M
if (v1-v2)/14400 >= 1 then return(14400) //4h
else if (v1-v2)/3600 >= 1 then return(3600) //1H
else if (v1-v2)/1800 >= 1 then return(1800) //30M
else if (v1-v2)/900 >= 1 then return(900) //15M
else return (-1);
};

________________________________________________
TEST - Custom indicator

/*[[
Name := test
Author := Copyright © 2003, Nikolay Stoychev
Link := http://www.company.com/
Separate Window := No
First Color := Blue
First Draw Type := Line
First Symbol := 217
Use Second Data := No
Second Color := Red
Second Draw Type := Line
Second Symbol := 218
]]*/
SetLoopCount(0);

Switch UserFunction("GetChartPeriodicity")
begin
case 604800: print("Periodicity: Weekly");
case 86400: print("Periodicity: Daily");
case 14400: print("Periodicity: 4H");
case 3600: print("Periodicity: 1H");
case 1800: print("Periodicity: 30M");
case 900: print("Periodicity: 15M");
end;
 
а про штатную функцию Period не знали?
 
10x
Причина обращения: