Intrabar Price

Questions about MultiCharts and user contributed studies.
pschriber2
Posts: 36
Joined: 24 Apr 2012
Has thanked: 6 times
Been thanked: 2 times

Intrabar Price

Postby pschriber2 » 04 Jun 2012

I was wondering how I would reference the current price for a security within a bar for a indicator. The manual only says you can reference the open, close, high and low.

User avatar
Henry MultiСharts
Posts: 8383
Joined: 25 Aug 2011
Has thanked: 1200 times
Been thanked: 2678 times

Re: Intrabar Price

Postby Henry MultiСharts » 05 Jun 2012

pschriber2 wrote:I was wondering how I would reference the current price for a security within a bar for a indicator. The manual only says you can reference the open, close, high and low.

Hello Pschriber,

Close is the current price of the security.

pschriber2
Posts: 36
Joined: 24 Apr 2012
Has thanked: 6 times
Been thanked: 2 times

Re: Intrabar Price

Postby pschriber2 » 05 Jun 2012

Hi thanks for the response. Then how would I able to distinguish with the current close of the security (tick) and the close for the time resolution identified (i.e. 1 day). I need to use different logic on the different closes so is there a way to do this?

User avatar
JoshM
Posts: 2074
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1523 times
Been thanked: 1479 times
Contact:

Re: Intrabar Price

Postby JoshM » 06 Jun 2012

pschriber2 wrote:Then how would I able to distinguish with the current close of the security (tick) and the close for the time resolution identified (i.e. 1 day). I need to use different logic on the different closes so is there a way to do this?

You can save the value of Close to a variable, and refer to it later.

For example:

Code: Select all

Variables:
   closeOfDay(0), lastTickPrice(0);
   
if (Date <> Date[1]) then
   closeOfDay = Close[1];
   
lastTickPrice = Close;

if (LastBarOnChart_s = True) then
   Print("Yesterday's close was: ", closeOfDay, NewLine, "Last tick was: ", lastTickPrice);


Also see TJ's PowerLanguage FAQ.

User avatar
Henry MultiСharts
Posts: 8383
Joined: 25 Aug 2011
Has thanked: 1200 times
Been thanked: 2678 times

Re: Intrabar Price

Postby Henry MultiСharts » 06 Jun 2012

pschriber2 wrote:Hi thanks for the response. Then how would I able to distinguish with the current close of the security (tick) and the close for the time resolution identified (i.e. 1 day). I need to use different logic on the different closes so is there a way to do this?

You can use Josh's solution and the following keywords:

Getappinfo(airealtimecalc)
Barstatus

They will help you to understand what values you are dealing with and distinguish between them.

pschriber2
Posts: 36
Joined: 24 Apr 2012
Has thanked: 6 times
Been thanked: 2 times

Re: Intrabar Price

Postby pschriber2 » 06 Jun 2012

Thanks for the reply guys.

I'm trying to use BarStatus (1)=1 and BarStatus (1)=2 to distinguish between the two. For example when checking for a new high compared to the previous bar I'm trying to use the following:

if ( (Close > High[1]) and (BarStatus(1) = 1) and (Low > Low[1])) then begin
PlotPaintBar(high, low, open, close, "", green);
end;

But when I do this, it doesn't plot anything. However, if I take the BarStatus(1)=1 statement out it plots but it does for the closing value of the bars not the intraday highs.

User avatar
Henry MultiСharts
Posts: 8383
Joined: 25 Aug 2011
Has thanked: 1200 times
Been thanked: 2678 times

Re: Intrabar Price

Postby Henry MultiСharts » 11 Jun 2012

When indicator is applied to the chart it is calculated on historical (Barstatus=2) data first.
Then it starts the real-time calculation from the moment it is applied to the chart (if "update on every tick" is enabled in the indicator settings).

That is why BarStatus=1 in your code does not work on the historical data. It will work after the specified conditions are met in real-time. Removing Barstatus=1 from your code is equals to writing Barstatus=2 because in both cases the calculation will be done only on the historical close values.

Probably it will be easier to distinguish historical calculation and realtime calculation with the following code:

Code: Select all

//historical data
if GetAppInfo(aiRealTimeCalc)=0 then begin 
PlotPaintBar(high, low, open, close, "", green);
end;

//realtime data   
if GetAppInfo(aiRealTimeCalc)=1 then begin 
PlotPaintBar(high+1, low+1, open+1, close+1, "", red);
end;

pschriber2
Posts: 36
Joined: 24 Apr 2012
Has thanked: 6 times
Been thanked: 2 times

Re: Intrabar Price

Postby pschriber2 » 19 Jun 2012

Okay I will try that out. I also noticed that when a trigger has been hit during the playback mode it works fine but when it is applied to historical data the plot doesn't change colour. I am using the close price to compare to new lows and highs within a bar. So when the close bar ends within the previous bars range the bar doesn't change colours as required. I tried using flags to distinguish between these scenarios as follows:

if ( (High >High[1]) and (Close< Low[1]) and flagH=1) then begin //Detects a new high
flagHL=1;
flagH=0;
PlotPaintBar(high, low, open, close, "", yellow);
end;

User avatar
Henry MultiСharts
Posts: 8383
Joined: 25 Aug 2011
Has thanked: 1200 times
Been thanked: 2678 times

Re: Intrabar Price

Postby Henry MultiСharts » 20 Jun 2012

pschriber2 wrote:Okay I will try that out. I also noticed that when a trigger has been hit during the playback mode it works fine but when it is applied to historical data the plot doesn't change colour. I am using the close price to compare to new lows and highs within a bar. So when the close bar ends within the previous bars range the bar doesn't change colours as required. I tried using flags to distinguish between these scenarios as follows:

if ( (High >High[1]) and (Close< Low[1]) and flagH=1) then begin //Detects a new high
flagHL=1;
flagH=0;
PlotPaintBar(high, low, open, close, "", yellow);
end;

Please provide more details. What trigger are you referring to?


Return to “MultiCharts”