Page 2 of 2 FirstFirst 12
Results 21 to 34 of 34

Thread: Technical indicators over trading curves

  1. #21
    Join Date
    Nov 2012
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Quote Originally Posted by Seamus View Post
    Is QTransform the way to go hear?
    I think I will just use a factory class, and recreate the shape at the desired size (outside of draw()) instead of QTransforming the the current shape().

  2. #22
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    What exactly do you want to do with the coordinates of the painter path of your shape items ?

    Uwe

  3. #23
    Join Date
    Nov 2012
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Quote Originally Posted by Uwe View Post
    What exactly do you want to do with the coordinates of the painter path of your shape items ?
    Horizontal scaling of the shape.

    For instance, a 15 minute chart has a rectangle drawn at 10:15 to 10:45 (spanning 2 bars), when the time frame is changed to a 1 hour chart the rectangle is drawn only on one bar. I have already implemented axis/index<->date conversion calculations, and they are working good with a subclass of QwtPlotMarker, just had to add a invalidateCache() that re-index the markers, and a custom setValue() was enough.

    Shapes (and QwtPlotShapeItem) don't have setters for left/right/x. I looked into QTransform and got the m11 scaling right, but couldn't get the translation to accurately place the item, I stopped looking at QTransform as it requires a QPainter (probably?) and re-applying the QTransform in a custom draw() is probably a bit heavy.

    I may have to iterate over all elements in the shape and scale their x manually. The most elegant solution is probably to subclass QwtScaleMap.

    Basically I would like to set the equivalent of boundingRect().left() and boundingRect().right() on the shape.
    --
    For those interested the m11 calculation that was working for me (I think) was
    Qt Code:
    1. double m11 = m_rightIndex - m_leftIndex / shape().controlPointRect().right() - shape().controlPointRect().left()
    To copy to clipboard, switch view to plain text mode 

  4. #24
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    The points of the painter path of a shape item are always in plot coordinates. If you don't want this QwtPlotShapeItem is probably the wrong type of item. Maybe a marker/curve with QwtSymbol::Path symbols ( or QwtSymbol::Graphic when you need symbols with different colors ) is what you are looking for ?

    Uwe

  5. #25
    Join Date
    Nov 2012
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Quote Originally Posted by Uwe View Post
    Maybe a marker/curve with QwtSymbol::Path symbols ( or QwtSymbol::Graphic when you need symbols with different colors ) is what you are looking for ?
    I got QwtPlotShapeItem to do what I required after looking at the QwtSymbol::setPath() example. I only had to add this:
    Qt Code:
    1. void PlotShapeItem::invalidateCache()
    2. {
    3. if(! m_xScaleDraw)
    4. return;
    5.  
    6. m_leftIndex = m_xScaleDraw->indexOf(m_leftDate, true);
    7. m_rightIndex = m_xScaleDraw->indexOf(m_rightDate, true);
    8.  
    9. QPainterPath pp = m_path.translated(0, 0);
    10.  
    11. // Scale transform
    12. double w = m_rightIndex - m_leftIndex;
    13. double m11;
    14. if (w > 0)
    15. m11 = w / (int)(m_path.controlPointRect().width() + 0.5);
    16. else
    17. m11 = 0;
    18.  
    19. QTransform t(m11, 0, 0, 1.0, 0, 0);
    20. pp = t.map(pp);
    21.  
    22. // Translate transform
    23. double dx = m_leftIndex - (int)(pp.controlPointRect().left() + 0.5);
    24. QTransform ts(1, 0, 0, 1, dx, 0);
    25. pp = ts.map(pp);
    26.  
    27. setShape(pp);
    28. }
    To copy to clipboard, switch view to plain text mode 
    This is called only when the charts/samples time frame changes, I chose to use QwtPlotShapeItem as it didn't require modification to my plot item editor. It also automatically shifts the shape as new candles come in from the server.
    Results look like this (note - these are shapes not rectangles):
    5m.jpg1m.jpg

    I will take a closer look at QwtGraphic and QwtPlotSvgItem, as I would like the user to be able to load custom analysis/shapes.
    Last edited by Seamus; 24th January 2013 at 04:28.

  6. #26
    Join Date
    Nov 2012
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Issue with QwtSymbol::setPinPoint()?
    I create a QPainterPath and add it to a QwtSymbol, then to a QwtPlotMarker. The path draws Fibonacci retracement and extension levels, the extension levels also go beyond the area selected by a user with a QwtPicker, so I have used QwtSymbol::setPinPoint(). Here are the results:
    fib-pin-point.jpg
    The fib control lines are the angled black lines, they were drawn from the upper blue line to the lower blue line. When setPinPoint() is used a portion of the left side is cut off, the extent of the cut off area gets larger as you get closer to y-axis (yRight), the text also gets cut. It also looks like if you draw a line connecting the black lines tops that the cut-off area increases smoothly.

    When I don't use setPinPoint(), the path is drawn properly (except its position).

    Has anybody out-there experienced this?

  7. #27
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Please upload a small demo showing the effects.

    Uwe

  8. #28
    Join Date
    Nov 2012
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Quote Originally Posted by Uwe View Post
    Please upload a small demo showing the effects.
    markerPinPointDemo.jpg
    Effect most evident in the rightmost numbers 50.00 and 90.00, but the most important part for me is the missing line start.
    Qt Code:
    1. void TechnicalAnalysisPlot::markerPinPointDemo(const QPointF &topLeft, const QPointF &bottomRight)
    2. {
    3. const QwtScaleMap xMap = axisScaleDraw(xBottom)->scaleMap();
    4. const QwtScaleMap yMap = axisScaleDraw(yRight)->scaleMap();
    5.  
    6. const QPointF topLeft0 = QwtScaleMap::transform(xMap, yMap, topLeft);
    7. const QPointF bottomRight0 = QwtScaleMap::transform(xMap, yMap, bottomRight);
    8.  
    9. path.moveTo(topLeft0);
    10. path.lineTo(bottomRight0);
    11.  
    12. const QPointF pinPoint0 = path.pointAtPercent(0.50);
    13.  
    14. const QVector<double> levels = QVector<double>() << 0.1 << 0.5 << 0.9 << 1.2 << 1.4;
    15.  
    16. const double left = topLeft0.x();
    17. const double right = bottomRight0.x();
    18. const double top = topLeft0.y();
    19. const double height = bottomRight0.y() - topLeft0.y();
    20.  
    21. QFont font;
    22. font.setPointSize(24);
    23.  
    24. foreach(const double f, levels)
    25. {
    26. const double level = top + (height * f);
    27. path.moveTo(left, level);
    28. path.lineTo(right, level);
    29. path.addText(left, level, font, QString::number(f * 100, 'f', 2));
    30. }
    31.  
    32. QwtSymbol *symbol = new QwtSymbol(QwtSymbol::Path);
    33. symbol->setPath(path);
    34. symbol->setPen(QPen(Qt::red));
    35. symbol->setPinPoint(pinPoint0);
    36.  
    37. // Center of picked area
    38. const QPointF center = topLeft + ((bottomRight - topLeft) * 0.5);
    39.  
    40. marker->setAxes(xBottom, yRight);
    41. marker->setValue(center);
    42. marker->setSymbol(symbol);
    43. marker->attach(this);
    44.  
    45. autoRefresh();
    46. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Seamus; 28th January 2013 at 08:09.

  9. #29
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Please attach a compilable project - not only a code snippet.

    Uwe

    PS: what happens when you set QwtSymbol::NoCache ?

  10. #30
    Join Date
    Nov 2012
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    PS: what happens when you set QwtSymbol::NoCache ?
    QwtSymbol::NoCache rectified the issue.

    Quote Originally Posted by Uwe View Post
    Please attach a compilable project - not only a code snippet.
    I suppose you don't need this anymore.

    Spotted this though:
    Qt Code:
    1. void QwtPlotShapeItem::setShape( const QPainterPath &shape )
    2. {
    3. if ( shape != d_data->shape )
    4. {
    5. d_data->shape = shape;
    6. if ( shape.isEmpty() )
    7. {
    8. d_data->boundingRect == QwtPlotItem::boundingRect();
    9. // ^ Comparison not assignment
    10. }
    11. else
    12. {
    13. d_data->boundingRect = shape.boundingRect();
    14. }
    15.  
    16. itemChanged();
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

  11. #31
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Quote Originally Posted by Seamus View Post
    QwtSymbol::NoCache rectified the issue.
    What probably means, that the result of QwtSymbol::boundingRect() is wrong. To be honest I never tried painter paths with texts inside, so there might be something wrong in general with them.

    That's why I'm still interested in understanding the effect - even if you have a workaround for your situation.

    Uwe

  12. #32
    Join Date
    Nov 2012
    Posts
    34
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Quote Originally Posted by Uwe View Post
    What probably means, that the result of QwtSymbol::boundingRect() is wrong.
    The snippet "Comparison not assignment" was for QwtPlotShapeItem, not QwtSymbol.

    That's why I'm still interested in understanding the effect - even if you have a workaround for your situation.
    Attachments: Modified stockchart demo showing the problem, image of the demo too.
    stockchart-marker.tar.gzstockchart-marker.jpg
    In the code left may be right and right may be left, as the demo does most things opposite to how I've done them

    To be honest I never tried painter paths with texts inside, so there might be something wrong in general with them.
    I also don't use text in painter paths (with markers) as the pen width makes it unreadable at most desired font sizes.

  13. #33
    Join Date
    Dec 2013
    Posts
    7
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Hi,

    I have just started to use qwt for a trading software and I'm stuck doing the (probably) simplest things. Now I stumbled upon this very informative thread and wanted to ask, if the application you, Seamus, are working on is open source or if not, would you share just the drawing/gui part?
    There seem to be quite a lot of programmers that are interested in creating a decent open source trading platform (like qttrader.com or some posts in this forum suggest) and QT/qwt seems to be the way to do it. Maybe we should join forces?

  14. #34
    Join Date
    Feb 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Technical indicators over trading curves

    Hi,

    Is there any open source project that plot the stock chart kind of discussed above?
    If not can we have interested people for a project like this.

Similar Threads

  1. Replies: 0
    Last Post: 17th January 2012, 19:24
  2. Replies: 0
    Last Post: 4th April 2011, 16:17
  3. Replies: 0
    Last Post: 1st July 2010, 21:55
  4. Qwt - Qt Widgets for Technical Applications
    By gandalf in forum Newbie
    Replies: 6
    Last Post: 5th May 2010, 15:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.