Question, execution of signal script  [SOLVED]

Questions about MultiCharts and user contributed studies.
andy4444
Posts: 25
Joined: 14 Nov 2013
Has thanked: 8 times
Been thanked: 2 times

Question, execution of signal script

Postby andy4444 » 15 Nov 2013

I am trying to program a signal and in the code I want the logic to go between different "stations" for processing. (Sort of like a product travels between different machines for different kinds of processing in a workshop).
I have written a simple verison below, where processing starts at station 1, but when a certain condition is true (as an example I have used the condition "close>100") then the processing moves to station 2. While at station 2 I want the programme to forget all about station 1 (at least until I redirect processing there from code within station 2). However I get the impression that the way Multicharts reads the script, is that as soon as the condition1 becomes untrue (in this case close<100) then Multicharts will start to process things at station1 again!?


Var:
station(1);

if station =1 then begin
//blablabla code
if close>100 then station=2;
end;

if station=2 then begin
//blablabla Code
end;

Have I understood this correctly,? And if so, how can I get around this problem so that I can create a script where the logic moves between different stations, and does not "scip back" to previous stations when conditions within those previous stations change.
I may add that I have no programming background.

Thank you for any input!

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

Re: Question, execution of signal script

Postby TJ » 15 Nov 2013

I am trying to program a signal and in the code I want the logic to go between different "stations" for processing. (Sort of like a product travels between different machines for different kinds of processing in a workshop).
I have written a simple verison below, where processing starts at station 1, but when a certain condition is true (as an example I have used the condition "close>100") then the processing moves to station 2. While at station 2 I want the programme to forget all about station 1 (at least until I redirect processing there from code within station 2). However I get the impression that the way Multicharts reads the script, is that as soon as the condition1 becomes untrue (in this case close<100) then Multicharts will start to process things at station1 again!?
Var:
station(1);
if station =1 then begin
//blablabla code
if close>100 then station=2;
end;
if station=2 then begin
//blablabla Code
end;
Have I understood this correctly,? And if so, how can I get around this problem so that I can create a script where the logic moves between different stations, and does not "scip back" to previous stations when conditions within those previous stations change.
I may add that I have no programming background.
Thank you for any input!
Computers are dumb.
They will only do what you tell it to do.
If you tell the computer that station=1, it will remember the value and never forget...
until you tell him that station=2.
When station=2, no matter what happens (eg. C<100), station will still =2 unless you specifically tell the computer otherwise.
eg.

Code: Select all

if close<100 then station=1;
Hope the above helps.


ps. [FAQ] How to Post Codes (that people can read)
viewtopic.php?f=16&t=11713

andy4444
Posts: 25
Joined: 14 Nov 2013
Has thanked: 8 times
Been thanked: 2 times

Re: Question, execution of signal script

Postby andy4444 » 20 Nov 2013

Thank you for your reply and your time TJ.

There is a serious problem here. I have written an even more simple script to visualize below, and below it I also paste the content from the Output tab from the Powerlanguage Editor.
The intention is for station 0 to only run once, and then for station 1 to run going forward.
However, while the bar stays the same (bar 51) the logic keeps reverting back to station 0!
Not until a new bar is beginning to form (bar 52), does the logic stay completely at station 1.
This is a serious problem for me, since if I have the order entry function in station 0, I end up sending multiple entries instead of 1 etc.
Please, does anyone have an explanation/solution to this problem which I have spent over a week trying to solve. I tried every workaround possible. Is it a flaw in MC, or am I just dumb?

Code: Select all

vars:
station(0);

//Station 0//////////////
if station = 0 then begin
print( maxbarsback+currentbar ,"Print A. Station is ", station:1:0);
station=1;
end;
///////////////////////


//Station 1/////////////
if station = 1 then begin
print( maxbarsback+currentbar ,"Print B. Station is ", station:1:0);
end;
//////////////////////
51.00Print A. Station is 0
51.00Print B. Station is 1
51.00Print A. Station is 0
51.00Print B. Station is 1
51.00Print A. Station is 0
51.00Print B. Station is 1
51.00Print A. Station is 0
51.00Print B. Station is 1
52.00Print B. Station is 1
52.00Print B. Station is 1
52.00Print B. Station is 1
52.00Print B. Station is 1

andy4444
Posts: 25
Joined: 14 Nov 2013
Has thanked: 8 times
Been thanked: 2 times

Re: Question, execution of signal script

Postby andy4444 » 20 Nov 2013

I should add that the problem occurs when Intrabar Order Generation is true.

[IntrabarOrderGeneration = True];

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Question, execution of signal script  [SOLVED]

Postby Smoky » 21 Nov 2013

Take a look about 'intrabarpersist' variable for tick/tick code ;)

andy4444
Posts: 25
Joined: 14 Nov 2013
Has thanked: 8 times
Been thanked: 2 times

Re: Question, execution of signal script

Postby andy4444 » 27 Nov 2013

Smoky.
Thank you soo much! IntrabarPersist did indeed solve all my problems.
Have an awesome day!
Andy

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Question, execution of signal script

Postby Smoky » 28 Nov 2013

happy to help you Andy ;)


Return to “MultiCharts”