The recalculate command restarts your study. In other words all variables are reinitialize, currentbar=1 is reprocessed and all bars continue to be processed up until LastBarOnChart. At that point the individual ticks are processed (assuming you have that option turned on). I use this command a lot. I located the command in the LastBarOnChart section and trigger it by switching on a Global Variable (GV) with setting "R". The if test detects this and issues the command. In the CurrentBar=1 section of the chart you must set this GV back to setting "N". Obviously if you forget to reset the GV your study will recalculate over and over in an infinite loop. Here is an example. This is actually a test script designed to test the RecalcPersist key word. RecalcPersist was not available until MC 8.0.
You need to set up a way to alter your "RecalcPersistTest" GV to control this test.
Note: I have coded the GV definitions without the wrapper function. The calls are the same except they appear with GV_ instead of just GV at the front. You may need to do this if you ever have to redirect the DLLs to a different directory.
Code: Select all
variables:
MyVarNormal("Init"),
IntraBarPersist MyVarIntraBarPersist("Init"),
RecalcPersist MyVarRecalcPersist("Init"),
CurrentBar1ExecCnt(0);
if CurrentBar = 1 then
Begin
DefineDLLFunc:
"C:\Program Files\TS Support\MultiCharts\GlobalVariable.dll", int, "GV_SetNamedString", lpstr, lpstr ;
DefineDLLFunc:
"C:\Program Files\TS Support\MultiCharts\GlobalVariable.dll", lpstr, "GV_GetNamedString", lpstr, lpstr;
DefineDLLFunc:
"C:\Program Files\TS Support\MultiCharts\GlobalVariable.dll", int, "GV_SetNamedInt", lpstr, int ;
DefineDLLFunc:
"C:\Program Files\TS Support\MultiCharts\GlobalVariable.dll", int, "GV_GetNamedInt", lpstr, float ;
CurrentBar1ExecCnt = GV_GetNamedInt("RecalcPersistTest",0);
CurrentBar1ExecCnt = CurrentBar1ExecCnt + 1;
value1 = GV_SetNamedInt("RecalcPersistTest",CurrentBar1ExecCnt);
FileAppend("C:\RecalcPersistTest.txt",
"CurrentBar1ExecCnt=" +
numtostr(CurrentBar1ExecCnt,0) + " " +
"MyVarNormal=" +
MyVarNormal + " " +
"MyVarRecalcPersist=" +
MyVarRecalcPersist + " " +
"MyVarIntraBarPersist=" +
MyVarIntraBarPersist + " " +
NewLine);
value1 = GV_SetNamedString("RecalcPersistTest","N"); {Prevent the infinite loop}
end;
if LastBarOnChart then
begin
if GV_GetNamedString("RecalcPersistTest","N") = "R" then
begin
MyVarNormal = "BeforeRecalculate";
MyVarIntraBarPersist = "BeforeRecalculate";
MyVarRecalcPersist = "BeforeRecalculate";
recalculate();
end;
RecalcLastBarAfter(1);
end;
** to recalculate plots with different settings such as the bollinger bands.
** to recalculate swing settings possibly.