2 registered members (7th_zorro, dr_panther),
724
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Plot Dots prior to current position
#460085
06/15/16 17:58
06/15/16 17:58
|
Joined: Apr 2014
Posts: 24
yebit
OP
Newbie
|
OP
Newbie
Joined: Apr 2014
Posts: 24
|
I'm plotting the LowPass filter over price and identifying peaks and valleys visually using dots with plotGraph. As per the valley() and peak() formulas, the dots are appearing one bar ahead (to the right) of the actual valley or peak. I'm not sure what to set the y parameter in plotGraph to, in order to have to dots appearing at the actual valley or peak bar. When I set it to myseries[0], although dots display, the price and LowPass series lines disappear, and too many dots appear, same as if I try to get in the ballpark by using priceHigh(1) or priceLow(1).
function indicatortest() {
set(PLOTNOW);
int ma_short = 5;
BarPeriod = 60*8;
vars Price = series(price());
vars lowpass_MA_short = series(LowPass(Price, ma_short));
if (valley(lowpass_MA_short)) {
plotGraph("valley", 1, lowpass_MA_short[0] ,DOT, YELLOW );
//plot("valley", lowpass_MA_short, DOT, YELLOW );
}
else if (peak(lowpass_MA_short)) {
plotGraph("peak", 1, lowpass_MA_short[0], DOT, GREEN );
//plot("peak", lowpass_MA_short, DOT, GREEN );
}
}
The commented out code is the code that plots the dots according to the valley and peak functions, that is, 1 bar after the event took place. The x position is 1, as in 1 bar period in the past, and the y position needs to be the y position of the actual peak or valley (multiplied by a small amount to get it hovering just above or below). How to get that value is eluding me. Any comments or solutions would be appreciated.
|
|
|
Re: Plot Dots prior to current position
[Re: yebit]
#460091
06/16/16 02:48
06/16/16 02:48
|
Joined: Apr 2014
Posts: 482 Sydney, Australia
boatman
Senior Member
|
Senior Member
Joined: Apr 2014
Posts: 482
Sydney, Australia
|
The peak and valley functions return true one bar after the actual maximum or minimum that cause the peak or valley. This is the case because you can't know if a peak or valley exists until the completion of the following candle - by definition, a peak or valley requires three bars to identify. If you need to plot something at the bar corresponding to the maximum or minimum, you could set the PEEK flag (this enables you to see into the future during the simulation) and check if the peak or valley functions returned true at the next bar. Somethign like this would work (but of course it won't work for live trading since you can't see into the future):
function run()
{
set(PLOTNOW|PEEK);
int ma_short = 5;
BarPeriod = 60*8;
vars Price = series(price());
vars lowpass_MA_short = series(LowPass(Price, ma_short));
//future peeking lowpass filter
vars PricePeek = series(price(-1));
vars lowpassPeek = series(LowPass(PricePeek, ma_short));
if (valley(lowpassPeek)) {
plot("valley", priceLow()-10*PIP, DOT, YELLOW);
}
else if (peak(lowpassPeek)) {
plot("peak", priceHigh()+10*PIP, DOT, GREEN );
}
PlotBars = 100;
PlotScale = 12;
plot("lowpass", lowpass_MA_short, MAIN, BLUE);
}
|
|
|
Re: Plot Dots prior to current position
[Re: boatman]
#460096
06/16/16 05:56
06/16/16 05:56
|
Joined: Apr 2014
Posts: 24
yebit
OP
Newbie
|
OP
Newbie
Joined: Apr 2014
Posts: 24
|
Thanks for your response. No need to use logic, it's in the definition! I haven't run your code yet, still working on mine and I found that it's actually fine except when I try to use PlotBars. As soon as I use PlotBars (which I want to see the graph better), the graph is blank except for the dots, with the bars scrunched up to the far left side.
function indicatortest(ma_short, ma_medium, ma_long) {
int ma_short = 15;
BarPeriod = 60*8;
PlotDate = 20150105;
//PlotBars = -100; //uncomment this and the chart is unreadable
vars Price = series(price());
set(PLOTNOW);
vars lowpass_MA_short = series(LowPass(Price, ma_short));
plot("low pass short", lowpass_MA_short,LINE, ORANGE);
if (valley(lowpass_MA_short)) {
plotGraph("valley", 1, priceLow(1) ,DOT, YELLOW );
}
else if (peak(lowpass_MA_short)) {
//shows 2 dots, both at the correct bar, one at the level of
// priceHigh, the other at the level of the trendline.
plotGraph("peak", 1, lowpass_MA_short[1], DOT, GREEN );
plotGraph("peak", 1, priceHigh(1), DOT, GREEN );
}
}
any idea why PlotBars affects the chart in this way?
Last edited by yebit; 06/16/16 06:04.
|
|
|
Re: Plot Dots prior to current position
[Re: boatman]
#460097
06/16/16 06:47
06/16/16 06:47
|
Joined: Apr 2014
Posts: 24
yebit
OP
Newbie
|
OP
Newbie
Joined: Apr 2014
Posts: 24
|
OK, yours works better, there's no problem plotting with PlotBars. Thanks.
Last edited by yebit; 06/16/16 06:48.
|
|
|
|