RecalcLastBarAfter(): need some clarification.

Questions about MultiCharts and user contributed studies.
maxmax68
Posts: 163
Joined: 20 Nov 2012
Has thanked: 55 times
Been thanked: 48 times

RecalcLastBarAfter(): need some clarification.

Postby maxmax68 » 17 Sep 2020

Hello,
I am running some tests with the "Print" function and the "RecalcLastBarAfter()" function, and I need some clarification.
I am running on a chart a Signal with this simple code:

Code: Select all

[IntrabarOrderGeneration = True]; Var: intrabarpersist TickCounter(0); Var: intrabarpersist BarCounter(0); RecalcLastBarAfter(1); If LastBarOnChart then begin TickCounter=TickCounter+1; If barstatus(1)=0 then BarCounter=0; BarCounter=BarCounter+1; Print(File("C:\Users\Utente07\Documents\test.txt"), Time_S:0:0, " BarStatus: ",barstatus(1):0:0, " BarNumber: ",BarNumber:0:0, " TickCounter ",TickCounter:0:0, " BarTickCounter ",BarCounter:0:0, " Ask: ",CurrentAsk:0:0, " Bid: ",CurrentBid:0:0, " Last: ",last:0:0, " Close: ",Close:0:0 ); end;
I have attached an image of the output window with the print result.

My goal was to find out if Multicharts was reading the bid and ask price correctly at the broker (WeBank).
The result of the test was positive, but I realized that while the bid and ask prices were constantly changing at the broker, in the Multicharts signal they were updated only when a tick arrived that allowed the recalculation of the formula.
And this is correct as far as I understood how Multicharts works.
So to try to get an update of the bid and ask also in the signal I thought to use the RecalcLastBarAfter function once per second, and I would like an explanation of the observed behavior:
Correctly every second the line of the print function is reprinted, but it seems that Time_s is not recalculated correctly.
In each line the time should have one second more.

Why doesn't this happen?
Why for several lines the time remains the same and is printed updated only after a few lines,
when probably a tick comes in and causes the signal recalculation?

And as a result, with every line printed for recalc, just as no time_s is updated, probably no bid and ask are updated either,
defeating the purpose of the recalc function of the signal?

Best regards
Massimo


MultiCharts_Test_1.png
(218.94 KiB) Not downloaded yet

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

Re: RecalcLastBarAfter(): need some clarification.

Postby JoshM » 17 Sep 2020

So to try to get an update of the bid and ask also in the signal I thought to use the RecalcLastBarAfter function once per second, and I would like an explanation of the observed behavior:
Correctly every second the line of the print function is reprinted, but it seems that Time_s is not recalculated correctly.
In each line the time should have one second more.

Why doesn't this happen?
Why for several lines the time remains the same and is printed updated only after a few lines,
when probably a tick comes in and causes the signal recalculation?
`Time_s` returns the closing time of the bar, with seconds precision.

So if a script keeps calculating on the same price bar, that bar's closing time hasn't changed, and `time_s` keeps returning the same values.

You can use `currenttime_s` to look up the computer's current time, with seconds precision. This one does change with every passing second.

(And with `ComputerDateTime` you can also access the computer's time with millisecond precision, although you'll need to convert that DateTime value to a string first for proper outputting.)


Return to “MultiCharts”