protected override void CalcBar()
        {
            // strategy logic
            spread_diff_func.Call();             // force calculation

            // data_1 = series 1
            // data_2 = series 2
            // data_3 = series 1 bid
            // data_4 = series 1 ask

            double ask, bid;

            if (price_signal == price_signal_enum.Bid_Ask)
            {
                bid = BarsOfData(3).Close[0];
                ask = BarsOfData(4).Close[0];
            }
            else
            {
                bid = BarsOfData(1).Close[0];
                ask = BarsOfData(1).Close[0];
            }

            // lift the ask
            if (ask < spread_diff_func.ErrorLow)
            {
                if (this.StrategyInfo.MarketPosition >= 0 && enable_long)
                {
                    long_order.Send();
                }
                else if (!liquidate_at_midpoint && this.StrategyInfo.MarketPosition < 0)
                {
                    close_short_order.Send();
                }
            }

            if (liquidate_at_midpoint && this.StrategyInfo.MarketPosition < 0 && ask <= spread_diff_func.spread_value)
            {
                close_short_order.Send();
            }

            // hit the bid
            else if (bid > spread_diff_func.ErrorHigh)
            {
                if (!liquidate_at_midpoint && this.StrategyInfo.MarketPosition > 0)
                {
                    close_long_order.Send();
                }
                else if (this.StrategyInfo.MarketPosition <= 0 && enable_short)
                {
                    short_order.Send();
                }
            }

            if (liquidate_at_midpoint && this.StrategyInfo.MarketPosition > 0 && bid >= spread_diff_func.spread_value)
            {
                close_long_order.Send();
            }
        }
        protected override void CalcBar()
        {
            // strategy logic
            spread_diff_func.Call();             // force calculation

            // data_1 = series 1
            // data_2 = series 2
            // data_3 = series 1 bid
            // data_4 = series 1 ask

            // ask is less than the the lowest we think is reasonable - close short
            if (BarsOfData(4).Close[0] < spread_diff_func.ErrorLow)
            {
                entry_order.Send();
            }
        }
Example #3
0
        protected override void CalcBar()
        {
            // strategy logic
            spread_diff_func.Call();             // force calculation

            // data_1 = series 1
            // data_2 = series 2
            // data_3 = series 1 bid
            // data_4 = series 1 ask

            // bid is more than the the highest we think is reasonable - go short
            if (BarsOfData(3).Close[0] > spread_diff_func.ErrorHigh)
            {
                entry_order.Send();
            }
        }