[PL] Signal plots several times per bar with different value

Questions about MultiCharts and user contributed studies.
duration
Posts: 179
Joined: 20 Dec 2005
Been thanked: 1 time

[PL] Signal plots several times per bar with different value

Postby duration » 30 Mar 2010

Dear All,

I am having issues writing a signal in powerlanguage.

I want the signal to plot the difference between the white xaverage and the low of a bar. It does it, but gives me several values for a bar, see the attached screenshot. How come? Is there a way to fix this>

Here is the signal:

Code: Select all

variables:
ema1(0), diff(0);

if currentbar = 0 then ema1 = close;

ema1 = xaverage(close,8);
diff = ema1-low;

value1 = arw_new(date,time,low,false);
arw_settext(value1,"d:"&" "&text(diff:0:4));
Many thanks,
Attachments
difference.png
(28.22 KiB) Downloaded 641 times

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Postby SP » 30 Mar 2010

You could use if barstatus (1) =2 to plot the arrow only at the end of the bar
or you need to delete the arrow and the text erverytime the diff value changed intrabar using arw_delete.

duration
Posts: 179
Joined: 20 Dec 2005
Been thanked: 1 time

Postby duration » 01 Apr 2010

Dear SP,

Thank you for your reply.

I write the following, but Barstatus() does not seem to work:


Code: Select all

variables:
ema1(0), diff(0);

if currentbar = 0 then ema1 = close;

ema1 = xaverage(close,8);
diff = ema1-low;

value1 = arw_new(date,time,low,false);
if barstatus(1) = 2 then arw_settext(value1,"d:"&" "&text(diff:0:4));
I don't really know how to delete the arrow intrabar :(

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 01 Apr 2010

You have essentially two choices.

First, you could put the text_new inside of an "if barstatus(1) = 2 then" such that the text is only added if the bar is complete.

or

Second, you could save the text object's identifier created by text_new in an intrabarpersist variable (not just discard it in value1) and then later, in subsequent ticks on the same bar, either delete the object first and re-add it, or better, change the text on the same existing object by referencing its identifier which you earlier saved.

A key issue here is that relative to what you're doing now, value1 isn't intrabarpersist, and therefore, you're not saving the identifier, and also, the barstatus qualification should likely be on the creation of a new arrow rather than just on the assignment of the text.

duration
Posts: 179
Joined: 20 Dec 2005
Been thanked: 1 time

Postby duration » 05 Apr 2010

Dear Bruce,

Thank you very much for your reply and explanations.

I have tried your first suggestion as the second one is a bit more complex for me.

Code: Select all

variables:
ema1(0), diff(0);

if currentbar = 0 then ema1 = close;

ema1 = xaverage(close,8);
diff = ema1-low;

if barstatus(1) = 2 then text_new(date, time,low,"d:"&" "&text(diff:0:4));
But it does not fixed the problem (although logically it should), I still get up to 3 texts per bar...

Any other ideas?

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 05 Apr 2010

Running the exact code you've posted, there is only one text object per bar as expected.

Perhaps you are not running that code verbatim, or perhaps you have some issue specific to a particular kind of bars (for instance, you could be using bars so small that there are multiple bars for the same date and time - in which case the text objects would overlap because they're specified by the date and time), but there is not an issue in general.
Attachments
MC Screenshot.png
(150.87 KiB) Downloaded 622 times

duration
Posts: 179
Joined: 20 Dec 2005
Been thanked: 1 time

Postby duration » 05 Apr 2010

Dear Bruce,

Thanks for trying, I will submit this to the support.

Many thanks,

User avatar
Andrew Kirillov
Posts: 1589
Joined: 28 Jul 2005
Has thanked: 2 times
Been thanked: 31 times
Contact:

Postby Andrew Kirillov » 06 Apr 2010

The following code will work:

Code: Select all

////-------
variables:
ema1(0), diff(0);

if currentbar = 0 then ema1 = close;

ema1 = xaverage(close, 8);
diff = ema1 - low;

if barstatus(1) = 2 then
begin
value1 = arw_new(date,time,low,false);
arw_settext(value1,"d:"&" "&text(diff:0:4));
end;

////------------------
If you take a look at the help you will see why there are multiple arrows on the single bar:

Usage
Arw_New (BarDate, BarTime, PriceValue, Direction)

Parameters
BarDate - a numerical expression specifying the date of the bar at which the object is to be placed; the date is indicated in the YYYMMdd format, where YYY is the number of years since 1900, MM is the month, and dd is the day of the month

BarTime - a numerical expression specifying the time of the bar at which the object is to be placed; the time is indicated in the 24-hour HHmm format, where 1300 = 1:00 PM

PriceValue - a numerical expression specifying the price value (vertical position, corresponding to a value on the price scale of a chart), where the object is to be placed

Direction - a logical expression specifying the direction of the arrow; True = Down and False = Up
-----------------
Time coordinates will be accurate within minutes.
According to the picture the neighboring bars have the same time.

There is another function that specifies time with second precision:


Arw_New_s (BarDate, BarTime_s, PriceValue, Direction)

BarTime_s - a numerical expression specifying the time of the bar, including seconds, at which the object is to be placed; the time is indicated in the 24-hour HHmmss format, where 130000 = 1:00:00 PM


Please try this way:
value1 = arw_new_s(date, time_s, low, false);

duration
Posts: 179
Joined: 20 Dec 2005
Been thanked: 1 time

Postby duration » 07 Apr 2010

Dear Andrew,

Well spotted! The arw_new_s & time_s solutions fixed it!

Thank you again for your support,


Return to “MultiCharts”