Results 1 to 20 of 34

Thread: Technical indicators over trading curves

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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
    Setting QwtScaleEngine::Inverted and setAxisScale( 10, 0 ) works good for me, but QwtPlotRescaler doesn't respect the invert.
    I got QwtPlotRescaler working with an my inverted plot:
    Qt Code:
    1. m_rescaler = new QwtPlotRescaler( canvas() );
    2. m_rescaler->setReferenceAxis( QwtPlot::xBottom );
    3. m_rescaler->setRescalePolicy( QwtPlotRescaler::Expanding );
    4. m_rescaler->setEnabled(true);
    5. m_rescaler->setExpandingDirection( QwtPlot::yRight, QwtPlotRescaler::ExpandBoth );
    6. m_rescaler->setAspectRatio( QwtPlot::yRight, 0.0 );
    To copy to clipboard, switch view to plain text mode 

    I only had to change
    Qt Code:
    1. m_rescaler->setExpandingDirection( QwtPlot::xBottom, QwtPlotRescaler::ExpandDown );
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. m_rescaler->setExpandingDirection( QwtPlot::yRight, QwtPlotRescaler::ExpandBoth );
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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

    So my candlestick plot now uses QwtPlotRescaler and QwtPlotPanner, when panning on a rescaled chart the y axis doesn't update to visible samples only (like this 2012-12-06_19h30_32.jpg) but I would like it to rescale on every pan (like this 2012-12-06_19h31_26.jpg). This is my current working code
    Qt Code:
    1. if( !axisAutoScale(yRight) )
    2. {
    3. double min, max, begin, end;
    4.  
    5. begin = qMin( axisScaleDiv(xBottom).lowerBound(), axisScaleDiv(xBottom).upperBound() );
    6. end = qMax( axisScaleDiv(xBottom).lowerBound(), axisScaleDiv(xBottom).upperBound() );
    7.  
    8. if( begin < 0 )
    9. begin = 0;
    10. if( end < 0 )
    11. end = 0;
    12.  
    13. if( m_samples.size() < end )
    14. end = m_samples.size() - 1;
    15.  
    16. if(!includeWeekends())
    17. {
    18. min = m_samples.at(begin).low;
    19. max = m_samples.at(begin).high;
    20. }
    21. else
    22. {
    23. min = m_openCandle.at(begin).low;
    24. max = m_openCandle.at(begin).high;
    25. }
    26.  
    27. for ( int i = begin + 1; i <= end; i++ )
    28. {
    29. min = qMin( min, m_samples.at(i).low );
    30. max = qMax( max, m_samples.at(i).high );
    31. }
    32. setAxisScale(yRight, min, max);
    33. }
    To copy to clipboard, switch view to plain text mode 

    This code seems to work okay, but I'm thinking this requirement is common and may be build in to Qwt already? I though it was QwtScaleEngine::Floating but that didn't have any effect.

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    Autoscaling and a fixed aspect ratio ( = QwtPlotRescaler ) are contradictory requirements !

    What would you expect to happen after panning: shrinking the y axis to the boundaries of the visible area and adjusting the range of the x axis somehow according to the aspect ratio ?

    Uwe

  4. #4
    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
    Autoscaling and a fixed aspect ratio ( = QwtPlotRescaler ) are contradictory requirements !
    QwtPlotRescaler is being used to make the x axis longer or shorter keeping the candle width and only changing the amount of candles displayed (keeping the index used for the last candle in view). Making a window/plot taller has no effect on x axis but makes the candles (on y axis) taller, making a window wider show more time, and only effects y if the samples brought into view are outside of the y axis bounds, the y bounds are set to the lowest low and highest high or the visible samples.

    Quote Originally Posted by Uwe View Post
    What would you expect to happen after panning: shrinking the y axis to the boundaries of the visible area and adjusting the range of the x axis somehow according to the aspect ratio ?
    QwtPlorPanner is being used to pan back and forwards in time (left and right). Adjusting y axis to high low bounds of visible samples when required.

    This is the behavior I've implemented and it works, it just redraws the chart twice I want to get this down to once.

    So I think I need to subclass QwtPlotRescaler and QwtPlotPanner, look up the samples highs and lows in between the x axis upper/lower bounds. Then change the plot->setAxisScale() call for y axis in QwtPlotRescaler::updateScales() and QwtPlotPanner::moveCanvas() with the visible samples y bounds.

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Technical indicators over trading curves

    I guess overloading QwtPlotPanner::moveCanvas() is enough.

    The rescaler is an event filter for resize events of the canvas, that will happen after a replot that has an effect on the layout ( f.e. because of tick label modifications ). To avoid flickering I would disable the rescaler until the panner has done its job. But as the resulting resizeEvent happens asynchronously this is not right after the replot of the panner !

    Don't forget to recalculate and assign the new aspect ratio for the rescaler for the new situation after panning.

    Uwe

  6. #6
    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

    I've now got TA-Lib abstract interface integrated nicely and outputting to Qwt.

    In the screenshot attached the lime triangles are output from one of TA-Libs pattern recognition functions, instead of plotting a symbol for some of the other patterns I may want to draw the candles differently. Can individual candles be targeted/styled differently, or should i use a separate [overlaid] curve for each style.
    2013-01-07_14h01_04.jpg
    Also, the horizontal lines currently have the labels on the canvas, I would like to have them overlapping (in a solid background box) over the labels on the axis, and have them movable [mouse drag], Is this something QwtWidgetOverlay is used for?

    I would also like the candles width to be the same pixel size on any window size, I've tried numbers from the canvas like:
    Qt Code:
    1. setAxisScale(xBottom, canvas()->contentsRect().width() / 5.0, 0);
    To copy to clipboard, switch view to plain text mode 
    So if that code was run on a canvas with width 100px, 100 / 5 = 20 candles visible, if run on 50px canvas, 50 / 5 = 10 candles visible.
    Is they any other numbers, or functions that I can use. I also tried setSymBolWidth() but the candles overlapped. Also after the initial plot I have resizing the window properly working, its just the initial setAxisScale().

    Thanks

  7. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 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
    Can individual candles be targeted/styled differently, or should i use a separate [overlaid] curve for each style.
    You can use QwtPlotTradingCurve::UserSymbol and implement YourTradingCurve::drawUserSymbol().

    After checking this hook I decided to extend the API of drawUserSymbol() and also added methods for drawing a candlestick or bar to the public API, so that they can be used as fallback. These modifications have been made in SVN trunk and will be part of Qwt 6.1.0.

    Also, the horizontal lines currently have the labels on the canvas, I would like to have them overlapping (in a solid background box) over the labels on the axis, and have them movable [mouse drag], Is this something QwtWidgetOverlay is used for?
    Yes, have a look at the itemeditor example.

    In your case you don't hide/show the item ( = trading curve ) while dragging the symbol, instead you remove/insert the sample you are moving from the data.

    I would also like the candles width to be the same pixel size on any window size, ...
    You can limit the width of the candles by setMinSymbolWidth()/setMaxSymbolWidth(). When min and max are the same value the width is fixed. Of course you can't have a fixed height.

    Did you try the new QwtDateScaleEngine - I would be interested in having some feedback before Qwt 6.1 final is out.

    Uwe

  8. #8
    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

    Yes, have a look at the itemeditor example.
    Thats a nifty example, Is QwtWidgetOverlay now the recommended method for adding most non-curve items now?, like shapes, labels, and everything that doesn't need to be redrawn when a replot happens?

    You can limit the width of the candles by setMinSymbolWidth()/setMaxSymbolWidth(). When min and max are the same value the width is fixed.
    The symbol width isn't affecting the number of candles, I think I need to set a fixed interval width, which would make the candles appear to have a fixed width (I think).

    Did you try the new QwtDateScaleEngine - I would be interested in having some feedback before Qwt 6.1 final is out.
    I read the changelog after my last rebase, and noticed these classes. Unfortunately, I don't actually use dates in the plot any-more, as I didn't want dates without samples being shown, I use an index for x axis and pass around a reference to the samples for the labels.

    I just took a look at the QwtDateScaleEngine docs it mentions "[values] are organised in steps with non constant intervals", so if I'm understanding that correctly I may be able to change back to dates, I will have a closer look.

  9. #9
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 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
    Thats a nifty example, Is QwtWidgetOverlay now the recommended method for adding most non-curve items now?, like shapes, labels, and everything that doesn't need to be redrawn when a replot happens?
    No the other way round - the intention is to avoid replots. Dragging an object on the canvas is a performance requirement: when the object is behind the mouse movement grahical editing becomes unusable soon ( the problem is erasing the previous position of an object - not drawing it on its new position ).

    Note that overlays are only intended for the temporary state while you drag something. They are not part of the scene or the backing store of the canvas and are not seen by classes like QwtPlotPanner or QwtPlotRenderer.

    The technical reason for using an overlay is:


    1. the canvas gets minimal update regions: the previous mask of the overlay only
    2. these regions can be filled from the backing store of the canvas without any replot


    On high end system and scenes without much content you might notice the difference, but on systems with low graphics ( f.e. the raspberry ) or when using remote desktops it might be a difference of usable vs. unaccapatble.

    The symbol width isn't affecting the number of candles, I think I need to set a fixed interval width, which would make the candles appear to have a fixed width (I think). .
    I'm afraid I didn't get the point, but if you want to show less candles depending on the width of the scale interval you could enable QwtPlotItem::ScaleInterest and overload:

    Qt Code:
    1. QwtPlotItem::updateScaleDiv() or QwtSeriesData< T >::setRectOfInterest( )
    To copy to clipboard, switch view to plain text mode 

    I just took a look at the QwtDateScaleEngine docs it mentions "[values] are organised in steps with non constant intervals", so if I'm understanding that correctly I may be able to change back to dates, I will have a closer look.
    Non constant intervals f.e. means that the scale engine might decide to return ticks for the beginning of each month - what is non constant, because the number of days of the months differ. For the requirement of leaving out weekends the situation is the same as with any other scale engine.

    But please have a look - maybe you have an idea how to improve QwtDateScaleEngine with such an option.

    Uwe

  10. #10
    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

    Did you try the new QwtDateScaleEngine - I would be interested in having some feedback before Qwt 6.1 final is out.
    I was able to change back from index based candles to dates in about five small edits. Keeping in mind that my data doesn't have a start or a real end, and weeks are just another time frame, What areas in particular would you like feedback for?

  11. #11
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,318
    Thanked 879 Times in 827 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
    Keeping in mind that my data doesn't have a start or a real end, and weeks are just another time frame, What areas in particular would you like feedback for?
    QwtDateScaleEngine is a collection of several algorithms for the various units of date/time ( milliseconds -> years ). It has to decide which unit to align to for a date/time range and to find reasonable positions for the ticks. For Qt::LocalTime you have additional problems like DST or locale depending issues like the first day of a week: this all sums up to a quite complex class, that hasn't been used - or even tested - much so far.

    When you have a plot where you know the date/time axis you can build your scales manually, but as soon as you need autoscaling or use some sort of navigation ( zooming, panning ... ) QwtDateScaleEngine is the only way to have reasonable scales !

    Uwe

    PS: QwtDateScaleEngine is not for scales that show elapsed time ( f.e. seconds since starting something ). Unfortunately I was too late for such a scale engine, but it is planned to come with Qwt 6.2.

  12. #12
    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
    QwtDateScaleEngine is the only way to have reasonable scales !
    I added in QwtDateScaleEngine, but I haven't quite got the scaling right yet so I don't have any useful comments, I think it will come in handy for the trading analytics portion the my program that I've just started with, or for any aggregate data I suppose. I am using the other Qwt date classes, they have tidied my weekly chart up nicely.

    As am using the pseudo date axis (index based), I've re-implemented all the drawing tools in my program (except markers) to use QwtPlotShapeItem, now I'm adding support to them to rescale themselves when the charts time frame changes. So far I've got rectangle behaving correctly with draw implemented as

    Qt Code:
    1. void PlotShapeItem::draw(
    2. QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &rect) const
    3. {
    4. const QPointF topLeft =
    5. QPointF(xMap.transform(m_leftIndex), yMap.transform(boundingRect().topLeft().y()));
    6. const QPointF bottomRight =
    7. QPointF(xMap.transform(m_rightIndex), yMap.transform(boundingRect().bottomRight().y()));
    8.  
    9. // QTransform t;
    10. p->save();
    11. // p->setTransform(t);
    12. p->fillRect(QRectF(topLeft, bottomRight), brush());
    13. // p->drawPath(shape());
    14. p->restore();
    15. }
    To copy to clipboard, switch view to plain text mode 

    m_leftIndex, and m_rightIndex are values I calculate when the time frame changes, they should match up with x values. I want to add support for transforming the shape(), or QPainterPaths. Is QTransform the way to go hear?, I've tried QTransform::scale() but couldn't get anything accurate;

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.