Tham khảo tài liệu 'ehlers, john - cybernetics analysis for stock and futures_8', tài chính - ngân hàng, đầu tư chứng khoán phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 182 CYBERNETIC ANALYSIS FOR STOCKS AND FUTURES aFiltArray O nCoefl nValuel nCoef2 aFiltArray l nCoef3 aFiltArray 2 nCoef4 aFiltArray 3 if currently flat look for a trade entry if nStatus 0 if nStatus 0 aFiltArray 0 0 aFiltArray 1 0 goLong 1 else if nStatus 0 aFiltArray 0 0 aFiltArray 1 0 goShort else in a long trade if nStatus 1 if stop hit sell long if low nStop if open nStop closeliong open else closeLong nStop check for reversal signal else if aFiltArray 0 0 aFiltArray 1 0 goShort in a short trade else if nStatus -1 FIGURE Continued Adapting to the Trend 183 if stop hit cover short if high nStop if open nStop closeShort open else closeShort nStop check for reversal signal else if aFiltArray 0 0 aFiltArray 1 0 goLong gID function assigns unique identifier to graphic text routines function gID grID return grID Convert Degrees to Radians function DegToRad nValue var nTmp nTmp nValue 180 return nTmp Convert Radians to Degrees function RadToDeg nValue var nTmp continued FIGURE Continued 184 CYBERNETIC ANALYSIS FOR STOCKS AND FUTURES nTmp nValue 180 return nTmp function Median nBars aArray var aTmp new Array var nTmp var result var X transfer elements to temp array X 0 while X nBars aTmpfx aArray x sort array in asc order SortAsc if odd of elements just take middle if nBars 2 0 result aTmp nBars 1 2 aTmp null return result if even elements take average of two middle elements else nTmp nBars 2 result aTmptnTmp aTmp nTmp 1 2 aTmp null return result function SortAsc argl arg2 if argl arg2 return -1 FIGURE Continued Adapting to the Trend . . . -. else return 1 enter a short trade function goShortO drawShapeRelatived high l Shape. DOWNARROW _ gID Short nEntryPrice. open l nstop nEntryPrice nSVal nPVal nStatus -1 close a short trade function closeShort nPrice drawShapeRelative 0 low .