本人觉得用大智慧中的江恩正方实在是太烦了,因为它没有将阻力位(支撑位)的价码明显标识出来,而是要用鼠标一个个点击小方格。出于分析的考虑,就开始尝试用Python实现它,代码部分不用我多说了,大家细细体会便可,或者干脆直接在Python中运行也行。
# Gann_Matrix.py
def GetKeyPositions ():
Ret = []
Ret.append (1)
# left-top corner line
for ix in range (1, 9):
if ix % 2 == 0:
val = ix * ix + 1
Ret.append (val - ix/2)
Ret.append (val)
# rith-bottom corner line
for ix in range (3, 10):
if ix % 2 <> 0:
val = ix * ix
Ret.append (val - ix/2)
Ret.append (ix * ix)
# right-top corner line
for ix in range (1, 8):
if ix % 2 <> 0:
val = (ix + 1)*(ix + 1) - ix
Ret.append (val - (ix + 1)/2)
Ret.append (val)
# left-bottom corner line
for ix in range (1, 9):
if ix % 2 == 0:
val = (ix + 1)*(ix + 1) - ix
Ret.append (val - ix/2)
Ret.append (val)
Ret.sort ()
return Ret

def DisputablePrices (InitVal, Step, Format):
if (InitVal < 0) or (Step < 0):
return
Prices = []
for ix in range (1, 82):
Prices.append (InitVal + (ix-1) * Step)
KeyPos = GetKeyPositions ()
if Format:
PriceStr = ''
for ix in KeyPos:
PriceStr += '%.2f ' % (Prices[ix - 1])
if (KeyPos.index (ix) + 1) % 8 == 0:
PriceStr += ' '
print '%s %s' % ('[Prices]', PriceStr)
else:
for ix in KeyPos: print Prices[ix - 1]
print '%s InitValue = %f; Step = %f; RecordCount = %d' %
('[Params]', InitVal, Step, len (KeyPos))
# 下面主代码体中提供了两种方式显示数据,一种是按每行8个价格排列,另一种是按竖列一次性排列出,参数Format的值可为True/False;
# 使用时,要先设置初始价格(InitPrice)和单位步长(Step);
# 对于寻找阻力位而言,通常选择历史最低点作为初始价格,相反,对于寻找支撑位而言,通常选择历史最高点作为初始价格;
# 单位步长的设置,通常有两种方式。一种是按波动率(一定时长内的波动点数),另一种是按1,0.1,0.01,0.001,0.0001方式设置(遵循宇宙中所有物质的自然规律,总是由量变到质变的过程)
if __name__ == "__main__":
InitPrice = 4.74
Step = 0.1
Format = True
DisputablePrices (InitPrice, Step, Format)

# enf of file
输出执行结果如下:
[Prices]
4.74 4.84 4.94 5.04 5.14 5.24 5.34 5.44
5.54 5.74 5.94 6.14 6.34 6.54 6.74 6.94
7.14 7.44 7.74 8.04 8.34 8.64 8.94 9.24
9.54 9.94 10.34 10.74 11.14 11.54 11.94 12.34
12.74
[Params]
InitValue = 4.740000; Step = 0.100000; RecordCount = 33
本文介绍了使用Python编程实现著名的江恩四方形的方法,旨在解决分析过程中阻力位和支撑位价码不清晰的问题。通过代码实现,可以方便地查看和运行结果,包括一系列的价格和参数值。
1182

被折叠的 条评论
为什么被折叠?



