Ejemplo n.º 1
0
 public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
 {
     if (signal.getSignal() < 0)
     {
         return strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_BID) + strategy.iATR(symbol, (int)timeframe, atrPeriods, atrShift);
     }
     else
     {
         return strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_ASK) - strategy.iATR(symbol, (int)timeframe, atrPeriods, atrShift);
     }
 }
Ejemplo n.º 2
0
        public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
        {
            double range = strategy.iHigh(symbol, (int)timeframe, 1) - strategy.iLow(symbol, (int)timeframe, 1);

            if (signal.getSignal() == (int)SignalResult.SELLMARKET)
            {
                return strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_BID) - pips* strategy.pipToPoint(symbol);
            }
            else
            {
                    return strategy.MarketInfo(symbol, (int)MARKET_INFO.MODE_ASK) + pips* strategy.pipToPoint(symbol);
            }
        }
Ejemplo n.º 3
0
 public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
 {
     if (signal.getSignal() == SignalResult.SELLMARKET)
     {
         double current_high = strategy.iHigh(symbol, (int)timeframe, 0);
         for (int i = 1; strategy.iHigh(symbol, (int)timeframe, i) > current_high; i++)
         {
             current_high = strategy.iHigh(symbol, (int)timeframe, i);
         }
         return current_high + pipTolerance * strategy.pipToPoint(symbol);
     }
     else
     {
         double current_low = strategy.iLow(symbol, (int)timeframe, 0);
         for (int i = 1; strategy.iLow(symbol, (int)timeframe, i) < current_low; i++)
         {
             current_low = strategy.iLow(symbol, (int)timeframe, i);
         }
         return current_low - pipTolerance * strategy.pipToPoint(symbol);
     }
 }
Ejemplo n.º 4
0
 public override double getTakeProfit(string symbol, SignalResult signal)
 {
     return fixedPipTakeProfit.getLevel(symbol, strategyTimeframe, signal);
 }
Ejemplo n.º 5
0
 // Method to return the stop loss level
 public abstract double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal);
Ejemplo n.º 6
0
 public override double getStopLoss(string symbol, SignalResult signal)
 {
     return srStopLoss.getLevel(symbol, strategyTimeframe, signal);
 }
Ejemplo n.º 7
0
 public override double getTakeProfit(string symbol, SignalResult signal)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 public abstract double getEntryPrice(String symbol, SignalResult signal);
Ejemplo n.º 9
0
 public abstract DateTime getExpiry(String symbol, SignalResult signal);
Ejemplo n.º 10
0
 public abstract double getStopLoss(String symbol, SignalResult signal);
Ejemplo n.º 11
0
 public abstract double getTakeProfit(String symbol, SignalResult signal);
Ejemplo n.º 12
0
        // Method to execute the trade
        public void executeTrade(String symbol, SignalResult signal)
        {
            try
            {
                TRADE_OPERATION op;
                double price, lots;
                int slippage = 5000;
                double stoploss = this.getStopLoss(symbol, signal);
                double takeprofit = this.getTakeProfit(symbol, signal);
                String comment = this.getComment(symbol);
                int magic = this.getMagicNumber(symbol);
                DateTime expiration = this.getExpiry(symbol, signal);
                COLOR arrowColor = COLOR.Aqua;

                double stopDistance;

                DateTime lastBuyOpen, lastSellOpen;
                bool openBuyOrder = false, openSellOrder = false, openBuyStopOrder = false, openSellStopOrder = false, openBuyLimitOrder = false, openSellLimitOrder = false;

                if (signal.getSignal() == SignalResult.BUYMARKET)
                {
                    op = TRADE_OPERATION.OP_BUY;
                }
                else if (signal.getSignal() == SignalResult.SELLMARKET)
                {
                    op = TRADE_OPERATION.OP_SELL;
                }
                else if (signal.getSignal() == SignalResult.BUYSTOP)
                {
                    op = TRADE_OPERATION.OP_BUYSTOP;
                }
                else if (signal.getSignal() == SignalResult.SELLSTOP)
                {
                    op = TRADE_OPERATION.OP_SELLSTOP;
                }
                else if (signal.getSignal() == SignalResult.BUYLIMIT)
                {
                    op = TRADE_OPERATION.OP_BUYLIMIT;
                }
                else if (signal.getSignal() == SignalResult.SELLLIMIT)
                {
                    op = TRADE_OPERATION.OP_SELLLIMIT;
                }
                else
                {
                    throw new Exception("Invalid Signal signal=" + signal);
                }

                //LOG.Debug("stopDistance: " + stopDistance);
                //LOG.Debug("price: " + price);
                //LOG.Debug("stoploss: " + stoploss);
                //LOG.Debug("takeprofit: " + takeprofit);


                // Check open trades on this symbol
                for (int i = 0; i < OrdersTotal(); i++)
                {
                    OrderSelect(i, (int)SELECTION_TYPE.SELECT_BY_POS, (int)SELECTION_POOL.MODE_TRADES);
                    if (OrderType() == (int)TRADE_OPERATION.OP_BUY && OrderSymbol().Equals(symbol) && OrderMagicNumber() == magic)
                    {
                        lastBuyOpen = OrderOpenTime();
                        openBuyOrder = true;
                        if (closeOnOpposingSignal && signal.getSignal() < 0)
                        {
                            closeOutThisOrder(symbol);
                        }
                    }
                    else if (OrderType() == (int)TRADE_OPERATION.OP_SELL && OrderSymbol().Equals(symbol) && OrderMagicNumber() == magic)
                    {
                        lastSellOpen = OrderOpenTime();
                        openSellOrder = true;
                        if (closeOnOpposingSignal && signal.getSignal() > 0)
                        {
                            closeOutThisOrder(symbol);
                        }

                    }
                    else if (OrderType() == (int)TRADE_OPERATION.OP_BUYSTOP && OrderSymbol().Equals(symbol) && OrderMagicNumber() == magic)
                    {
                        openBuyStopOrder = true;
                    }
                    else if (OrderType() == (int)TRADE_OPERATION.OP_SELLSTOP && OrderSymbol().Equals(symbol) && OrderMagicNumber() == magic)
                    {
                        openSellStopOrder = true;
                    }
                    else if (OrderType() == (int)TRADE_OPERATION.OP_BUYLIMIT && OrderSymbol().Equals(symbol) && OrderMagicNumber() == magic)
                    {
                        openBuyLimitOrder = true;
                    }
                    else if (OrderType() == (int)TRADE_OPERATION.OP_SELLLIMIT && OrderSymbol().Equals(symbol) && OrderMagicNumber() == magic)
                    {
                        openSellLimitOrder = true;
                    }
                }

                // Calculate lots
                double entryPrice = this.getEntryPrice(symbol, signal);

                if (signal.getSignal() > 0)
                {
                    stopDistance = entryPrice - stoploss;
                }
                else
                {
                    stopDistance = stoploss - entryPrice;
                }
                lots = this.getLotSize(symbol, stopDistance);


                if ((signal.getSignal() == SignalResult.BUYMARKET && !openBuyOrder) 
                        || (signal.getSignal() == SignalResult.SELLMARKET && !openSellOrder)
                        || (signal.getSignal() == SignalResult.BUYLIMIT && !openBuyLimitOrder && !openBuyOrder)
                        || (signal.getSignal() == SignalResult.SELLLIMIT && !openSellLimitOrder && !openSellOrder)
                        || (signal.getSignal() == SignalResult.BUYSTOP && !openBuyStopOrder && !openBuyOrder) 
                        || (signal.getSignal() == SignalResult.SELLSTOP && !openSellStopOrder && !openSellOrder))
                {
                    LOG.Info(String.Format("Executing Trade at " + DateUtil.FromUnixTime((long)MarketInfo(symbol, (int)MARKET_INFO.MODE_TIME)) +
                                            "\n\tsymbol:\t{0}" +
                                            "\n\top:\t\t{1}" +
                                            "\n\tlots:\t\t{2}" +
                                            "\n\tentryPrice:\t{3}" +
                                            "\n\tslippage:\t{4}" +
                                            "\n\tstoploss:\t{5}" +
                                            "\n\ttakeprofit:\t{6}" +
                                            "\n\tcomment:\t{7}" +
                                            "\n\tmagic:\t\t{8}" +
                                            "\n\texpiration:\t{9}" +
                                            "\n\tarrowColor:\t{0}", symbol, (int) op, lots, entryPrice, slippage, stoploss, takeprofit, comment, magic, expiration, arrowColor));

                    OrderSend(symbol, (int)op, lots, entryPrice, slippage, stoploss, takeprofit, comment, magic, expiration, arrowColor);
                }

            }
            catch (Exception e)
            {
                LOG.Error(e);
                throw;
            }
        }
Ejemplo n.º 13
0
 public override DateTime getExpiry(string symbol, SignalResult signal)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 14
0
 public override double getEntryPrice(string symbol, SignalResult signal)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 15
0
 public override double getEntryPrice(string symbol, SignalResult signal)
 {
     if (signal.getSignal() == SignalResult.BUYMARKET)
     {
         return this.MarketInfo(symbol, (int)MARKET_INFO.MODE_ASK);
     }
     else 
     {
         return this.MarketInfo(symbol, (int)MARKET_INFO.MODE_BID);
     }
 }
Ejemplo n.º 16
0
 // Non Abstract methods
 public double getStopEntry(String symbol, SignalResult signal)
 {
     return 0;
 }
Ejemplo n.º 17
0
 public override DateTime getExpiry(string symbol, SignalResult signal)
 {
     return DateUtil.FromUnixTime(0); //epoch
 }
Ejemplo n.º 18
0
 public override double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal)
 {
     return 0;
 }
Ejemplo n.º 19
0
 // Method to return the Take Profit Level
 public abstract double getLevel(String symbol, TIMEFRAME timeframe, SignalResult signal);
Ejemplo n.º 20
0
 public override double getStopLoss(string symbol, SignalResult signal)
 {
     throw new NotImplementedException();
 }