Ejemplo n.º 1
0
 public ParabolicSar(MqlApi api, string symbol, int timeFrame, int period)
 {
     _mqlApi = api;
     _symbol = symbol;
     _timeFrame = timeFrame;
     _period = period;
 }
Ejemplo n.º 2
0
 public ParabolicSar(MqlApi api, string symbol, int timeFrame, int period)
 {
     _mqlApi    = api;
     _symbol    = symbol;
     _timeFrame = timeFrame;
     _period    = period;
 }
        public ShortProfitTargetReachedLookingToAdjustStopLoss(ATRTrade aContext, MqlApi mql4) : base(mql4)
        {

            currentLL = 99999;
            this.timeWhenProfitTargetWasReached = mql4.TimeCurrent();
            this.context = aContext;
        }
Ejemplo n.º 4
0
 public static bool isSymbol(string symbol, MqlApi mql4)
 {
     double bid = mql4.MarketInfo(symbol, MqlApi.MODE_BID);
     if (mql4.GetLastError() == 4106) // unknown symbol
         return (false);
     else
         return (true);
 }
Ejemplo n.º 5
0
 public CandleStick(MqlApi api, string symbol, int timeFrame, int period, int candleCount)
 {
     _mqlApi      = api;
     _symbol      = symbol;
     _timeFrame   = timeFrame;
     _period      = period;
     _candleCount = candleCount;
 }
Ejemplo n.º 6
0
 public CandleStick(MqlApi api, string symbol, int timeFrame, int period, int candleCount)
 {
     _mqlApi = api;
     _symbol = symbol;
     _timeFrame = timeFrame;
     _period = period;
     _candleCount = candleCount;
 }
Ejemplo n.º 7
0
 public ExpertAdvisor CreateExpertAdvisor(AdvisorType advisorType, MqlApi api)
 {
     switch(advisorType) {
         case AdvisorType.Scalper:
             return new ScalperAdvisor(api);
         default:
             throw new InvalidEnumArgumentException(string.Format("Invalid advisor type:{0}", advisorType));
     }
 }
Ejemplo n.º 8
0
 public BollingerBands(MqlApi api, string symbol, int timeFrame, int period, int trendDirectionCandleCount,
                       int marginPoints)
 {
     _mqlApi    = api;
     _symbol    = symbol;
     _timeFrame = timeFrame;
     _period    = period;
     _trendDirectionCandleCount = trendDirectionCandleCount;
     _marginPoints = marginPoints;
 }
Ejemplo n.º 9
0
 public BollingerBands(MqlApi api, string symbol, int timeFrame, int period, int trendDirectionCandleCount,
     int marginPoints)
 {
     _mqlApi = api;
     _symbol = symbol;
     _timeFrame = timeFrame;
     _period = period;
     _trendDirectionCandleCount = trendDirectionCandleCount;
     _marginPoints = marginPoints;
 }
 public WaitForBreakToPlaceLimitOrder(ATRTrade _trade, int _limitOrderType, double _rangeLow, double _rangeHigh, double _entryPrice, double _cancelPrice, double _positionSize, MqlApi mql4) : base(mql4)
 {
     trade = _trade;
     limitOrderType = _limitOrderType;
     rangeHigh = _rangeHigh;
     rangeLow = _rangeLow;
     cancelPrice = _cancelPrice;
     positionSize = _positionSize;
     entryPrice = _entryPrice;
 }
Ejemplo n.º 11
0
 public ScalperAdvisor(MqlApi api)
 {
     _mqlApi = api;
     _timeFrame = MqlApi.PERIOD_M5;
     _bollingersPeriod = 20;
     _candleStickPeriod = 20;
     _bollingersTrendDirectionCandleCount = 3;
     _candleStickCandleCount = 3;
     _bollingersMarginPoints = 1;
     _trailing = 30;
 }
Ejemplo n.º 12
0
 public ScalperAdvisor(MqlApi api)
 {
     _mqlApi = api;
     _timeFrame = MqlApi.PERIOD_M5;
     _bollingersPeriod = 20;
     _candleStickPeriod = 20;
     _bollingersTrendDirectionCandleCount = 3;
     _candleStickCandleCount = 3;
     _bollingersMarginPoints = 1;
     _trailing = 30;
 }
Ejemplo n.º 13
0
        public ExpertAdvisor CreateExpertAdvisor(AdvisorType advisorType, MqlApi api)
        {
            switch (advisorType)
            {
            case AdvisorType.Scalper:
                return(new ScalperAdvisor(api));

            default:
                throw new InvalidEnumArgumentException(string.Format("Invalid advisor type:{0}", advisorType));
            }
        }
Ejemplo n.º 14
0
        public static double getPipValue(MqlApi mql4)
        {
            int factor;
            
            if (mql4.Digits == 5)
                factor = 1;
            else
                factor = 10;

            if (!mql4.IsTesting())
            {
                return (mql4.MarketInfo(mql4.Symbol(), MqlApi.MODE_TICKVALUE) * factor);
            }
            else
            {
                //this works only for FOREX
                string accountCurrency = mql4.AccountInfoString(MqlApi.ACCOUNT_CURRENCY);
                //check if quotation currnecy is account currency. 
                string quotationCurrency = mql4.Symbol().Substring(3, 3);
                //if the same, then pip value is 1. 
                if (accountCurrency.Equals(quotationCurrency))
                {
                    return 1.0 * factor;

                }
                //if not - find the current rate of the quotation currency compared to account currnecy. 
                string ACCQUO = accountCurrency + quotationCurrency;
                if (isSymbol(ACCQUO, mql4))
                {
                    return ((1 / mql4.MarketInfo(ACCQUO, MqlApi.MODE_BID))) * factor;
                }
                //if symbol does not exist try to the other way around
                string QUOACC = quotationCurrency + accountCurrency;
                if (isSymbol(QUOACC, mql4))
                {
                    return ((mql4.MarketInfo(QUOACC, MqlApi.MODE_BID))) * factor;
                }
                //otherwise
                return 0.0;
            }


            /*
            //if testing - use exchange rate at the time of testing, instead of current rate. Only applies to pairs where USD is the first symbol. 
            if ((mql4.IsTesting()) && (mql4.MarketInfo(mql4.Symbol(), MqlApi.MODE_TICKVALUE) != 1))
            {
                return (1 / ((mql4.Bid + mql4.Ask) / 2) * point) / mql4.MarketInfo(mql4.Symbol(), MqlApi.MODE_TICKSIZE);
            }
            else
            {
                return (mql4.MarketInfo(mql4.Symbol(), MqlApi.MODE_TICKVALUE) * point) / mql4.MarketInfo(mql4.Symbol(), MqlApi.MODE_TICKSIZE);
            }
            */
        }
        public LowestLowReceivedEstablishingEligibilityRange(ATRTrade aContext, MqlApi mql4) : base(mql4)
        {
            this.context = aContext;
            this.entryTime = mql4.Time[0];
            this.rangeHigh = mql4.High[0];
            this.rangeLow = mql4.Low[0];
            this.barCounter = 0;
            this.buffer = aContext.getRangeBufferInMicroPips() / OrderManager.getPipConversionFactor(mql4);
            context.setTradeType(TradeType.LONG);

            //context.addLogEntry("Lowest Low found - establishing eligibility range. Lowest low: " + mql4.DoubleToString(mql4.Close[0], mql4.Digits), true);
        }
        public HighestHighReceivedEstablishingEligibilityRange(ATRTrade aContext, MqlApi mql4) : base(mql4)
        {
            this.context = aContext;
            this.entryTime = mql4.Time[0];
            this.rangeHigh = mql4.High[0];
            this.rangeLow = mql4.Low[0];
            this.barCounter = 0;
            this.buffer = aContext.getRangeBufferInMicroPips() / OrderManager.getPipConversionFactor(mql4); ///Works for 5 Digts pairs. Verify that calculation is valid for 3 Digits pairs

            context.setTradeType(TradeType.SHORT);

            //context.addLogEntry("Highest high found - establishing eligibility range. Highest high: " + mql4.DoubleToString(mql4.Close[0], mql4.Digits), true);
        }
Ejemplo n.º 17
0
        public TradeClosed(Trade aContext, MqlApi mql4) : base(mql4)
        {
            this.context = aContext;
            this.context.Order.OrderType = OrderType.FINAL;
            context.setEndingBalance(mql4.AccountBalance());
            context.setTradeClosedDate(mql4.TimeCurrent());
            context.setSpreadOrderClose((int)mql4.MarketInfo(mql4.Symbol(), MqlApi.MODE_SPREAD));
            context.addLogEntry("Trade is closed", true);

            context.writeLogToCSV();

            context.setFinalStateFlag();

        }
Ejemplo n.º 18
0
        public Session(int aSessionID, string aSessionName, DateTime aSessionStartDateTime, DateTime aSessionEndDateTime, DateTime aHHLL_ReferenceDateTime, bool tradingFlag, int aHHLLThreshold, ATR_Type atrType, MqlApi mql4) : base(mql4)
        {
            this.sessionID = aSessionID;
            this.sessionName = aSessionName;
            this.sessionStartDateTime = aSessionStartDateTime;
            this.sessionEndDateTime = aSessionEndDateTime;
            this.HHLL_ReferenceDateTime = aHHLL_ReferenceDateTime;
            this.isTradingAllowed = tradingFlag;
            this.HHLL_Threshold = aHHLLThreshold;
            this.highestHigh = -1;
            this.lowestLow = 9999999999;
            this.atrType = atrType;

            initialize();
        }
Ejemplo n.º 19
0
        public ATRTrade(bool sim, int _lotDigits, string _logFileName, double _newHHLL, double _ATR, int _lengthIn1MBarsOfWaitingPeriod, double _percentageOfATRForMaxRisk, double _percentageOfATRForMaxVolatility,
            double _minProfitTarget, int _rangeBufferInMicroPips, double _rangeRestriction, double _tenDayRange, Session referenceSession, double _maxBalanceRisk, MqlApi mql4) : base(sim, _lotDigits, _logFileName, mql4)
        {
            this.newHHLL = _newHHLL;
            this.atr = _ATR;
            this.lengthIn1MBarsOfWaitingPeriod = _lengthIn1MBarsOfWaitingPeriod;
            this.percentageOfATRForMaxRisk = _percentageOfATRForMaxRisk;
            this.percentageOfATRForMaxVolatility = _percentageOfATRForMaxVolatility;
            this.minProfitTarget = _minProfitTarget;
            this.rangeBufferInMicroPips = _rangeBufferInMicroPips;
            this.rangeRestriction = _rangeRestriction;

            this.rangeHigh = 0;
            this.rangeLow = 0;
            this.rangePips = 0;
            this.newHHLL = _newHHLL;
            this.tenDayRange = _tenDayRange;
            this.referenceSession = referenceSession;
            this.currentDailyRange = mql4.iHigh(null, MqlApi.PERIOD_D1, 0) - mql4.iLow(null, MqlApi.PERIOD_D1, 0);
            this.maxBalanceRisk = _maxBalanceRisk;
        }
Ejemplo n.º 20
0
 public SarMacd(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 21
0
 public static ErrorType deleteOrder(int orderTicket, Trade trade, MqlApi mql4)
 {
     trade.addLogEntry("Attemting to delete Order (ticket number: " + mql4.IntegerToString(orderTicket) + ")", true);
     mql4.ResetLastError();
     bool success = mql4.OrderDelete(orderTicket, System.Drawing.Color.Red);
     return analzeAndProcessResult(trade, mql4);
 }
Ejemplo n.º 22
0
 public BearishEngulfing(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 23
0
 public FXEdgeShort(RoyalZigZagTrade _context, MqlApi mql4) : base(mql4)
 {
     this.context = _context;
 }
Ejemplo n.º 24
0
 public BullishEngulfing(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
 private ATRTrade context; //hides conext in Trade
 public BuyOrderFilledProfitTargetNotReached(ATRTrade aContext, MqlApi mql4) : base(mql4)
 {
     this.context = aContext;
     context.setOrderFilledDate(mql4.TimeCurrent());
     context.Order.OrderType = OrderType.BUY;
 }
 public StochasticIndicator(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
 public MovingAverageCrossoverIndicator(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 28
0
 public EveningDojiStar(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 29
0
 public SarIndicator(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 30
0
 public static double getPipConversionFactor(MqlApi mql4)
 {
     //multiplier depending on YEN or non YEN pairs
     if (mql4.Digits == 5)
         return 100000.00;
     else
         return 10000.00;
 }
Ejemplo n.º 31
0
 public static double getLotSize(double riskCapital, int riskPips, MqlApi mql4)
 {
     double pipValue = OrderManager.getPipValue(mql4);
     return riskCapital / ((double)riskPips * pipValue);
 }
Ejemplo n.º 32
0
 public TrenderOrderManager(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 33
0
 public MorningStar(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 34
0
 public Final(Order context, MqlApi mql4) : base(context, mql4)
 {
 }
Ejemplo n.º 35
0
 public OrderState(Order context, MqlApi mql4) : base(mql4)
 {
     this.context = context;
 }
 public StochasticIndicator(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 37
0
 public MACD(MqlApi api, string symbol, int period)
 {
     _mqlApi = api;
     _symbol = symbol;
     _period = period;
 }
Ejemplo n.º 38
0
 public CandleStickHelper(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 39
0
        public SimOrder(Trade trade, MqlApi mql4) : base (trade, mql4)
        {

        }
Ejemplo n.º 40
0
 public TrenderOrderManager(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 41
0
 public SIM_Pending(SimOrder context, MqlApi mql4) : base(context, mql4)
 {
     this.context = context;
 }
Ejemplo n.º 42
0
 public CandleStickHelper(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }
Ejemplo n.º 43
0
 public TrenderStrategy(string symbol, MqlApi mqlApi, TrendDirectionEnum trendDirection)
 {
     _symbol        = symbol;
     _mqlApi        = mqlApi;
     _trenDirection = trendDirection;
 }
Ejemplo n.º 44
0
 public static ErrorType analzeAndProcessResult(Trade trade, MqlApi mql4)
 {
     int result = mql4.GetLastError();
     switch (result)
     {
         //No Error
         case 0: return (ErrorType.NO_ERROR);
         // Not crucial errors                  
         case 4:
             mql4.Alert("Trade server is busy");
             trade.addLogEntry("Trade server is busy. Waiting 3000ms and then re-try", true);
             mql4.Sleep(3000);
             return (ErrorType.RETRIABLE_ERROR);
         case 135:
             mql4.Alert("Price changed. Refreshing Rates");
             trade.addLogEntry("Price changed. Refreshing Rates and retry", true);
             mql4.RefreshRates();
             return (ErrorType.RETRIABLE_ERROR);
         case 136:
             mql4.Alert("No prices. Refreshing Rates and retry");
             trade.addLogEntry("No prices. Refreshing Rates and retry", true);
             while (mql4.RefreshRates() == false)
                 mql4.Sleep(1);
             return (ErrorType.RETRIABLE_ERROR);
         case 137:
             mql4.Alert("Broker is busy");
             trade.addLogEntry("Broker is busy. Waiting 3000ms and then re-try", true);
             mql4.Sleep(3000);
             return (ErrorType.RETRIABLE_ERROR);
         case 146:
             mql4.Alert("Trading subsystem is busy.");
             trade.addLogEntry("Trade system is busy. Waiting 500ms and then re-try", true);
             mql4.Sleep(500);
             return (ErrorType.RETRIABLE_ERROR);
         // Critical errors      
         case 2:
             mql4.Alert("Common error.");
             trade.addLogEntry("Common error. Abort trade", true);
             return (ErrorType.NON_RETRIABLE_ERROR);
         case 5:
             mql4.Alert("Old terminal version.");
             trade.addLogEntry("Old terminal version. Abort trade", true);
             return (ErrorType.NON_RETRIABLE_ERROR);
         case 64:
             mql4.Alert("Account blocked.");
             trade.addLogEntry("Account blocked. Abort trade", true);
             return (ErrorType.NON_RETRIABLE_ERROR);
         case 133:
             mql4.Alert("Trading forbidden.");
             trade.addLogEntry("Trading forbidden. Abort trade", true);
             return (ErrorType.NON_RETRIABLE_ERROR);
         case 134:
             mql4.Alert("Not enough money to execute operation.");
             trade.addLogEntry("Not enough money to execute operation. Abort trade", true);
             return (ErrorType.NON_RETRIABLE_ERROR);
         case 4108:
             mql4.Alert("Order ticket was not found. Abort trade");
             trade.addLogEntry("Order ticket was not found. Abort trade", true);
             return (ErrorType.NON_RETRIABLE_ERROR);
         default:
             mql4.Alert("Unknown error, error code: ", result);
             return (ErrorType.NON_RETRIABLE_ERROR);
     } //end of switch
 }
Ejemplo n.º 45
0
 public SimFilled(SimOrder context, MqlApi mql4) : base(context, mql4)
 {
     this.context = context;
 }
Ejemplo n.º 46
0
 public MorningStar(MqlApi mqlApi, string symbol)
 {
     _mqlApi = mqlApi;
     _symbol = symbol;
 }