Detecting and acting on the beginning of last bar

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

Detecting and acting on the beginning of last bar

Postby arjfca » 05 Mar 2012

Hello

I need to react and detect only and only the last bar on a chart. Problem is when I load my chart, the condition is detected and a process is execute

Code: Select all

If barstatus[1]= 2 and LastBarOnChart then begin // this is the begining of a new bar
Print (lastbaronchart);
BarCompleted = "BC";
If you test it, the condition will return true before the completion of the actual bar. Just starting the signal code engage the process and conditions are tested. I want to test only after the entire graph as been loaded and only for the last bar after the initialization.

The fact that lastbaronchart is detected while the chart is initialized cause some data to be sent to Excel. This process is very slow and create an error

Hope I'm clear enough :)

Martin

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

Re: Detecting and acting on the beginning of last bar

Postby TJ » 05 Mar 2012

Hello

I need to react and detect only and only the last bar on a chart. Problem is when I load my chart, the condition is detected and a process is execute

Code: Select all

If barstatus[1]= 2 and LastBarOnChart then begin // this is the begining of a new bar
Print (lastbaronchart);
BarCompleted = "BC";
If you test it, the condition will return true before the completion of the actual bar. Just starting the signal code engage the process and conditions are tested. I want to test only after the entire graph as been loaded and only for the last bar after the initialization.

The fact that lastbaronchart is detected while the chart is initialized cause some data to be sent to Excel. This process is very slow and create an error

Hope I'm clear enough :)

Martin
What is your chart resolution?

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

Re: Detecting and acting on the beginning of last bar

Postby arjfca » 05 Mar 2012

Hello TJ

175 seconds

The code work perfectly outside the initial loading time. I don't want the condition to be triggered in the initialization or chart loading

Martin

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

Re: Detecting and acting on the beginning of last bar

Postby TJ » 05 Mar 2012

Hello TJ

175 seconds

The code work perfectly outside the initial loading time. I don't want the condition to be triggered in the initialization or chart loading

Martin
try

LastBarOnChart_s

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

Re: Detecting and acting on the beginning of last bar

Postby arjfca » 05 Mar 2012

LastBarOnChart_S ....Negative. Last bar detected while loading the chart or when put the signal on

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

Re: Detecting and acting on the beginning of last bar

Postby arjfca » 05 Mar 2012

Did found a solution, maybe not a one line like TJ could create, but it work

- In the initialization process, capture the machine time

- In the running process, look for the actual time of the machine be greater than the referencetime + 100 ms.

Using that the last bar is detected only after the completion of the actual bar and not during the initialization of the chart

Code: Select all

Once If barnumber = 1 then begin
Referentime = machinetime // Capture the actual time of the machine
end;

//Running code

If barstatus[1] = 2 and lastBarOnChart and machinetime > referentime +100 then begin
Print (LastBarOnChart)
end;
Martin


Return to “MultiCharts”