Intrabar Price
-
- Posts: 36
- Joined: 24 Apr 2012
- Has thanked: 6 times
- Been thanked: 2 times
Intrabar Price
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.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Intrabar Price
Hello Pschriber,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.
Close is the current price of the security.
-
- Posts: 36
- Joined: 24 Apr 2012
- Has thanked: 6 times
- Been thanked: 2 times
Re: Intrabar Price
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?
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Intrabar Price
You can save the value of Close to a variable, and refer to it later.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?
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);
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Intrabar Price
You can use Josh's solution and the following keywords: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?
Getappinfo(airealtimecalc)
Barstatus
They will help you to understand what values you are dealing with and distinguish between them.
-
- Posts: 36
- Joined: 24 Apr 2012
- Has thanked: 6 times
- Been thanked: 2 times
Re: Intrabar Price
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.
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.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Intrabar Price
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:
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;
-
- Posts: 36
- Joined: 24 Apr 2012
- Has thanked: 6 times
- Been thanked: 2 times
Re: Intrabar Price
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;
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;
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Intrabar Price
Please provide more details. What trigger are you referring to?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;