Abbreviations replacement project:修订间差异

来自BPAX Lab
(创建页面,内容为“import re <nowiki>#</nowiki> 定义替换规则 patterns = [     (r'\bBRB\b', 'bear body'),     (r'\bTTR\b', 'tight trading range'),     (r'\bOB\b', 'outside bar'),     (r'\bIB\b', 'inside bar'),     (r'\bFBO\b', 'failed breakout'),     (r'\bMTR\b', 'major trend reversal'),     (r'\bPW\b', 'parabolic wedge'),     (r'\bL2\b', 'low 2'),     (r'\bHOD\b', 'high of today'),     (r'\bLOD\b', 'low of today'),     (r'\bHPW\b', 'wait f…”)
 
无编辑摘要
 
(未显示另一用户的1个中间版本)
第1行: 第1行:
<syntaxhighlight lang="python3" line="1">
import re
import re


<nowiki>#</nowiki> 定义替换规则


# 定义替换规则
patterns = [
patterns = [
   (r'\bBRB\b', 'bear body'),
   (r'\bTTR\b', 'tight trading range'),
   (r'\bOB\b', 'outside bar'),
   (r'\bIB\b', 'inside bar'),
   (r'\bFBO\b', 'failed breakout'),
   (r'\bMTR\b', 'major trend reversal'),
   (r'\bPW\b', 'parabolic wedge'),
   (r'\bL2\b', 'low 2'),
   (r'\bHOD\b', 'high of today'),
   (r'\bLOD\b', 'low of today'),
   (r'\bHPW\b', 'wait for higher probability'),
   (r'\bBRE2\b', 'bear exit above'),
   (r'\bBRE4\b', 'bear exit above'),
   (r'\bBOP\b', 'breakout point'),
   (r'\bSPBR\b', 'surprise bear bar'),
   (r'\bPP\b', "60% or higher probability"),
   (r'\bS\b', 'bear bar'),
   (r'\bSB\b', 'seller below'),
   (r'\bPS\b', 'lower than 50% probability'),
   (r'\bMGB\b', 'magnet below'),
   (r'\bMMD\b', 'measured move down'),
   (r'\bY\b', 'yesterday'),
   (r'\bBO\b', 'breakout'),
   (r'\bLOY\b', 'low of yesterday'),
   (r'\bREV\b', 'reversal'),
   (r'\bBR\b', 'bears'),
   (r'\bCH\b', 'channel'),
   (r'\bDD\b', 'doji'),
   (r'\bBL\b', 'bulls'),
   (r'\bBRN\b', 'big round number'),
   (r'\bSS\b', 'sell signal'),
   (r'\bBL\b', 'bulls'),
   (r'\bSBDM\b', 'surprise bears dominant major trend'),
   (r'\bSBU\b', 'Surprisingly big bulls'),
   (r'\bPL\b', "50% or lower probability"),
   (r'\bS2\b', "Weak Trader's Equation wait for higher probability sell"),
   (r'\bBL\b', "bulls"),
   (r'\bSC\b', 'spike and channel'),
   (r'\bPTG\b', 'profit taking'),
   (r'\bBRTP\b', 'bear trap, failed bear breakout'),
   (r'\bSTC\b', 'sell the close'),
   (r'\bMRV\b', 'minor reversal '),
   (r'\bBUDC\b', 'BUDC 60% probability of trading range'),
   (r'\bNS\b', 'Not high enough probability for stop entry traders to scalp'),
   (r'\bMBO\b', 'Minor Breakout, 60% will last 1-5 bars'),
   (r'\bNWS\b', "need wide stop"),
   (r'\bBBRBC\b', "big bear bar Closing near its low"),
   (r'\bBRCH\b', "bear channel"),
   (r'\bNWS\b', "need wide stop"),
   (r'\bBB\b', "buyer below"),
#  (r'\b\b', ""),
   (r'\bTGT\b', "target"),
   (r'\bBR\b', "bears"),
   (r'\bSP\b', "support"),
   (r'\bTR\b', "trading range"),
   (r'\bSCBR\b', "Spike and Channel Bear Trend, at least 2 legs down, often in a wedge bottom"),
   (r'\bSPBR\b', "Small PullBack Bear trend. Most pullbacks are small and only last 1 or 2 bars. 60% or higher probability sellers above prior bar."),
   (r'\bW\b', "wedge,or anything similar, like any 3 push pattern"),
   (r'\bREVU\b', "reversal up"),
   (r'\bBLD\b', "bull doji"),
   (r'\bMW\b', "micro Wedge, a wedge formed by only 3 - 4 bars"),
   (r'\bMDRU\b', "Midday reversal up is a bull trend reversal in the middle of the day, sometimes exactly at bar 40 or 41, and sometimes leads to bull trend for rest of day"),


    (r'\bBRB\b', 'bear body'),


    (r'\bTTR\b', 'tight trading range'),
    (r'\bOB\b', 'outside bar'),
    (r'\bIB\b', 'inside bar'),
    (r'\bFBO\b', 'failed breakout'),
    (r'\bMTR\b', 'major trend reversal'),
    (r'\bPW\b', 'parabolic wedge'),
    (r'\bL2\b', 'low 2'),
    (r'\bHOD\b', 'high of today'),
    (r'\bLOD\b', 'low of today'),
    (r'\bHPW\b', 'wait for higher probability'),
    (r'\bBRE\b', 'bear exit above'),
    (r'\bBOP\b', 'breakout point'),
    (r'\bSPBR\b', 'surprise bear bar'),
    (r'\bPP\b', '60% or higher probability'),
    (r'\bS\b', 'bear bar'),
    (r'\bSB\b', 'seller below'),
    (r'\bPS\b', 'lower than 50% probability'),
    (r'\bMGB\b', 'magnet below'),
    (r'\bMMD\b', 'measured move down'),
    (r'\bY\b', 'yesterday'),
    (r'\bBO\b', 'breakout'),
    (r'\bLOY\b', 'low of yesterday'),
    (r'\bREV\b', 'reversal'),
    (r'\bBR\b', 'bears'),
    (r'\bCH\b', 'channel'),
    (r'\bDD\b', 'doji'),
    (r'\bBL\b', 'bulls'),
    (r'\bBRN\b', 'big round number')


]
]


<nowiki>#</nowiki> 打开文件A.txt并读取内容
# 打开文件A.txt并读取内容
 
with open('A.txt', 'r') as file:
with open('A.txt', 'r') as file:
   data = file.read()


    data = file.read()
# 替换指定字符串
 
<nowiki>#</nowiki> 替换指定字符串
 
for pattern, replacement in patterns:
for pattern, replacement in patterns:
   data = re.sub(pattern, replacement, data)


    data = re.sub(pattern, replacement, data)
# 将结果写入文件B.txt
 
<nowiki>#</nowiki> 将结果写入文件B.txt
 
with open('B.txt', 'w') as file:
with open('B.txt', 'w') as file:
 
   file.write(data)
    file.write(data)
</syntaxhighlight>
[[分类:Automation]]

2023年3月29日 (三) 13:07的最新版本

import re


# 定义替换规则
patterns = [
    (r'\bBRB\b', 'bear body'),
    (r'\bTTR\b', 'tight trading range'),
    (r'\bOB\b', 'outside bar'),
    (r'\bIB\b', 'inside bar'),
    (r'\bFBO\b', 'failed breakout'),
    (r'\bMTR\b', 'major trend reversal'),
    (r'\bPW\b', 'parabolic wedge'),
    (r'\bL2\b', 'low 2'),
    (r'\bHOD\b', 'high of today'),
    (r'\bLOD\b', 'low of today'),
    (r'\bHPW\b', 'wait for higher probability'),
    (r'\bBRE2\b', 'bear exit above'),
    (r'\bBRE4\b', 'bear exit above'),
    (r'\bBOP\b', 'breakout point'),
    (r'\bSPBR\b', 'surprise bear bar'),
    (r'\bPP\b', "60% or higher probability"),
    (r'\bS\b', 'bear bar'),
    (r'\bSB\b', 'seller below'),
    (r'\bPS\b', 'lower than 50% probability'),
    (r'\bMGB\b', 'magnet below'),
    (r'\bMMD\b', 'measured move down'),
    (r'\bY\b', 'yesterday'),
    (r'\bBO\b', 'breakout'),
    (r'\bLOY\b', 'low of yesterday'),
    (r'\bREV\b', 'reversal'),
    (r'\bBR\b', 'bears'),
    (r'\bCH\b', 'channel'),
    (r'\bDD\b', 'doji'),
    (r'\bBL\b', 'bulls'),
    (r'\bBRN\b', 'big round number'),
    (r'\bSS\b', 'sell signal'),
    (r'\bBL\b', 'bulls'),
    (r'\bSBDM\b', 'surprise bears dominant major trend'),
    (r'\bSBU\b', 'Surprisingly big bulls'),
    (r'\bPL\b', "50% or lower probability"),
    (r'\bS2\b', "Weak Trader's Equation wait for higher probability sell"),
    (r'\bBL\b', "bulls"),
    (r'\bSC\b', 'spike and channel'),
    (r'\bPTG\b', 'profit taking'),
    (r'\bBRTP\b', 'bear trap, failed bear breakout'),
    (r'\bSTC\b', 'sell the close'),
    (r'\bMRV\b', 'minor reversal '),
    (r'\bBUDC\b', 'BUDC 60% probability of trading range'),
    (r'\bNS\b', 'Not high enough probability for stop entry traders to scalp'),
    (r'\bMBO\b', 'Minor Breakout, 60% will last 1-5 bars'),
    (r'\bNWS\b', "need wide stop"),
    (r'\bBBRBC\b', "big bear bar Closing near its low"),
    (r'\bBRCH\b', "bear channel"),
    (r'\bNWS\b', "need wide stop"),
    (r'\bBB\b', "buyer below"),
 #   (r'\b\b', ""),
    (r'\bTGT\b', "target"),
    (r'\bBR\b', "bears"),
    (r'\bSP\b', "support"),
    (r'\bTR\b', "trading range"),
    (r'\bSCBR\b', "Spike and Channel Bear Trend, at least 2 legs down, often in a wedge bottom"),
    (r'\bSPBR\b', "Small PullBack Bear trend. Most pullbacks are small and only last 1 or 2 bars. 60% or higher probability sellers above prior bar."),
    (r'\bW\b', "wedge,or anything similar, like any 3 push pattern"),
    (r'\bREVU\b', "reversal up"),
    (r'\bBLD\b', "bull doji"),
    (r'\bMW\b', "micro Wedge, a wedge formed by only 3 - 4 bars"),
    (r'\bMDRU\b', "Midday reversal up is a bull trend reversal in the middle of the day, sometimes exactly at bar 40 or 41, and sometimes leads to bull trend for rest of day"),



]

# 打开文件A.txt并读取内容
with open('A.txt', 'r') as file:
    data = file.read()

# 替换指定字符串
for pattern, replacement in patterns:
    data = re.sub(pattern, replacement, data)

# 将结果写入文件B.txt
with open('B.txt', 'w') as file:
    file.write(data)