@@ -12,6 +12,8 @@ class ColorTheme:
1212 down_candle = red
1313 wick = white
1414 text = white
15+ buy = green
16+ sell = red
1517
1618class PygameRender :
1719 def __init__ (
@@ -127,7 +129,33 @@ def render(self, info: dict):
127129 # Draw candlestick body
128130 self .pygame .draw .rect (canvas , candle_color , (candle_offset , candle_body_y , self .candle_width , candle_body_height ))
129131
132+ # Compare with previous state to determine whether buy or sell action was taken and draw arrow
133+ index = self ._states .index (state )
134+ if index > 0 :
135+ last_state = self ._states [index - 1 ]
136+ if last_state .allocation_percentage < state .allocation_percentage :
137+ # buy
138+ self .pygame .draw .polygon (canvas , self .color_theme .buy , [
139+ (candle_offset + self .candle_width // 2 , candle_y_low + 10 ),
140+ (candle_offset + self .candle_width // 2 - 5 , candle_y_low + 20 ),
141+ (candle_offset + self .candle_width // 2 + 5 , candle_y_low + 20 )
142+ ])
143+ elif last_state .allocation_percentage > state .allocation_percentage :
144+ # sell
145+ self .pygame .draw .polygon (canvas , self .color_theme .sell , [
146+ (candle_offset + self .candle_width // 2 , candle_y_high - 10 ),
147+ (candle_offset + self .candle_width // 2 - 5 , candle_y_high - 20 ),
148+ (candle_offset + self .candle_width // 2 + 5 , candle_y_high - 20 )
149+ ])
150+
130151 # Move to the next candle
131152 candle_offset += self .candle_width + self .candle_spacing
132153
154+ # Draw max and min ohlc values on the chart
155+ font = self .pygame .font .SysFont ('Noto Sans' , 15 )
156+ label_y_low = font .render (str (max_low ), True , self .color_theme .text )
157+ label_y_high = font .render (str (max_high ), True , self .color_theme .text )
158+ canvas .blit (label_y_low , (self .candle_spacing + 5 , self .chart_height + 35 ))
159+ canvas .blit (label_y_high , (self .candle_spacing + 5 , 5 ))
160+
133161 return canvas
0 commit comments