⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gaprule.java

📁 EclipseTrader is a stock exchange analysis system, featuring shares pricing watch, intraday and hi
💻 JAVA
字号:
/* * Copyright (c) 2004-2006 Marco Maccaferri and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: *     Marco Maccaferri - initial API and implementation */package net.sourceforge.eclipsetrader.trading.patterns;import java.util.ArrayList;import java.util.List;import net.sourceforge.eclipsetrader.core.IPattern;import net.sourceforge.eclipsetrader.core.Sentiment;import net.sourceforge.eclipsetrader.core.db.Bar;import net.sourceforge.eclipsetrader.core.db.Security;public class GapRule implements IPattern{    List bars = new ArrayList();    int minimumBars = 3;    int maximumBars = 3;    Sentiment sentiment = Sentiment.INVALID;    public GapRule()    {    }    /* (non-Javadoc)     * @see net.sourceforge.eclipsetrader.core.IPattern#init(net.sourceforge.eclipsetrader.core.db.Security)     */    public void init(Security security)    {        bars = new ArrayList();        sentiment = Sentiment.INVALID;    }    /* (non-Javadoc)     * @see net.sourceforge.eclipsetrader.core.IPattern#getSentiment(net.sourceforge.eclipsetrader.core.db.Bar)     */    public void add(Bar bar)    {        bars.add(bar);        if (bars.size() > maximumBars)            bars.remove(0);        if (bars.size() >= minimumBars)        {            sentiment = Sentiment.NEUTRAL;            Bar[] recs = (Bar[])bars.toArray(new Bar[bars.size()]);            if (recs[0].getHigh() < recs[1].getLow() // gap up                    && closesInTopQuarter(recs[1]) && closesInTopQuarter(recs[2]))            {                sentiment = Sentiment.BULLISH;            }            else if (recs[1].getHigh() < recs[0].getLow() // gap down                    && closesInBottomQuarter(recs[1]) && closesInBottomQuarter(recs[2]))            {                sentiment = Sentiment.BEARISH;            }        }    }    /* (non-Javadoc)     * @see net.sourceforge.eclipsetrader.core.IPattern#getSentiment()     */    public Sentiment getSentiment()    {        return sentiment;    }    private boolean closesInTopQuarter(Bar rec)    {        return rec.getClose() >= (rec.getLow() + (rec.getHigh() - rec.getLow()) * 3 / 4);    }    private boolean closesInBottomQuarter(Bar rec)    {        return rec.getClose() <= (rec.getLow() + (rec.getHigh() - rec.getLow()) / 4);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -