# Zhejiang University PTA basic programming topic set: 7-13 K candle chart

### Zhejiang University PTA < basic programming topic set >: 7-13 K candle chart

Topic content
The trend of stock price rise and fall is usually represented by K-line chart in candle chart technology, which is divided into daily K-line, weekly K-line and monthly K-line. Take the daily K-line as an example. Every day, the stock price goes from the opening to the closing one day, corresponding to a small candle chart, which represents four prices: the opening price Open (the first price of the opening transaction just in the morning), the closing price Close (the last price of the closing transaction in the afternoon), the highest price in the middle and the lowest price Low.

If Close < Open, it means BW solid; if Close > Open, it means R-Hollow; if Open equals Close, it means R-Cross. If Low is lower than Open and Close, it is called "Lower Shadow" (i.e. with Lower Shadow), and if High is higher than Open and Close, it is called "Upper Shadow" (i.e. with Upper Shadow). Please program, according to the given four price combinations, to determine what kind of candle the day is.

Input format
Input four positive real numbers in a row, corresponding to Open, High, Low and Close, separated by spaces.

Output format
Output the type of day K candle in one line. If there are up and down hatches, add with hatches after the type. If there are both hatches, output with Lower Shadow and Upper Shadow.

Input sample 1

5.110 5.250 5.100 5.105

Output sample 1

Input example 2

5.110 5.110 5.110 5.110

Output sample 2

R-Cross

Input example 3

5.110 5.125 5.112 5.126

Output example 3

R-Hollow

Code 1: C language
It's only a third right

```#include "stdio.h"
int main(){
double Open, High, Low, Close;
scanf("%f %f %f %f",&Open,&High,&Low,&Close);
if (Close < Open)  {
if (Low < Open && Low < Close)  {
if (High > Open && High > Close)
}
else if (High > Open && High > Close)  printf("BW-Solid with Upper Shadow");
else  printf("BW-Solid");
}

else if (Close > Open){
if (Low < Open && Low < Close)  {
if (High > Open && High > Close)
}
else if (High > Open && High > Close)  {
}
else printf("R-Hollow");
}

else if (Close == Open) {
if (Low < Open && Low < Close)  {
if (High > Open && High > Close)
}
else if (High > Open && High > Close)  printf("R-Cross with Upper Shadow");
else printf("R-Cross");
}
return 0;
}
```

Code 2: Python
This is right

```# -*- coding: utf-8 -*-
Open, High, Low, Close = input().split()
Open = eval(Open)
High = eval(High)
Low = eval(Low)
Close = eval(Close)
if Close < Open:
if Low < Open and Low < Close:
if High > Open and High > Close:
else:
elif High > Open and High > Close:
else:
print("BW-Solid")

elif Close > Open:
if Low < Open and Low < Close:
if High > Open and High > Close:
else:
elif High > Open and High > Close:
else:
print("R-Hollow")

elif Close == Open:
if Low < Open and Low < Close:
if High > Open and High > Close:
else:
elif High > Open and High > Close:
else:
print("R-Cross")
```
Published 11 original articles, praised 0, visited 40

Keywords: Programming Python C

Added by IronWarrior on Sat, 01 Feb 2020 15:46:03 +0200