Converting 1 minute bar scripts to 1 second bar scripts

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Converting 1 minute bar scripts to 1 second bar scripts

Postby bowlesj3 » 31 Jul 2021

Hi,

regarding the subject, if I had the list of items below I could have saved myself a whole day working almost none stop trying to find a bug in one of my very complex 1 second bar chart scripts I had created from the exact same script running in the other charts I used (1 week, 1 day, 30 minute, 15 minute, 5 minute, 1 minute). There have been other times this list could have saved annoyance and debugging work as well.
Change LastBarOnChart to LastBarOnChart_s.

Change DateTime2ELTime(MouseClickDateTime) to DateTime2ELTime_s(MouseClickDateTime). Note: DateTime2ELTime is in the Help but DateTime2ELTime_s is not.

Change the built in function "TimeToMinutes" to "TimeToSeconds".
Change the built in function "MinutesToTime" to "SecondsToTime_s". Note: There is a built in function called "SecondsToTime" but it will truncate the seconds so do not use it.

Change time to time_s
Note:
If all the variables that get the value of Time_s are named such that they end with the word Time (example FutureTime) then change these to end with Time_s (example FutureTime_s). The reasons to do this is because it makes it easier to get all the associated commands mentioned below changed for both Time_s and FutureTime_s. Specifically you do one string search at the end for Time_s and you will find all the associated commands mentioned below.

Where ever the time command needs to be replace with the time_s command the associated command (Text_New, TL_new, etc) needs to be replaced with the _s version as well.
Where ever the value of time_s was moved to a work field you also need to change the associated commands (Text_New, TL_new, etc).
I think this covers it. If you have any other items please let us know.

Regards,
John
Last edited by bowlesj3 on 17 Aug 2021, edited 2 times in total.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Converting 1 minute bar scripts to 1 second bar scripts

Postby bowlesj3 » 31 Jul 2021

Note that I have two simpler scripts that can run in both 1 minute bars and 1 second bars by testing the BarType variable that I set in a switch statement shown below that is inside the CurrentBar = 1 code.

Code: Select all

if CurrentBar = 1 then begin switch bartype_ex begin { NumericSimple bartype_ex [of Data(*)] - returns MC adaptable symbol resolution info: Tick = 1, // Tick Volume = 8, Second = 9, Minute = 2, Hour = 3, Day = 4, Week = 5, Month = 6, Year = 7, Quarter = 10, Points = 11, Change = 12, OrigPoints = 13, } case 1: {tick bars} BarType = "T"; case 2: {minute bars} BarType = "M"; case 4: {daily bars} BarType = "D"; case 5: {weekly bars} BarType = "W"; case 9: {second bars} BarType = "S"; Default: raiseruntimeerror("A_MY_StepScanner_Set_GV has invalid bartype_ex. Aborting."); end; {switch MySide} End; //if CurrentBar = 1 then

User avatar
TJ
Posts: 7739
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1032 times
Been thanked: 2221 times

Re: Converting 1 minute bar scripts to 1 second bar scripts

Postby TJ » 31 Jul 2021

Code: Select all

if CurrentBar = 1 then begin
You can also use the keyword ONCE.
It might save some processing cycles.

Because MultiCharts will re-evaluate the IF statement at every new tick to see if it meets the criteria.
While the ONCE statement is only evaluated once when you load the indicator into the chart. That section of the code will not be invoked again during the day.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Converting 1 minute bar scripts to 1 second bar scripts

Postby bowlesj3 » 17 Aug 2021

For anyone who may have (prior to 2021/August/17) copied the code from the first post of this thread you should copy it again since I made two significant updates on 2021/August/17.


Return to “User Contributed Studies and Indicator Library”