编写一个这样的程序,满足五日均线,十日均线,二十日均线,六十天六日均线调头向上的选股代码

cf01a49e2eb147dd98eb4fc102ad0224.jpg

 

编写一个这样的程序,满足五日均线,十日均线,二十日均线,六十天六日均线调头向上的选股代码

以下是一个用C语言编写的程序,可以读取股票数据并筛选出满足条件的股票。程序使用了一个假设的股票数据文件格式,文件名为"stock_data.csv",其中包含一列名为"close"的收盘价数据。

#include <stdio.h>
#include <stdlib.h>
#define MAX_ROWS 1000 // 假设数据文件最多有1000行
int main() {
    FILE *fp;
    char filename[100];
    char line[MAX_ROWS][100];
    double close_prices[MAX_ROWS];
    int ma5[6] = {0, 0, 0, 0, 0, 0}; // 五日移动平均线
    int ma10[6] = {0, 0, 0, 0, 0, 0}; // 十日移动平均线
    int ma20[6] = {0, 0, 0, 0, 0, 0}; // 二十日移动平均线
    int ma60[6] = {0, 0, 0, 0, 0, 0}; // 六十日六日移动平均线
    int i, j, k;
    // 读取股票数据文件
    sprintf(filename, "stock_data.csv");
    fp = fopen(filename, "r");
    if (fp == NULL) {
        printf("Failed to open file %s\n", filename);
        return 1;
    }
    for (i = 0; i < MAX_ROWS; i++) {
        fgets(line[i], sizeof(line[i]), fp);
        sscanf(line[i], "%lf", &close_prices[i]);
    }
    fclose(fp);
    // 计算移动平均线
    for (i = 4; i < MAX_ROWS; i++) {
        ma5[5] = ma5[4];
        ma5[4] = ma5[3];
        ma5[3] = ma5[2];
        ma5[2] = ma5[1];
        ma5[1] = close_prices[i];
        ma5[0] = (ma5[1] + ma5[2] + ma5[3] + ma5[4] + ma5[5]) / 5;
        ma10[5] = ma10[4];
        ma10[4] = ma10[3];
        ma10[3] = ma10[2];
        ma10[2] = ma10[1];
        ma10[1] = close_prices[i];
        ma10[0] = (ma10[1] + ma10[2] + ma10[3] + ma10[4] + ma10[5]) / 5;
        ma20[5] = ma20[4];
        ma20[4] = ma20[3];
        ma20[3] = ma20[2];
        ma20[2] = ma20[1];
        ma20[1] = close_prices[i];
        ma20[0] = (ma20[1] + ma20[2] + ma20[3] + ma20[4] + ma20[5]) / 5;
        ma60[5] = ma60[4];
        ma60[4] = ma60[3];
        ma60[3] = ma60[2];
        ma60[2] = ma60[1];
        ma60[1] = close_prices[i];
        ma60[0] = (ma60[1] + ma60[2] + ma60[3] + ma60[4] + ma60[5]) / 6;
    }
    // 筛选满足条件的股票
    int count = 0;
    for (i = 4; i < MAX_ROWS - 5; i++) {
        if (close_prices[i] < ma5[0]) continue; // 五日均线调头向上
        if (close_prices[i] < ma10[0]) continue; // 十日均线
 

今天就分享这里,需要的朋友拿去自用

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清泉-通达信编程专家-苏大毕业

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值