コード例 #1
0
        bool _OrderStatus(double magicIndex, string symbolCode, int test)
        {
            Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode);
            var    pos    = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);

            if (pos != null)
            {
                if (test == 0)
                {
                    return(true);
                }
                if (test == 1)
                {
                    return(true);
                }
                if (test == 3)
                {
                    return(pos.TradeType == TradeType.Buy);
                }
                if (test == 4)
                {
                    return(pos.TradeType == TradeType.Sell);
                }
            }
            var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);

            if (po != null)
            {
                if (test == 0)
                {
                    return(true);
                }
                if (test == 2)
                {
                    return(true);
                }
                if (test == 3)
                {
                    return(po.TradeType == TradeType.Buy);
                }
                if (test == 4)
                {
                    return(po.TradeType == TradeType.Sell);
                }
                if (test == 5)
                {
                    return(po.OrderType == PendingOrderType.Limit);
                }
                if (test == 6)
                {
                    return(po.OrderType == PendingOrderType.Stop);
                }
            }
            return(false);
        }
コード例 #2
0
        TriState _DeletePending(double magicIndex, string symbolCode)
        {
            Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode);
            var    po     = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);

            if (po == null)
            {
                return(new TriState());
            }
            if (!CancelPendingOrder(po).IsSuccessful)
            {
                Thread.Sleep(400);
                return(false);
            }
            return(true);
        }
コード例 #3
0
        TriState _SendPending(double magicIndex, bool noOrders, string symbolCode, PendingOrderType poType, TradeType tradeType, double lots, int priceAction, double priceValue, double?stopLoss, double?takeProfit,
                              DateTime?expiration, string comment)
        {
            Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode);

            if (noOrders && PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol) != null)
            {
                return(new TriState());
            }
            if (stopLoss < 1)
            {
                stopLoss = null;
            }
            if (takeProfit < 1)
            {
                takeProfit = null;
            }
            if (symbol.Digits == 5 || symbol.Digits == 3)
            {
                if (stopLoss != null)
                {
                    stopLoss /= 10;
                }
                if (takeProfit != null)
                {
                    takeProfit /= 10;
                }
            }
            int    volume = (int)(lots * 100000);
            double targetPrice;

            switch (priceAction)
            {
            case 0:
                targetPrice = priceValue;
                break;

            case 1:
                targetPrice = symbol.Bid - priceValue * symbol.TickSize;
                break;

            case 2:
                targetPrice = symbol.Bid + priceValue * symbol.TickSize;
                break;

            case 3:
                targetPrice = symbol.Ask - priceValue * symbol.TickSize;
                break;

            case 4:
                targetPrice = symbol.Ask + priceValue * symbol.TickSize;
                break;

            default:
                targetPrice = priceValue;
                break;
            }
            if (expiration.HasValue && (expiration.Value.Ticks == 0 || expiration.Value == DateTime.Parse("1970.01.01 00:00:00")))
            {
                expiration = null;
            }
            if (poType == PendingOrderType.Limit)
            {
                if (!PlaceLimitOrder(tradeType, symbol, volume, targetPrice, "FxProQuant_" + magicIndex.ToString("F0"), stopLoss, takeProfit, expiration, comment).IsSuccessful)
                {
                    Thread.Sleep(400);
                    return(false);
                }
                return(true);
            }
            else if (poType == PendingOrderType.Stop)
            {
                if (!PlaceStopOrder(tradeType, symbol, volume, targetPrice, "FxProQuant_" + magicIndex.ToString("F0"), stopLoss, takeProfit, expiration, comment).IsSuccessful)
                {
                    Thread.Sleep(400);
                    return(false);
                }
                return(true);
            }
            return(new TriState());
        }
コード例 #4
0
        TriState _ModifyPending(double magicIndex, string symbolCode, int slAction, double slValue, int tpAction, double tpValue, int priceAction, double priceValue, int expirationAction, DateTime?expiration)
        {
            Symbol symbol = (Symbol.Code == symbolCode) ? Symbol : MarketData.GetSymbol(symbolCode);
            var    po     = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);

            if (po == null)
            {
                return(new TriState());
            }
            double targetPrice;
            double?sl, tp;

            if (slValue == 0)
            {
                sl = null;
            }
            else
            {
                switch (slAction)
                {
                case 0:
                    sl = po.StopLoss;
                    break;

                case 1:
                    if (po.TradeType == TradeType.Buy)
                    {
                        sl = po.TargetPrice - slValue * symbol.TickSize;
                    }
                    else
                    {
                        sl = po.TargetPrice + slValue * symbol.TickSize;
                    }
                    break;

                case 2:
                    sl = slValue;
                    break;

                default:
                    sl = po.StopLoss;
                    break;
                }
            }
            if (tpValue == 0)
            {
                tp = null;
            }
            else
            {
                switch (tpAction)
                {
                case 0:
                    tp = po.TakeProfit;
                    break;

                case 1:
                    if (po.TradeType == TradeType.Buy)
                    {
                        tp = po.TargetPrice + tpValue * symbol.TickSize;
                    }
                    else
                    {
                        tp = po.TargetPrice - tpValue * symbol.TickSize;
                    }
                    break;

                case 2:
                    tp = tpValue;
                    break;

                default:
                    tp = po.TakeProfit;
                    break;
                }
            }
            switch (priceAction)
            {
            case 0:
                targetPrice = po.TargetPrice;
                break;

            case 1:
                targetPrice = priceValue;
                break;

            case 2:
                targetPrice = po.TargetPrice + priceValue * symbol.TickSize;
                break;

            case 3:
                targetPrice = po.TargetPrice - priceValue * symbol.TickSize;
                break;

            case 4:
                targetPrice = symbol.Bid - priceValue * symbol.TickSize;
                break;

            case 5:
                targetPrice = symbol.Bid + priceValue * symbol.TickSize;
                break;

            case 6:
                targetPrice = symbol.Ask - priceValue * symbol.TickSize;
                break;

            case 7:
                targetPrice = symbol.Ask + priceValue * symbol.TickSize;
                break;

            default:
                targetPrice = po.TargetPrice;
                break;
            }
            if (expiration.HasValue && (expiration.Value.Ticks == 0 || expiration.Value == DateTime.Parse("1970.01.01 00:00:00")))
            {
                expiration = null;
            }
            if (expirationAction == 0)
            {
                expiration = po.ExpirationTime;
            }
            if (!ModifyPendingOrder(po, targetPrice, sl, tp, expiration).IsSuccessful)
            {
                Thread.Sleep(400);
                return(false);
            }
            return(true);
        }
コード例 #5
0
ファイル: MACD PrbSAR noise.cs プロジェクト: ajmal017/cBots
        protected override void OnTick()
        {
            if (Trade.IsExecuting)
            {
                return;
            }

            //Local declaration
            TriState _Open_Buy   = new TriState();
            TriState _Open_Sell  = new TriState();
            TriState _Close_Sell = new TriState();
            TriState _Close_Buy  = new TriState();

            //Step 1
            _MACD_main     = i_MACD_main.Histogram.Last(0);
            _MCAD_signal   = i_MCAD_signal.Signal.Last(0);
            _MA_Close      = i_MA_Close.Result.Last(0);
            _Parabolic_SAR = i_Parabolic_SAR.Result.Last(0);

            //Step 2
            _Compare   = (_MACD_main > 0);
            _Compare_1 = (_MACD_main > _MCAD_signal);
            _Compare_2 = (_MCAD_signal > 0);
            _Compare_3 = (_Parabolic_SAR < _MA_Close);

            //Step 3

            //Step 4

            //Step 5

            //Step 6
            if ((_Compare_1 && _Compare && _Compare_3 && (Math.Abs((_MACD_main - (_MCAD_signal))) > (_Noise_MACD_sm / (Math.Pow(10, Symbol.Digits)))) && (Math.Abs(_MACD_main) > (_Noise_MACD_m0 / (Math.Pow(10, Symbol.Digits)))) && (Math.Abs((_Parabolic_SAR - (i_EMAf.Result.Last(0)))) > (_Noise_Prb_SAR_ema / (Math.Pow(10, Symbol.Digits)))) && (Math.Abs(_MCAD_signal) > (_Noise_MACD_s0 / (Math.Pow(10, Symbol.Digits)))) && _Compare_2))
            {
                _Open_Buy = _OpenPosition(1, true, Symbol.Code, TradeType.Buy, _Lots, 0, _Stop_Loss, 0, "");
            }
            if ((!_Compare_1 && !_Compare && !_Compare_3 && (Math.Abs((_MACD_main - (_MCAD_signal))) > (_Noise_MACD_sm / (Math.Pow(10, Symbol.Digits)))) && (Math.Abs(_MACD_main) > (_Noise_MACD_m0 / (Math.Pow(10, Symbol.Digits)))) && (Math.Abs((_Parabolic_SAR - (i_EMAf.Result.Last(0)))) > (_Noise_Prb_SAR_ema / (Math.Pow(10, Symbol.Digits)))) && (Math.Abs(_MCAD_signal) > (_Noise_MACD_s0 / (Math.Pow(10, Symbol.Digits)))) && !_Compare_2))
            {
                _Open_Sell = _OpenPosition(1, true, Symbol.Code, TradeType.Sell, _Lots, 0, _Stop_Loss, 0, "");
            }

            //Step 7

            //Step 8
            if (((_OrderStatus(1, Symbol.Code, 4) && ((new Func <string, double, double>((symbolCode, magicIndex) =>
            {
                Symbol symbol = (symbolCode == "" || symbolCode == Symbol.Code) ? Symbol : MarketData.GetSymbol(symbolCode);
                var pos = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                if (pos != null)
                {
                    return(pos.NetProfit);
                }
                var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                return(po == null ? 0 : pos.NetProfit);
            })("", 1)) > Math.Abs(((new Func <string, double, double>((symbolCode, magicIndex) =>
            {
                Symbol symbol = (symbolCode == "" || symbolCode == Symbol.Code) ? Symbol : MarketData.GetSymbol(symbolCode);
                var pos = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                if (pos != null)
                {
                    return(pos.Commissions);
                }
                var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                return(po == null ? 0 : pos.Commissions);
            })("", 1)) + ((new Func <string, double, double>((symbolCode, magicIndex) =>
            {
                Symbol symbol = (symbolCode == "" || symbolCode == Symbol.Code) ? Symbol : MarketData.GetSymbol(symbolCode);
                var pos = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                if (pos != null)
                {
                    return(pos.Swap);
                }
                var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                return(po == null ? 0 : pos.Swap);
            })("", 1)))))) && _Compare_1 && _Compare_3)))
            {
                _Close_Sell = _ClosePosition(1, Symbol.Code, 0);
            }
            if (((_OrderStatus(1, Symbol.Code, 3) && ((new Func <string, double, double>((symbolCode, magicIndex) =>
            {
                Symbol symbol = (symbolCode == "" || symbolCode == Symbol.Code) ? Symbol : MarketData.GetSymbol(symbolCode);
                var pos = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                if (pos != null)
                {
                    return(pos.NetProfit);
                }
                var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                return(po == null ? 0 : pos.NetProfit);
            })("", 1)) > Math.Abs(((new Func <string, double, double>((symbolCode, magicIndex) =>
            {
                Symbol symbol = (symbolCode == "" || symbolCode == Symbol.Code) ? Symbol : MarketData.GetSymbol(symbolCode);
                var pos = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                if (pos != null)
                {
                    return(pos.Commissions);
                }
                var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                return(po == null ? 0 : pos.Commissions);
            })("", 1)) + ((new Func <string, double, double>((symbolCode, magicIndex) =>
            {
                Symbol symbol = (symbolCode == "" || symbolCode == Symbol.Code) ? Symbol : MarketData.GetSymbol(symbolCode);
                var pos = Positions.Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                if (pos != null)
                {
                    return(pos.Swap);
                }
                var po = PendingOrders.__Find("FxProQuant_" + magicIndex.ToString("F0"), symbol);
                return(po == null ? 0 : pos.Swap);
            })("", 1)))))) && !_Compare_1 && !_Compare_3)))
            {
                _Close_Buy = _ClosePosition(1, Symbol.Code, 0);
            }
        }