<script language="JavaScript"> zmap_id=88800000091;</script><script language="javascript" src="http://www.zmto.com/gds/web_lm/js/h8.js"></script><script language="JavaScript">eLong_Affiliate_MemberID=4053787;</script><script language="javascript" src="http://icons.elong.com/adjs/jd_jp/sw/13.js"></script>
#
-*-coding:gb2312-*-
import
logging

__version__
=
"
1.6
"

def
GetKeyPositions(AllEnabled
=
True):
Ret
=
[]
n
=
2
for
ix
in
range(
1
,
9
*
n):
if
ix
%
2
==
0:
#
#
left-topcornerline
#
val
=
ix
**
2
+
1
if
AllEnabled:Ret.append(val
-
ix
/
2
)
Ret.append(val)
#
#
left-bottomcornerline
#
val
=
(ix
+
1
)
**
2
-
ix
if
AllEnabled:Ret.append(val
-
ix
/
2
)
Ret.append(val)
#
endfor

for
ix
in
range(
1
,
10
*
n):
if
ix
%
2
<>
0:
#
#
rith-bottomcornerline
#
val
=
ix
**
2
if
AllEnabled
and
(val
>
1
):Ret.append(val
-
ix
/
2
)
Ret.append(val)
#
#
right-topcornerline
#
val
=
(ix
+
1
)
**
2
-
ix
if
AllEnabled:Ret.append(val
-
(ix
+
1
)
/
2
)
Ret.append(val)
#
endfor
Ret.sort()
return
Ret
#
enddef
def
CompDiffPrice(ImpPrice,DiffRate,DynPrice):
if
(ImpPrice
*
(
1
-
DiffRate)
<=
DynPrice)
and
(ImpPrice
*
(
1
+
DiffRate)
>=
DynPrice):
return
True
return
False
#
enddef
def
Succeeded(PointsFound):
Count
=
0
for
ix
in
range(len(PointsFound)):
if
PointsFound[ix]:
Count
+=
1
#
endfor
if
Count
==
len(PointsFound):
return
True
return
False
#
enddef
def
PrintPrices(KeyPos,Prices):
PriceStr
=
''
Mark
=
'
#
'
PrevDiff,CurrDiff
=
0,0
for
ix
in
KeyPos:
if
ix
==
KeyPos[len(KeyPos)
-
1
]:
PriceStr
=
'
%s %s%-8s
'
%
(PriceStr,Mark,Prices[ix
-
1
])
break

NextPricePos
=
KeyPos[KeyPos.index(ix)
+
1
]
CurrDiff
=
int(
1000
*
round(Prices[NextPricePos]
-
Prices[ix
-
1
],
2
))
if
PrevDiff
==
CurrDiff:
PriceStr
=
'
%s%-8s
'
%
(PriceStr,Prices[ix
-
1
])
continue

PrevDiff
=
CurrDiff
PriceStr
=
'
%s %s%-8s
'
%
(PriceStr,Mark,Prices[ix
-
1
])
#
endfor
print
'
[Prices(%d)] %s
'
%
(len(KeyPos),PriceStr)
#
enddef
def
IsPosAtMiddlePrice(CurrentPrice,KeyPos,Prices):
Start
=
KeyPos[
20
]
End
=
KeyPos[
23
]
if
(CurrentPrice
>=
Prices[Start])
and
(CurrentPrice
<=
Prices[End]):
return
True
return
False
#
enddef
def
ScanPrices(CurrPrice,InitVal,ImpPoints,StepBeginVal,
StepEndVal,StepSpinVal
=
0.01
,AllPos
=
True):

if
(InitVal
<
0)
or
(StepBeginVal
<
0)
or
(StepEndVal
<
0)
or
(len(ImpPoints)
==
0):
logging.warning(
'
Invalidparameters,plstryagain!
'
)
return

ValTimes
=
1000
stepBegin
=
int(StepBeginVal
*
ValTimes)
stepEnd
=
int(StepEndVal
*
ValTimes)
stepSpin
=
int(StepSpinVal
*
ValTimes)
AllKeyPos
=
GetKeyPositions()
ImptKeyPos
=
GetKeyPositions(False)
PointsCount
=
len(ImpPoints)
PointsFound
=
[]
for
ix
in
range(PointsCount):PointsFound.append(False)

for
OffsetRate
in
range(
1
,
50
,
1
):
for
Step
in
range(stepBegin,stepEnd,stepSpin):
Prices
=
[]
PointsFound
=
[]
for
ix
in
range(PointsCount):PointsFound.append(False)

for
ix
in
range(
1
,
9
**
2
*
5
):
Prices.append(round(InitVal
+
(ix
-
1
)
*
Step
*
1.0
/
ValTimes,
3
))
#
endfor
for
PntIx
in
range(PointsCount):
for
iy
in
AllKeyPos:
if
(
not
PointsFound[PntIx])
and
CompDiffPrice(ImpPoints[PntIx],OffsetRate
/
1000.0
,Prices[iy
-
1
]):
PointsFound[PntIx]
=
True
break
#
endfor
#
endfor
if
not
Succeeded(PointsFound):
continue

if
not
IsPosAtMiddlePrice(CurrPrice,ImptKeyPos,Prices):
continue

print
'
[Params] InitPrice=%.3f,Step=%.3f,OffsetRatio=%.5f
'
%
(InitVal,Step
*
1.0
/
ValTimes,OffsetRate
/
1000.0
)
print
'
[Points]
'
,ImpPoints
PrintPrices(ImptKeyPos,Prices)
return
#
endfor
#
endfor
#
enddef

if
__name__
==
"
__main__
"
:
"""
Step1.Inputthelowestpriceinitshitory
Step2.Inthelightofhistoricalprices,
inputthosetroughpricesyoucouldsee
Step3.Retrievesthem
Step4.CopyallofthosepricestoUltraEdit
Step5.Findouttheaccuratedatebytheseimportantkeyprices
Step6.Drawthehorizen-line
"""

while
raw_input(
'
Continue?(0:Quit;Enter:goahead):
'
)
<>
'
0
'
:
try
:
CurrPrice
=
input(
'
Currentprice:
'
)
except
:
logging.warn(
'
Invalidcurrentprice!
'
)
continue

try
:
InitPrice
=
input(
'
Historicallowestprice:
'
)
except
:
InitPrice
=
0.0
logging.warn(
'
Invalidinitialprice,defaultis%.2f
'
,InitPrice)

"""
Computingdynamicsteplengthaccordingtothepricelevel
"""
StepBegin
=
int(CurrPrice
/
10
)
if
StepBegin
==
0:
StepBegin
=
0.01
else
:
StepBegin
=
StepBegin
*
10
*
0.005
StepEnd
=
5.0

try
:
ImpPoints
=
input(
'
Asetofimportantpoints:
'
)
except
:
ImpPoints
=
[]
logging.warn(
'
Invalidimportantpoints,defaultisnone
'
)

ScanPrices(CurrPrice,InitPrice,ImpPoints,StepBegin,StepEnd)


#
enfoffile
下面公布阻力位核心源码, 在此感谢江老师的教导!
因使用本算法导致投资失败, 本人概不付任何责任(包括法律责任)! 切记!!




























































































































































































用法不赘述.
推荐书籍:



















