Once with ReCalcLastBarAfter

Questions about MultiCharts and user contributed studies.
escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Once with ReCalcLastBarAfter

Postby escamillo » 29 Feb 2012

If I use
Once ReCalcLastBarAfter(5) ;

Will code then recalculate ONCE after 5 seconds, or recalculate recurrently after every five seconds? Thanks.

User avatar
TJ
Posts: 6550
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 965 times
Been thanked: 1892 times

Re: Once with ReCalcLastBarAfter

Postby TJ » 29 Feb 2012

escamillo wrote:If I use
Once ReCalcLastBarAfter(5) ;

Will code then recalculate ONCE after 5 seconds, or recalculate recurrently after every five seconds? Thanks.

don't use ONCE with it.

just add the statement to the code

Code: Select all

ReCalcLastBarAfter(5) ;

and MultiCharts will recalculate the indicator at least once every 5 seconds.

Normally an indicator will only recalculate when there is a new tick coming in.
In the absence of new data, there is usually no need to recalculate the indicator because all the parameters will be unchanged. This ReCalcLastBarAfter command forces MultiCharts to recalculate your indicator when the market is thin, and when no new ticks are coming in.

This command is useful if your indicator is time sensitive.
eg. if lapse.time > X minutes then...
These users thanked the author TJ for the post:
PK1

escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Re: Once with ReCalcLastBarAfter

Postby escamillo » 29 Feb 2012

I do not want it to calculate recurrently, but one time only, so wondering if it will operate only once after Once.

User avatar
TJ
Posts: 6550
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 965 times
Been thanked: 1892 times

Re: Once with ReCalcLastBarAfter

Postby TJ » 29 Feb 2012

escamillo wrote:I do not want it to calculate recurrently, but one time only.


The keyword ONCE is executed only one time... when you load the indicator into the chart.
These users thanked the author TJ for the post:
escamillo

escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Re: Once with ReCalcLastBarAfter

Postby escamillo » 29 Feb 2012

Thanks TJ. Wasn't sure if there was some feature of ReCalcLastBarAfter that would not make it work with Once.

User avatar
TJ
Posts: 6550
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 965 times
Been thanked: 1892 times

Re: Once with ReCalcLastBarAfter

Postby TJ » 29 Feb 2012

escamillo wrote:Thanks TJ. Wasn't sure if there was some feature of ReCalcLastBarAfter that would not make it work with Once.

I don't quite understand your situation, so I don't know where to begin to help you.

Can you describe under what scenario you would like to have a recal, but only once?

How would you trigger the recal? manually?

automatically? how?

What if it is recalculated more than once? would it cause an error? Why? How so?


Maybe your situation has a simpler solution than ReCalcLastBarAfter.

escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Re: Once with ReCalcLastBarAfter

Postby escamillo » 29 Feb 2012

If you have an Indicator set to OFF (not checked) on 'Update every tick' on a Daily bar chart, then Plots will be a day behind, unless you use a timer or ReCalcLastBarAfter, which will cause the code to run and a Plot to appear on today's bar. Once the indicator has run once and the plot is updated, there is no need to run it again and prefer to not have the CPU overhead throughout the day (this is for an indicator that does not use information from today).

User avatar
TJ
Posts: 6550
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 965 times
Been thanked: 1892 times

Re: Once with ReCalcLastBarAfter

Postby TJ » 29 Feb 2012

escamillo wrote:If you have an Indicator set to OFF (not checked) on 'Update every tick' on a Daily bar chart, then Plots will be a day behind, unless you use a timer or ReCalcLastBarAfter, which will cause the code to run and a Plot to appear on today's bar. Once the indicator has run once and the plot is updated, there is no need to run it again and prefer to not have the CPU overhead throughout the day (this is for an indicator that does not use information from today).

If your computer is 4 years old, it is probably running at 2GHz,
it will perform 2,000,000,000 computation per second.

A typical current day trading computer is a quad core running at 3 GHz,
it will do 12,000,000,000 computation per second.

You can set the ReCalcLastBarAfter to 3600, and it won't hurt the computer a tiny bit.

escamillo
Posts: 197
Joined: 25 Mar 2011
Has thanked: 22 times
Been thanked: 55 times

Re: Once with ReCalcLastBarAfter

Postby escamillo » 29 Feb 2012

right. today for example, with 39,000 ES contracts in the ten seconds prior to 3PM and 64,000 ES contracts in the ten seconds after 3PM, I do not want much of anything running besides what is related to current data and current contracts. a tick behind here, a tick behind there.... If it does not NEED to run, I do not want to run it.

User avatar
TJ
Posts: 6550
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 965 times
Been thanked: 1892 times

Re: Once with ReCalcLastBarAfter

Postby TJ » 29 Feb 2012

escamillo wrote:right. today for example, with 39,000 ES contracts in the ten seconds prior to 3PM and 64,000 ES contracts in the ten seconds after 3PM, I do not want much of anything running besides what is related to current data and current contracts. a tick behind here, a tick behind there.... If it does not NEED to run, I do not want to run it.

Today is an exception.
Even that, my 4 yrs old computer never missed a beat.


You can try a time condition:

Code: Select all

If time > 1615 then Begin...



Alternatively you can do a manual recal.

View > Reload
These users thanked the author TJ for the post (total 2):
JoshMLobo.Trader

User avatar
Lobo.Trader
Posts: 12
Joined: 26 Nov 2011
Location: Germany
Has thanked: 19 times
Been thanked: 6 times

Re: Once with ReCalcLastBarAfter Keyword "ONCE"

Postby Lobo.Trader » 18 Mar 2012

Hello there :-)

me was searching for keyword "ONCE" and found this thread , whilst not finding anything in our MC-documentions (?) .

So , @ TJ , the keyword "ONCE" works same like function " INIT() " in MT4 ? Above, your statement was made re an indicator .Please let me reconfirm , that ONCE works same as MT4 - INIT() for MC - strategies ?

But I will be NOT able to apply "ONCE ... then begin ..code pieces.. end;" ?

Thank you

Lobo

PS.: This is, how I do my initialisation today

Code: Select all

//   ==============================================================================================
 
// INIT () : diese Routine laedt die offenen Trades und holt sich deren Daten                       
if init = true                                    //
   then begin                                    // Initialisierung des HS
   init = false                           ;// Init - Routine nur einmal ausfuehren
//   [IntrabarOrderGeneration = True]         ;//
   ClearPrintLog                               ;//
      Print (" ***** Initialising SLV Stratetgy NutShell *****")      ;//
      For  value1 = 1 to 10 begin
      DrawTL[value1,0] = tl_new(0,0,0,0,0,0);// DEBUGG :ID Horizontal Line for Prices
   end                                       ;//
   // Variable conditions
   TickSize  = MinMove/PriceScale             ;// Abgeguckt
   StopLoss1 = stop1*ticksize                 ;// StopLoss im Preis
   Step      = stepset*ticksize               ;// Trailing Schrittgroesse
end                                          ;// 

//   ==============================================================================================

Sorry, for German comments , no rocketscience anyhows ;)

User avatar
JoshM
Posts: 2080
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1483 times
Contact:

Re: Once with ReCalcLastBarAfter Keyword "ONCE"

Postby JoshM » 18 Mar 2012

Lobo.Trader wrote:the keyword "ONCE" works same like function " INIT() " in MT4 ?

Yes. MultiCharts' ..

Code: Select all

once begin

   ....

end;


..works the same as MT's ..

Code: Select all

int init()
{

   ...
   
   return (0);
}


Lobo.Trader wrote:But I will be NOT able to apply "ONCE ... then begin ..code pieces.. end;" ?

I don't follow you here - do you mean like MT's deinit()? (Code pieces can be placed in the once..begin statement if that's what you mean).

User avatar
JoshM
Posts: 2080
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1483 times
Contact:

Re: Once with ReCalcLastBarAfter Keyword "ONCE"

Postby JoshM » 18 Mar 2012

Lobo.Trader wrote:

Code: Select all

//   ==============================================================================================
 
// INIT () : diese Routine laedt die offenen Trades und holt sich deren Daten                       
if init = true                                    //
   then begin                                    // Initialisierung des HS
   init = false                           ;// Init - Routine nur einmal ausfuehren
//   [IntrabarOrderGeneration = True]         ;//
   ClearPrintLog                               ;//
      Print (" ***** Initialising SLV Stratetgy NutShell *****")      ;//
      For  value1 = 1 to 10 begin
      DrawTL[value1,0] = tl_new(0,0,0,0,0,0);// DEBUGG :ID Horizontal Line for Prices
   end                                       ;//
   // Variable conditions
   TickSize  = MinMove/PriceScale             ;// Abgeguckt
   StopLoss1 = stop1*ticksize                 ;// StopLoss im Preis
   Step      = stepset*ticksize               ;// Trailing Schrittgroesse
end                                          ;// 

//   ==============================================================================================



As far as I follow you, the following code does the same but is "better" and more handier I think:

Code: Select all

Variables:
   TickSize   (MinMove / PriceScale),
   StopLoss1   (Stop1 * TickSize),
   Step      (stepset * TickSize);
   
//[IntrabarOrderGeneration = TRUE]

// diese Routine laedt die offenen Trades und holt sich deren Daten 
once begin

   ClearPrintLog;
   Print (" ***** Initialising SLV Stratetgy NutShell *****");
   
   For value1 = 1 to 10 begin
      DrawTL[value1,0] = tl_new(0,0,0,0,0,0);      // DEBUGG :ID Horizontal Line for Prices
   end;

end;
These users thanked the author JoshM for the post:
Lobo.Trader

User avatar
TJ
Posts: 6550
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 965 times
Been thanked: 1892 times

Re: Once with ReCalcLastBarAfter Keyword "ONCE"

Postby TJ » 18 Mar 2012

Lobo.Trader wrote:Hello there :-)

me was searching for keyword "ONCE" and found this thread , whilst not finding anything in our MC-documentions (?) .

So , @ TJ , the keyword "ONCE" works same like function " INIT() " in MT4 ? Above, your statement was made re an indicator .Please let me reconfirm , that ONCE works same as MT4 - INIT() for MC - strategies ?
...


Sorry, for German comments , no rocketscience anyhows ;)



Sorry, I don't know MT4.
Please read the wiki for keyword explanation.

User avatar
Lobo.Trader
Posts: 12
Joined: 26 Nov 2011
Location: Germany
Has thanked: 19 times
Been thanked: 6 times

Re: Once with ReCalcLastBarAfter

Postby Lobo.Trader » 24 Mar 2012

JoshM , thank you very much for better and more handier code and how to apply "once begin ..end;" .

TJ : "Please read the wiki for keyword explanation" . ....... I did w/o success : within Wiki cannot find "Keyword Alphabetical Index " there in Chaper 5 . And in "Keyword Alphabetical Index " of the PowerLanguage Editor I could not find "ONCE" listed . That than made me post here after having used the search option of the forum and identifying this thread as the most adequate .
What was I doing wrong ? Thank you .

Lobo

PS.: Sorry, for late reply, was traveling entire week and only now returned. @all : Have a great weekend , "blue skies" in Germany wish you the same :-)

User avatar
JoshM
Posts: 2080
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1483 times
Contact:

Re: Once with ReCalcLastBarAfter

Postby JoshM » 24 Mar 2012

Lobo.Trader wrote:TJ : "Please read the wiki for keyword explanation" . ....... I did w/o success : within Wiki cannot find "Keyword Alphabetical Index " there in Chaper 5 . And in "Keyword Alphabetical Index " of the PowerLanguage Editor I could not find "ONCE" listed . That than made me post here after having used the search option of the forum and identifying this thread as the most adequate .
What was I doing wrong ? Thank you .

Your're right, there is no Once page in the wiki. But there's an small segment in EasyLanguage Essentials (pdf page 57, found here) about it:
scr.24-03-2012 15.00.17.png
scr.24-03-2012 15.00.17.png (35.25 KiB) Viewed 444 times
These users thanked the author JoshM for the post:
Lobo.Trader

User avatar
Lobo.Trader
Posts: 12
Joined: 26 Nov 2011
Location: Germany
Has thanked: 19 times
Been thanked: 6 times

Re: Once with ReCalcLastBarAfter

Postby Lobo.Trader » 24 Mar 2012

... and also in the Easy Language "Functions & Reserved Words Reference" (TS 8.3.) at page 861 . Should have searched the manuals as well .

Lobo
These users thanked the author Lobo.Trader for the post:
JoshM

janus
Posts: 747
Joined: 25 May 2009
Has thanked: 41 times
Been thanked: 83 times

Re: Once with ReCalcLastBarAfter

Postby janus » 24 Mar 2012

JoshM wrote:Your're right, there is no Once page in the wiki. But there's an small segment in EasyLanguage Essentials (pdf page 57, found here) about it:
scr.24-03-2012 15.00.17.png

I don't understand the need to use currentbar in the first example. Also, strictly speaking the first example is executed 4 times, not once. It would be better to use an intrabarpersist variable. Then it will be executed once. The second example using the once keyword is wrong. It doesn't even compile. It must be a typo, and doesn't make sense to use logical tests anyway with a once statement. It should be written as:

Code: Select all

var: counter(0);
once begin
   counter = 1000;
end;


Furthermore, if IOG is turned on, the counter will not retain the value of 1000; So, the correct code is:

Code: Select all

var: intrabarpersist counter(0);
once begin
   counter = 1000;
end;
These users thanked the author janus for the post:
JoshM


Return to “MultiCharts”