What is the purpose of the EL "Recalculate" function?

Questions about MultiCharts and user contributed studies.
NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

What is the purpose of the EL "Recalculate" function?

Postby NW27 » 22 Mar 2012

Hi,
I want to start at bar 1 and go through to the last bar using a variable of MA=10 then I want to increment MA ie MA=MA+1 and then loop through again.

I have tried

Code: Select all

Vars:MA(0);
Once MA = 10;

// Some code in here

FileAppend("C:\Temp\Test_"+NumtoStr(MA,0)+".TXT",NumtoStr(MA,0)+" " + FormatDate("dd/MM/yy",ELDateToDateTime(date)) +" "+NumtoStr(NetProfit,2)+NewLine);


If Date>=EndDate then
begin
FileAppend("C:\Temp\test"+NumtoStr(MA,0)+".txt",DatetoString(Date)+"End");
MA = MA + 1 ;
print("Loop =",MA);
recalculate;
end;
But this doesn't work :(
It would appear that recalculate forces MA back to 10.
Not using "Once" but using Vars:MA(10) doesn't work either.

Ideas?

Neil.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: What is the purpose of the EL "Recalculate" function?

Postby Henry MultiСharts » 22 Mar 2012

Hello Neil,

"Recalculate" function is equal to changing the study status (On - Off - On) on the chart.
When script is recalculated - the values of the variables are changed to the default ones.
You can save the value of the variable with the help of the new keyword RecalcPersist

NW27
Posts: 177
Joined: 25 Dec 2010
Has thanked: 40 times
Been thanked: 85 times

Re: What is the purpose of the EL "Recalculate" function?

Postby NW27 » 22 Mar 2012

Thanks Henry,

That fixed it and I like the link back to the Wiki as well.
I could not find the Recalculate in the Wiki/Help.

Neil.

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 23 Mar 2012

Interesting new command. I need to do a scan of the Wiki for new and interesting stuff.

I wonder if it would help with the hidden recalculate that occurs in studies (not indicators I gather) that occurs if one exceeds the maxbarsback with a loop or search. See link for the solution I came up with to be notified of it.
viewtopic.php?f=5&t=7362

I could not find the Recalculate in the Wiki/Help.
I also did not find it. I use this command extensively. I am curious why it is not supported and talked about (especially now that there is a RecalcPersist command).

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: What is the purpose of the EL "Recalculate" function?

Postby SUPER » 23 Mar 2012

Hello Neil,

"Recalculate" function is equal to changing the study status (On - Off - On) on the chart.
When script is recalculated - the values of the variables are changed to the default ones.
You can save the value of the variable with the help of the new keyword RecalcPersist
Henry,

Please can you demonstrate with an simple example how to use "RecalPersist" in a script.

Thanks
Super

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 23 Mar 2012

I am going to take a guess.

I use recalculate a lot. I use it in the lastbaronchart section. You trigger it with a GV setting (for example if the GV is value "R" you would execute the recalculate command). It causes the study to restart from currentbar=1 again and all normal variables to reset (all your plots etc will be re-done for all bars right back until the lastbaronchart code is reached). In the currentbar=1 section you have to reset the GV back to value "N" or you will get an infinite loop of restarting your study over and over again. So to test this command what I would do is this.

Code: Select all


Variable: CurrentBarEqual1CountNormal(0);
Variable: RecalcPersist CurrentBarEqual1CountPersist(0);

If currentBar=1 then
begin
CurrentBarEqual1CountNormal = CurrentBarEqual1CountNormal + 1;
CurrentBarEqual1CountPersist = CurrentBarEqual1CountPersist + 1;
{Write out the two counts using fileappend}
end
In the fileappend report, the normal variable should always be 1 and the variable with RecalcPersist should properly increase to show the count of each execution of currentbar=1. You can't use the print statement because it will be cleared on each restart of the study. The fileappend report will have a new line added on each restart.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: What is the purpose of the EL "Recalculate" function?

Postby janus » 03 May 2012

I use recalculate a lot. I use it in the lastbaronchart section.
As do I. I've been using IntraBarPesist for my variables that I want to keep updated on each tick. So what's the difference between using IntraBarPesist and RecalcPersist in a study using RecalcLastBarAfter? Does it mean IntraBarPesist variables are not updated to the last known value if the study run is not due to an update tick but by a RecalcLastBarAfter? Doesn't make sense if that's the case. More like the two keywords are the same. I hope so otherwise I will have to update a lot of my scripts when I transfer to MC version 8.0.

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 03 May 2012

Hi Janus,

You probably have seen this post with all sorts of test runs explaining intrabarpersist.
viewtopic.php?f=5&t=6871&hilit=understa ... barpersist
So you probably know this next statement in quotes.
In short it forces a write to the underlying maxbarsback tables on every tick rather than waiting to barstatus=2. Without it before barstatus=2 the values you update in the variable get set back to the previous bars value on each new tick.
I have not tested this because my studies are (for the most part) done. However I think I can give it very high odds that this quote is correct.
the fake tick command (as I call it) probably works the same as a regular tick and has the same effect as the above quote says (in other words intrabarpersist still works the same way). I say this because all my studies still work and I use the fake tick command in all of them (I have a mixture of intrabarpersist and not). However the recalculate command completely restarts the study and all variables will be reinit to their init values in the variables section regardless of the use of intrabarpersist or not. So RecalcPersist is meant only for use with the recalculate command to hold that variable even though the recalculate command has occurred (hold the variable at the value it had just before the recalculate command). I have a number of studies that use GVs to serve this function so that the variables are set at the start of the day and even if I bring MC down and back up they will be reset on each restart. Note that this is only possible because I have at least one other database up and running that is also updating GVs (or at least reading them) and this keeps the GVs in memory fully intact while MC is down. It also works obviously during a recalculate. So recalcpersist will work for a recalculate to hold the variable but not during a complete restart of MC obviously.
John

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: What is the purpose of the EL "Recalculate" function?

Postby janus » 03 May 2012

However the recalculate command completely restarts the study and all variables will be reinit to their init values in the variables section regardless of the use of intrabarpersist or not.
Wrong! A recalc does not reinitialise variables marked as IntraBarPersist. I just proved it myself with a simple test. I still don't understand the difference between RecalcPersist and IntraBarPersist.

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 03 May 2012

Interesting. I wrote a while study with GVs to detect when the hidden recalculate has occurred and it issues a popup on my database program because it detects that the hidden recalculate has reset the variable back to its initial value relative to the value held in the GV. So you are saying that your test shows that the hidden recalculate (MAY BE) different than the recalculate command. I guess I will have to inspect these studies again and see if the variables I am testing have intrabarpersist or not.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: What is the purpose of the EL "Recalculate" function?

Postby janus » 03 May 2012

I'm not sure what you mean by "hidden recalculate is different than the recalculate command". All I know is an IntraBarPersist variable will retain its value on the next run of the study regardless of whether the run was triggered by a real update tick or by RecalcLastBarAfter. The question I like answered is what's different about a RecalcPersist variable?

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 03 May 2012

Yes it would be good to know.

After the test you just did I guess my studies only work with the recalculate command because I always force things to the values I want when the currentbar=1 code is executed (old habit). I prefer to avoid using the variables statement to do the initializing. When it comes to GVs every single one is initialized before MC even starts. All my 1,000s of GVs have a database entry with the string name and I loop them to set them. It is also handy for debugging and getting the value (each line in the database has a get value button and set value can be done as well.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: What is the purpose of the EL "Recalculate" function?

Postby janus » 03 May 2012

I know what you mean. I've been doing something very similar for some time now, except I've been using a DLL to store my variables that I want to keep, which includes string types. I also use GVs in some cases to share small amounts of data between studies. This is one of a few reasons why I hate the PL/EL environment for complex coding. The new .NET release looks very promising as it will free me from a lot of garbage that surrounds the PL world. Finally we can use a real language of choice to program complex trading rules. It's something that has almost forced me to dump MC and move to a more appropriate trading solution, of which there a few. Now it appears I won't have to as I like the MC charting front end look and feel.

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 03 May 2012

Yes .NET sounds interesting. I am not sure I want to go through much learning curve these days (hoping to get a life back :-) but I would be interested in doing a quick scan of the features it provides to see if I want to dig in.

Anyway, getting back to the question you have, does the Wiki not have any subtle differences in the description between the two commands that gives the answer?

I will be back in about 1.5 hours.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: What is the purpose of the EL "Recalculate" function?

Postby janus » 03 May 2012

Yes .NET sounds interesting. I am not sure I want to go through much learning curve these days (hoping to get a life back :-) but I would be interested in doing a quick scan of the features it provides to see if I want to dig in.
We must be of the same age as I have the same feeling.
Anyway, getting back to the question you have, does the Wiki not have any subtle differences in the description between the two commands that gives the answer?.
Had a look and it's not clear there is any difference. I wonder if the new command was introduced as an alias to avoid confusion for those who do not turn on IOG but use RecalcLastBarAfter in their studies and want the feature of an IntraBarPersist variable. It's a shame we have to waste time second guessing all this when the documentation should have been clearer and more informative in the first place.

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 03 May 2012

Hi Janus,

After reading the Wiki on RecalcPersist I decided to create my test. I did it on the Notebook. When I get back to the main machine I will try it (assuming I can compile that keyword on version 7.4 of MC. Notice I had to comment it out for now to test the compile). Is this basically the same as your test? I will run the study, set the GV to recalculate it to a value "R" then check the file append and see what all 3 variables contain during each exeucte of the currentbar=1 code.

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");
end;


if LastBarOnChart then
begin
if GV_GetNamedString("RecalcPersistTest","N") = "R" then
begin
MyVarNormal = "BeforeRecalculate";
MyVarIntraBarPersist = "BeforeRecalculate";
MyVarRecalcPersist = "BeforeRecalculate";
recalculate();
end;
end;
Last edited by bowlesj3 on 03 May 2012, edited 1 time in total.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: What is the purpose of the EL "Recalculate" function?

Postby janus » 03 May 2012

We must be talking about two different things. I wasn't aware of a the recalculate command. I was talking about the RecalcLastBarAfter command as used below. The study recalcs every two seconds, or sonner if there's an update tick. The variable printed shows it's incremented by one regardless and stored that way.

Code: Select all

variables:
intrabarpersist n(2);

if LastBarOnChart_s then begin
n = n + 1;
print (barstatus," ",n);
end;
RecalcLastBarAfter(2);
As for GVs, I do it differently to you. I simple used GVSetNamedDouble(varname,0), value1 = GVGetNamedDouble(varname,value2), etc. I don't bother with the DefineDLLFunc directives; although I do use DefineDLLFunc for my own DLLs of course.
This is getting off the topic though. Still the question remains. Is there any difference between IntraBarPersist and RecalcPersist? Now I see there could be after seeing your code. I couldn't find any reference to "recalcualte" on the Wiki site yet it's a valid command when I type it in the PLEditor. Not sure if I have a use for it. I'm actually trying to get away from such "restarts" of a study. I prefer the traditional approach of running a program from start to end once only, and reference past data with dynamic arrays rather than the bar number method. That's why I like the idea of moving to the .NET approach. Array based programming is so much easier.
Last edited by janus on 03 May 2012, edited 3 times in total.

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 03 May 2012

Yes, my GV definitions come from the fact that I had to do this with TS4.0 and I did a bunch of them before I realized there was a wrapper function in MC (I just kept up the habit). I have been meaning to switch it over to the wrappers when ever I get around to doing a mass cleanup (someday). Right now putting in speedups to my code and work is much higher priority.

I think I may have given you the answer as to the difference. I will be running my test above in about 30 minutes (again if I can get it to compile - if not I may risk an upgrade to MC 8.0 beta 3 before Friday when I planned to do that.

The recalculate is a great command. I use it in about 8 studies. For example John Bollinger correctly states the Bollinger Bands should be adjusted. Using the MC inputs is far too slow for this. To make it faster I wrote a database program with a row for each chart and all the BB input settings (parameters) on each row. When ever I change a setting in the database a GV is set and this triggers the recalculate which causes the BBs to be redrawn with the new parameters. That was my first use for the command once I discovered it. Like I said, I have found at least a few other uses. I thought I could automate this adjustment to the BBs but I tried it and it sent MC a bit haywire (so much for fully automating a trading system - not for me I am afraid).
Last edited by bowlesj3 on 03 May 2012, edited 2 times in total.

janus
Posts: 835
Joined: 25 May 2009
Has thanked: 63 times
Been thanked: 104 times

Re: What is the purpose of the EL "Recalculate" function?

Postby janus » 03 May 2012

When ever I change a setting in the database a GV is set and this triggers the recalculate which causes the BBs to be redrawn with the new parameters. That was my first use for the command once I discovered it. Like I said, I have found at least a few other uses.
I see now how it has some uses. Can't think of one for my own work as I developed my own dynamic indicators that plot using trendline drawing in my signal studies. No need to recalulate as it would slow things down and stop auto trading.

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 03 May 2012

Yes to auto trade the the band bounces (all of them that is) one would need to find the band bounces (which often occur after the bands are adjusted) (and certainly no easy task for programming). It takes time to discover them however. I traded for 6 years before I even became aware of these bounces. Once they are found they often give you perfect entry points. However I prefer to use a form of confirmation. If anyone has figured out how to auto trade and adjust the bands during this process (automatically) I certainly would love to talk to this highly intelligent person. On band bounces, one day I just could not figure out the market. Later that day I found that the market all day had been bouncing off the upper 1 minute bars band with no more than a 4 unit push (E-Mini that is). However on this day there was no adjustment. So if one discovered that bounce one could have made 31 trades during the day with absolutely zero losses. Sadly I can not say I am that good. Finding them after the fact is one thing. Anticipating them and having the guts is another. Not hard to understand since this does not always happen. i have only seen this form of trend line twice. For sure, "trend line" does not always mean a straight line. No doubt, 31 bounces in a row is pretty significant (and another day of something very similar). I have seen 8 bounces of an adjusted 30 minute bars band (and about 1 unit push max). Trend line trading is an interesting strategy but not easy to program since one never really knows where the trend line will be (I often wonder if the market makers may have something to do with this doable but challenging task). I will never give up on trying to find the trend line but I have given up on any idea of trying to auto program it. One has to get realistic here. I suspect no one has been able to pull it off (but if one has I would love to talk to them about it). However for those who know where to look for the many places that trend lines can be found and can find the trend lines quickly with the eye they can make a lot of money. Still working on that big money part :-)
Last edited by bowlesj3 on 03 May 2012, edited 1 time in total.

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 03 May 2012

My compile of the test script I wrote above failed on the main machine. I am running MC 7.4. I have decided to not upgrade until Friday night and I will test it then. Maybe you will want to test it Janus. Others may want to see the output. I will remove the comments on the command.
We must be talking about two different things. I wasn't aware of a the recalculate command.
Yes, I guess I had a bit of an advantage having used the recalculate command since roughly after 4 months of buying MC when I found it in a list of unsupported reserve words. It allowed me to know exactly what the subject line question was all about. I will post the results of the test Friday night if the MC 8.0 beta3 upgrade can be kept. I am very curious if my suspicions about the "RecalcPersist" key word are indeed correct. The thanks from Henry for my post #6 would seem to lend odds to the theory being correct. If it is correct (related to the recalculate function) then I have to ask myself why they do not support the recalculate nor have it in the Wiki yet. Maybe that will be my first Wiki entry.

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

Re: What is the purpose of the EL "Recalculate" function?

Postby bowlesj3 » 06 May 2012

I forgot to use the test script above to test the RecalcPersist while I had MC 8.0 Beta 3 installed and before I rolled back to 7.4. Oh Well. Curiosity must wait. Maybe on MC 8.0 Beta 4.


Return to “MultiCharts”