diff --git a/widgets/components/StockParallelChannel/StockParallelChannel.h b/widgets/components/StockParallelChannel/StockParallelChannel.h index 8e7efa1..d51bc61 100644 --- a/widgets/components/StockParallelChannel/StockParallelChannel.h +++ b/widgets/components/StockParallelChannel/StockParallelChannel.h @@ -137,14 +137,19 @@ public: auto Y=[&](double v){ return y_at(v,lo,hi); }; (void)X; (void)Y; (void)px; (void)py; (void)pw; (void)ph; - double p0=anchors_[0].price, p1=anchors_[1].price, off=anchors_[2].price; + // Flag 13: set_anchors() leaves only 2 anchors, so anchors_[2] + // is out of bounds (aborted without -DNDEBUG). With 2 anchors + // the outer channel line falls back to the midline. + double p0=anchors_[0].price, p1=anchors_[1].price, mid=(p0+p1)/2.0; + double off=anchors_.size()>2?anchors_[2].price:mid; int b0=anchors_[0].bar, b1=anchors_[1].bar; double slope=(b1!=b0)?(p1-p0)/(b1-b0):0.0; auto line_at=[&](double base){ double v0=base+slope*(0-b0), v1=base+slope*((int)series_.size()-1-b0); return std::pair(v0,v1); }; XSetForeground(display_,gc_,acol); xf::set_line_width(display_, gc_, line_width_); auto c0=line_at(p0); XDrawLine(display_,window_,gc_,px,Y(c0.first),px+pw,Y(c0.second)); - double mid=(p0+p1)/2.0; auto cm=line_at(mid); set_dash(true); XDrawLine(display_,window_,gc_,px,Y(cm.first),px+pw,Y(cm.second)); set_dash(false); - auto c2=line_at(off); XDrawLine(display_,window_,gc_,px,Y(c2.first),px+pw,Y(c2.second)); xf::set_line_width(display_,gc_,1); - for (int i=0;i<3;++i){ int cx=X(anchors_[i].bar), cy=Y(anchors_[i].price); XFillArc(display_,window_,gc_,cx-4,cy-4,8,8,0,360*64); } + auto cm=line_at(mid); set_dash(true); XDrawLine(display_,window_,gc_,px,Y(cm.first),px+pw,Y(cm.second)); set_dash(false); + if (anchors_.size()>2) { auto c2=line_at(off); XDrawLine(display_,window_,gc_,px,Y(c2.first),px+pw,Y(c2.second)); } + xf::set_line_width(display_,gc_,1); + for (int i=0;i<3 && i<(int)anchors_.size();++i){ int cx=X(anchors_[i].bar), cy=Y(anchors_[i].price); XFillArc(display_,window_,gc_,cx-4,cy-4,8,8,0,360*64); } XSetForeground(display_,gc_,axis_col); XDrawRectangle(display_,window_,gc_,px,py,pw,ph); XSetForeground(display_,gc_,st.lineColor_); XDrawRectangle(display_,window_,gc_,x1_,y1_,width(),height()); xf::draw_text_at(display_,window_,gc_,st,x1_+8,y1_+14,name_); diff --git a/widgets/components/StockPitchfork/StockPitchfork.h b/widgets/components/StockPitchfork/StockPitchfork.h index f06d876..c47a129 100644 --- a/widgets/components/StockPitchfork/StockPitchfork.h +++ b/widgets/components/StockPitchfork/StockPitchfork.h @@ -138,15 +138,23 @@ public: auto Y=[&](double v){ return y_at(v,lo,hi); }; (void)X; (void)Y; (void)px; (void)py; (void)pw; (void)ph; - int x0=X(anchors_[0].bar), y0=Y(anchors_[0].price), x1=X(anchors_[1].bar), y1=Y(anchors_[1].price), x2=X(anchors_[2].bar), y2=Y(anchors_[2].price); + // Flag 13 (same class as StockParallelChannel): set_anchors() + // leaves only 2 anchors, so anchors_[2] is out of bounds. + // With 2 anchors the fork falls back to a trendline through + // them (the handle line); the tines need the third anchor. + int x0=X(anchors_[0].bar), y0=Y(anchors_[0].price), x1=X(anchors_[1].bar), y1=Y(anchors_[1].price); + bool has_third=anchors_.size()>2; + int x2=has_third?X(anchors_[2].bar):x1, y2=has_third?Y(anchors_[2].price):y1; int mx=(x1+x2)/2, my=(y1+y2)/2; XSetForeground(display_,gc_,acol); xf::set_line_width(display_, gc_, line_width_); XDrawLine(display_,window_,gc_,x0,y0,px+pw,my+(px+pw-x0)*(my-y0)/std::max(1,mx-x0)); xf::set_line_width(display_,gc_,1); set_dash(true); - XDrawLine(display_,window_,gc_,x1,y1,px+pw,y1+(px+pw-x1)*(my-y0)/std::max(1,mx-x0)); - XDrawLine(display_,window_,gc_,x2,y2,px+pw,y2+(px+pw-x2)*(my-y0)/std::max(1,mx-x0)); + if (has_third) { + XDrawLine(display_,window_,gc_,x1,y1,px+pw,y1+(px+pw-x1)*(my-y0)/std::max(1,mx-x0)); + XDrawLine(display_,window_,gc_,x2,y2,px+pw,y2+(px+pw-x2)*(my-y0)/std::max(1,mx-x0)); + } set_dash(false); - for (int i=0;i<3;++i){ int cx=X(anchors_[i].bar), cy=Y(anchors_[i].price); XFillArc(display_,window_,gc_,cx-4,cy-4,8,8,0,360*64); } + for (int i=0;i<3 && i<(int)anchors_.size();++i){ int cx=X(anchors_[i].bar), cy=Y(anchors_[i].price); XFillArc(display_,window_,gc_,cx-4,cy-4,8,8,0,360*64); } XSetForeground(display_,gc_,axis_col); XDrawRectangle(display_,window_,gc_,px,py,pw,ph); XSetForeground(display_,gc_,st.lineColor_); XDrawRectangle(display_,window_,gc_,x1_,y1_,width(),height()); xf::draw_text_at(display_,window_,gc_,st,x1_+8,y1_+14,name_);