Why a "Once Begin" function is executed twice

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Why a "Once Begin" function is executed twice

Postby arjfca » 13 Aug 2014

Hello

Only an interrogation. That does not affect my work.

An indicator is applied to one chart with one instrument

At the beginning of the code I got a command to be executed once

Code: Select all

Once begin
Comma = ",";
scale = scalestring;
print(getappinfo(aispacetoright):0:0);
end;
To my surprise, the returned print is executed twice. Any explanation?

Martin
Attachments
Twice.jpg
(135.14 KiB) Downloaded 663 times

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

Re: Why a "Once Begin" function is executed twice

Postby TJ » 13 Aug 2014

Hello
Only an interrogation. That does not affect my work.
An indicator is applied to one chart with one instrument
At the beginning of the code I got a command to be executed once

Code: Select all

Once begin
Comma = ",";
scale = scalestring;
print(getappinfo(aispacetoright):0:0);
end;
To my surprise, the returned print is executed twice. Any explanation?
Martin
Which version you are using?

I have tested it on MultiCharts64 Version 8.8 Release (Build 8967), and it works fine.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Why a "Once Begin" function is executed twice

Postby arjfca » 13 Aug 2014

Hello TJ

MultiCharts Version 8.8 Release (Build 9590)

I will look again if I don't find an hidden instrument. That could be the reason to explain that

Have a good evening
Martin

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Why a "Once Begin" function is executed twice

Postby JoshM » 14 Aug 2014

I don't know how the underlying process is called, but if you use `BarStatus`, `once` is only executed once.

Code: Select all

once (BarStatus(1) = 2) begin

Print("I'm only printed once");

end;

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Why a "Once Begin" function is executed twice

Postby arjfca » 24 Aug 2014

I still have my issue where the code is runned twice

I found this article related to MC.Net ( I'm using regular MC regarding this problem. It seem to be related to the maxbarBack in an Automatic detect.

http://www.tradingcode.net/multicharts- ... rice-data/
Why does my code execute twice when I reference price data?

The reason for this behaviour is the automatic determination of the maximum number of bars that a study will reference, the so called MaxBarsBack value.
I applied the suggested setup, but still have the same problem
Martin

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

Re: Why a "Once Begin" function is executed twice

Postby Henry MultiСharts » 25 Aug 2014

Martin, is the max bars back you have specified for the study enough for code calculation?
Have you tried increasing the value and then re-adding the study to the chart?

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Why a "Once Begin" function is executed twice

Postby arjfca » 25 Aug 2014

Martin, is the max bars back you have specified for the study enough for code calculation?
Have you tried increasing the value and then re-adding the study to the chart?
Henry

Is there a way to detect how many bars did MC needed to do it's calculation. I did try with 100 bars, but still do the same. I don't think that I have anything related to historic bars in my code. No MA, Bollinger or anything like that. This has been written few years ago and code added to it.

I did look trough all functions used in the indicator and non the max historic data is 3 bars if I recall.

Could the function "LastBarOnChart" be implicated?

The fact that the code is run twice do bug me because I wanted to use a Global variable as a toggle switch and be check at the beginning. If "on" then off, If "Off" then "on. I will see how to overpass that.


Martin

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

Re: Why a "Once Begin" function is executed twice

Postby Henry MultiСharts » 26 Aug 2014

Martin, please send me (support@multicharts.com) the following information for further investigation:
- workspace you are using;
- in PowerLanguage editor->File->Export->export with dependent functions the study you are having problem with. Send me the study export file. You can simplify the study and leave only the logic that replicates the duplicated execution behavior.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Why a "Once Begin" function is executed twice

Postby arjfca » 26 Aug 2014

Martin, please send me (support@multicharts.com) the following information for further investigation:
- workspace you are using;
- in PowerLanguage editor->File->Export->export with dependent functions the study you are having problem with. Send me the study export file. You can simplify the study and leave only the logic that replicates the duplicated execution behavior.
OK, I will do it after my trading session


Return to “MultiCharts”