Advertisement
retesere20

tos-bars-in-day-time-lastbar-etc

Mar 14th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. arCountInDay = yes; #input
  2. def EnableBarCountInDay = Enable_BarCountInDay and Market_Hours_USED;
  3. def Estimate_bar_numbers_in_day =if !EnableBarCountInDay then 1 else 86400 / BarFrameInSeconds;
  4.  
  5.  
  6. def Seconds_From_00__WhenDayStarts___initial =if !EnableBarCountInDay then 0 else if IsZeroFirstBar then 9999999 else
  7. if Seconds_From_00< Seconds_From_00__WhenDayStarts___initial[1] then Seconds_From_00 else Seconds_From_00__WhenDayStarts___initial[1];
  8. def Seconds_From_00__WhenDayEnds___initial = if !EnableBarCountInDay then 0 else if IsZeroFirstBar then 0 else
  9. if Seconds_From_00> Seconds_From_00__WhenDayEnds___initial[1] then Seconds_From_00 else Seconds_From_00__WhenDayEnds___initial[1];
  10.  
  11. def futured_Seconds_From_00__WhenDayStarts =if !EnableBarCountInDay then 0 else if IsZeroFirstBar then 0 else
  12. if (futured_Seconds_From_00__WhenDayStarts[1]!=0) then futured_Seconds_From_00__WhenDayStarts[1] else
  13. fold DS_indx=1 to Estimate_bar_numbers_in_day*2 with DS_start=0 while DS_start==0 do
  14. if getvalue(Day,-DS_indx+1) != getvalue(Day,-DS_indx) then getvalue(Seconds_From_00__WhenDayStarts___initial,-DS_indx+1) else 0;
  15. def futured_Seconds_From_00__WhenDayEnds = if !EnableBarCountInDay then 0 else if IsZeroFirstBar then 0 else
  16. if (futured_Seconds_From_00__WhenDayEnds[1]!=0) then futured_Seconds_From_00__WhenDayEnds[1] else
  17. fold DE_indx=1 to Estimate_bar_numbers_in_day*2 with DE_start=0 while DE_start==0 do
  18. if getvalue(Day,-DE_indx+1) != getvalue(Day,-DE_indx) then getvalue(Seconds_From_00__WhenDayEnds___initial,-DE_indx+1) else 0;
  19.  
  20. def Seconds_From_00__WhenDayStarts = if !EnableBarCountInDay then 0 else if IsZeroFirstBar then 9999999 else
  21. if !DaysPassed then futured_Seconds_From_00__WhenDayStarts else Seconds_From_00__WhenDayStarts[1];
  22. def Seconds_From_00__WhenDayEnds = if !EnableBarCountInDay then 0 else if IsZeroFirstBar then 0 else
  23. if !DaysPassed then futured_Seconds_From_00__WhenDayEnds else Seconds_From_00__WhenDayEnds[1];
  24.  
  25.  
  26. def Difference_between_START_And_END = if !EnableBarCountInDay then 0 else if !One_Day_Passed_in_Chart then 0 else
  27. (Seconds_From_00__WhenDayEnds - Seconds_From_00__WhenDayStarts)/60/60; #example: 8.4 - 8
  28. def HoursInDay___rounded = if !EnableBarCountInDay then 0 else
  29. rounddown(Difference_between_START_And_END,0);
  30. def Difference_between_rounded_and_original = if !EnableBarCountInDay then 0 else if !One_Day_Passed_in_Chart then 0 else
  31. (Difference_between_START_And_END - HoursInDay___rounded) * 100; #example: (8.4 - 8)*100 = 40 minutes
  32. def minutes_remaining = if !EnableBarCountInDay then 0 else
  33. if (Difference_between_rounded_and_original <= 60 ) then Difference_between_rounded_and_original else Difference_between_rounded_and_original-40; #because it swims from 0 to 100 minutes...
  34.  
  35. def ConvertTradingPeriodIntoMilliSeconds = if !EnableBarCountInDay then 0 else if !One_Day_Passed_in_Chart then 0 else
  36. ( minutes_remaining * 60 + HoursInDay___rounded * 60 *60) * 1000;
  37. def Bars_Amount_In_1_day = if !EnableBarCountInDay then 0 else if !One_Day_Passed_in_Chart then 0 else
  38. roundup(ConvertTradingPeriodIntoMilliSeconds / AggrPeriod , 0 );
  39.  
  40. #new interesting variables: detect the last bar:
  41. def now_Is_Last_Bar_of_day =if !EnableBarCountInDay then no else
  42. if !DaysPassed then no else Seconds_From_00__WhenDayEnds == secondsTill00;
  43. def now_Is_LastPrevious_Bar_of_day =if !EnableBarCountInDay then no else
  44. if !DaysPassed then no else Seconds_From_00__WhenDayEnds == Seconds_From_00 - BarFrameInSeconds;
  45.  
  46. ### ************************************************************* ###
  47. def use_pre_lastdaybar_detection = yes;
  48. def THIS_Is_Last_Bar_of_day = EnableBarCountInDay AND (now_Is_Last_Bar_of_day OR Last_Bar_Of_Market OR (use_pre_lastdaybar_detection and (!IsNan(close[-1]) and !IsNan(IsNewDay[-1]) and IsNewDay[-1])));
  49. def THIS_Is_LastPrevious_Bar_of_day = EnableBarCountInDay AND (now_Is_LastPrevious_Bar_of_day OR LastPrevious_Bar_Of_Market);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement