================================================
For someone new to MC, give this a try on your MC by creating a new study with the simple code below and putting it in your 1 minute bars (copy it in or use the attached zip of the pla file) . Here is what it does in my MC.
On the last bar on the chart with the code running on every tick, it sets testcnt to value 1, but if still on the same minute when it executes that same code on the next tick it resets testcnt back to 0. It continues to do this until that minute is finished. The print statements clearly show this. Finally when that minute is finished it leaves the value as 1 and tries to add to it again but on the second minute it sets it back to 1 with each new tick. This continues until it gets to the third minute then it holds its value at 2 and will then bring it up to the value 3 but keeps resetting it back to value 2 on each new tick during that minute.
Question? Without having to use GVs to get around this by storing the value and bring it back in on the next tick (which I have done in the past and have in a lot of my EL code) Is there a way around this so you can for example count the number of ticks that have come through in a minute?
It is very confusing for someone new to MC and probably even more confusing to a person new to MC but not new to programming. I had to sit down and figure out what is going on because it has been a while since I have created a new study and I had forgotten that MC does this. I remember now that I had worked around it by storing the values in a GV then bringing them back in on the next tick to get the value for the next addition.
Thanks,
John
Notes for trying it:
1/ It is also zipped as an attach so you can see the proper indenting.
2/ each print statement has a different marker "Here1 & here2", Here3 and Here4, Here5 and Here6. They are grouped in pairs based upon the if statements.
3/ I indented the print statements such that when you look at the print file you clearly see where a new minute is being processed.
4/ I had to create this post with the print statements going in the file C:\ALog_2.txt. My earlier attempts at this post had it going to a different directory.
Code: Select all
{A_TestCnt constantly reset back on each tick. =======================================================}
variables:
testcnt(0);
if LastBarOnChart then
begin
if testcnt = 2 then
begin
Print( File("C:\ALog_2.txt"),
" Here5", " " ,
" Time", " " ,
Time, " " ,
" TestCnt", " " ,
testcnt, " " ,
" ");
testcnt = testcnt + 1;
Print( File("C:\ALog_2.txt"),
" Here6", " " ,
" Time", " " ,
Time, " " ,
" TestCnt", " " ,
testcnt, " " ,
" ");
end;
if testcnt = 1 then
begin
Print( File("C:\ALog_2.txt"),
" Here3", " " ,
" Time", " " ,
Time, " " ,
" TestCnt", " " ,
testcnt, " " ,
" ");
testcnt = testcnt + 1;
Print( File("C:\ALog_2.txt"),
" Here4", " " ,
" Time", " " ,
Time, " " ,
" TestCnt", " " ,
testcnt, " " ,
" ");
end;
if testcnt = 0 then
begin
Print( File("C:\ALog_2.txt"),
" Here1", " " ,
" Time", " " ,
Time, " " ,
" TestCnt", " " ,
testcnt, " " ,
" ");
testcnt = testcnt + 1;
Print( File("C:\ALog_2.txt"),
" Here2", " " ,
" Time", " " ,
Time, " " ,
" TestCnt", " " ,
testcnt, " " ,
" ");
end;
end;