<jupyter_start><jupyter_text>短期趋势-移动平均指标ma10 指价格上穿ma10的bar数slo10 指ma10的斜率sth 指短期新高(20),lth指长期新高(200) scan criteria1. ma10 出现信号;斜率10大于斜率20（即ma10上穿ma20）;斜率20大于斜率502. ma10 出现信号，sth短期新高信号少于83. ma10,20,50都出现信号4. 现价大于sth短期新高的98%5. 价格在98% - 102% ma200之间(即接近200天均线的股票) column'symbol', 'px', 'macd', 'ma10%', 'ma20%', 'ma50%', 'ma10', 'ma20', 'ma50', 'ma200', 'volra20', 'vol20_sig', 'ma10_sig', 'ma20_sig', 'ma50_sig', 'slo10', 'slo20', 'slo50', 'sth', 'lth', 'stl', 'ltl', 'lth_sig', 'sth_sig', 'ltl_sig', 'stl_sig' sort1. ma10_sig, 升序2. ma50_sig, 升序'sort': [{'ma10_sig': 'True'}, {'ma50_sig': 'True'}]}  加载扫描规则 feeder type'IB1D','IB1H','IB1D5Y'<jupyter_code>cfg = """{
  "desc": "扫描规则",
  "feeder": {
    "type": "normal",
    "name": "ib1d",
    "start": "",
    "end": "",
    "path": "./cache_example/"
  },
  "algo":[
    {
      "name":"macd",
      "param":{}
    },
    {
      "name":"nhnl",
      "param":{
          "pct":"0.99"
       }
    }
  ],
  "criteria_up":[
    "ma10_sig>0",
    "slo10>slo20",
    "slo20>slo50"
  ],
  "criteria_nhnl":[
    "ma10_sig>0",
    "sth_sig<8"
  ],
  "criteria_ma":[
    "ma10_sig>0",
    "ma20_sig>0",
    "ma50_sig>0"
  ],
  "criteria_sth":[
    "px>0.98*sth"
  ],
  "criteria_200":[
    "px>0.98*ma200",
    "px<1.02*ma200"
  ],
  "criteria":[
    "ma10_sig>0",    
    "lth_sig>0"
  ],
  "columns":[
    "symbol","px",
    "macd","ma10%","ma20%","ma50%","ma10","ma20","ma50","ma200","volra20","vol20_sig","ma10_sig","ma20_sig","ma50_sig","slo10","slo20","slo50",
    "sth","lth","stl","ltl","lth_sig","sth_sig","ltl_sig","stl_sig"
  ],
  "sort":[
    {"ma10_sig":"True"},
    {"ma50_sig":"True"}
  ]
}"""
import json
rule=json.loads(cfg)
from tps import common
import algo_main
#g_rule = common.load_rule_file('config/trend.json')<jupyter_output><empty_output><jupyter_text>扫描<jupyter_code>ret=algo_main.main(rule,'symbol_ib.txt')<jupyter_output>run_strategy    symbol sectype exchange  priexg currency      info
0    AAPL     STK    SMART              USD          
1    AMZN     STK    SMART              USD          
2    MSFT     STK    SMART  NASDAQ      USD          
3   GOOGL     STK    SMART              USD          
4      FB     STK    SMART              USD          
5    ADBE     STK    SMART              USD          
6     CRM     STK    SMART              USD          
7    NFLX     STK    SMART              USD  internet
8    TSLA     STK    SMART              USD          
9    BABA     STK    SMART              USD          
10   NTES     STK    SMART              USD          
11   BIDU     STK    SMART              USD     china
12     SE     STK    SMART              USD     china
13   NVDA     STK    SMART              USD          
14   AVGO     STK    SMART              USD          
15   INTC     STK    SMART              USD          
16     MU     STK    SMART              USD          
17    SMH     S[...]<jupyter_text>显示设置以grid widget 方式显示<jupyter_code>import qgrid
#qgrid_widget = qgrid.show_grid(ret['raw'],show_toolbar=False,grid_options={'forceFitColumns': False})
qgrid_widget = qgrid.show_grid(ret['raw'],show_toolbar=False)
qgrid_widget
ret['scan']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15895498898331759, 'fraction_numerical': 0.06610009442870633, 'mean_word_length': 2.1434223541048465, 'pattern_counts': {'":': 23, '<': 14, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '89916', 'license': 'Apache-2.0', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1386, 'n_words': 215, 'path': 'Trend0_example.ipynb', 'repo_name': 'softarts/tradebook', 'size': '3177'}