//
// Function imports
// You require to import only functions you use
// 
external: "permvar.dll", int, "PVInit",LPSTR;   
external: "permvar.dll", int, "PVError";  
external: "permvar.dll", int, "PVString",int,LPSTR,LPSTR;
external: "permvar.dll", int, "PVValue",int,LPSTR,int;  
external: "permvar.dll", int, "PVDouble",int,LPSTR,double;
external: "permvar.dll", int, "PVWipe",LPSTR;
external: "permvar.dll", LPSTR, "PVGetString",int,LPSTR;
external: "permvar.dll", int, "PVGetValue",int,LPSTR;
external: "permvar.dll", double, "PVGetDouble",int,LPSTR;
external: "permvar.dll", int, "PVRelease";
external: "permvar.dll", int, "UnixTime";
external: "permvar.dll", LPSTR, "PVVersion";


 
// Variable declarations
Vars: hnd(0),LastStart(0),DeltaTime(0),intrabarpersist myHH(0),intrabarpersist 
myLL(999999);

// Here we go at start of study
if BarNumber=1 then 
begin   
  hnd=PVInit("permtest");
  if (hnd>0) then
  begin
    // Load previous start and calculate elapsed duration of absence in seconds
    LastStart=PVGetValue(hnd,"StartDateTime");
    if (LastStart>0) then
      begin
        DeltaTime=UnixTime() - LastStart;
        Print("Hello Developer, you have been absence ",DeltaTime:0," seconds. 
        Nice to see you 
again. You are using version ",PVVersion()," of PermVar");
      end   
      else   
      begin 
        Print("This is your first start. Welcome. Next time you start i ll count 
        your absence.");
      end;  
    // Store Date and Time of current start
    PVValue (hnd,"StartDateTime",UnixTime());
    if (PVError()<>0) then begin Print ("Error by storing variable"); end;
  end;
end;


// Lets remember HighestHigh and LowestLow from this Symbol
if High > myHH then myHH = High;
if Low < myLL then myLL = Low;

If LastBarOnChart then 
begin
  // Function PVRelease is to release storage buffer after using PVGetString
  // If you dont use PVGetString, this call is not required
  if hnd>0 then PVRelease(); 

  // Store myHH and myLL with using current symbol
  // if you have EURUSD loaded then Key gets "EURUSD-HH" and "EURUSD-LL"
  // You can read these values from other studies with PVGetDouble() function
  if hnd>0 then   begin
      PVDouble(hnd,(GetSymbolName+"-HH"),myHH);
      PVDouble(hnd,(GetSymbolName+"-LL"),myLL);
      end;
end;