RSIãç®åºãã
RSIãç®åºããã¯ã©ã¹ã§ãã
module Signal #===ä¸å®æéã®ã¬ã¼ããã¼ã¿ãå ã«å¤ãç®åºããã·ã°ãã«ã®åºåºã¯ã©ã¹ class RangeSignal include Signal def initialize( range=25 ) @datas = [] # ã¬ã¼ããè¨é²ãããããã¡ @range = range end def next_data( data ) # ãããã¡ã®ãã¼ã¿ãæ´æ° @datas.push data @datas.shift if @datas.length > @range # ãããã¡ãµã¤ãºãååã§ãªããã°ãnilãè¿ãã return nil if @datas.length != @range # ç®åº return calculate(@datas) end def calculate(datas); end attr_reader :range end #===RSI class RSI < RangeSignal def initialize( range=14 ) super(range) end def calculate(datas) rsi( datas ) end end module_function #===RSIãå¾ãã #ããã #RSI = næ¥éã®å¤ä¸ããå¹ åè¨ / (næ¥éã®å¤ä¸ããå¹ åè¨ + næ¥éã®å¤ä¸ããå¹ åè¨) * 100 #nã¨ãã¦ã14ã9ã使ãã®ããä¸è¬çã30以ä¸ã§ã¯å£²ãããã70以ä¸ã§ã¯è²·ããããã®æ°´æºã # #datas:: å¤ã®é å #æ»ãå¤:: RSIå¤ def rsi( datas ) prev = nil tmp = datas.inject( [0.0,0.0] ) {|r,i| r[ i > prev ? 0 : 1 ] += (i - prev).abs if prev prev = i r } (tmp[0] + tmp[1] ) == 0 ? 0.0 : tmp[0] / (tmp[0] + tmp[1]) * 100 end end
RSIã表示ããã¨ã¼ã¸ã§ã³ãã¯ä»¥ä¸ã
#RSIã表示ããã¨ã¼ã¸ã§ã³ãã®ãµã³ãã« class RSISampleAgent < JIJI::PeriodicallyAgent def description "RSIã表示ããã¨ã¼ã¸ã§ã³ãã®ãµã³ãã«ã§ã" end def init @rsi = JIJI::Agent::Shared::Signal::RSI.new(@range) @out = output.get( "RSI", :graph, { :column_count=>1, :lines=>[30,70], :colors=>["#557777"] } ) end # 次ã®ã¬ã¼ããåãåã def next_period_rates( rates ) res =@rsi.next_data( rates[:EURJPY].bid.end ) return unless res @out.put( res ) end # UIããè¨å®å¯è½ãªããããã£ã®ä¸è¦§ãè¿ãã def property_infos super().concat [ Property.new( "range", "éè¨æé", 25, :number ) ] end end
ä¾ã«ãã£ã¦ãデモサイトã«ããã¦ãã¾ãã