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; }
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); }
public CandleStick(MqlApi api, string symbol, int timeFrame, int period, int candleCount) { _mqlApi = api; _symbol = symbol; _timeFrame = timeFrame; _period = period; _candleCount = candleCount; }
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)); } }
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; }
public ScalperAdvisor(MqlApi api) { _mqlApi = api; _timeFrame = MqlApi.PERIOD_M5; _bollingersPeriod = 20; _candleStickPeriod = 20; _bollingersTrendDirectionCandleCount = 3; _candleStickCandleCount = 3; _bollingersMarginPoints = 1; _trailing = 30; }
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)); } }
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); }
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(); }
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(); }
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; }
public SarMacd(MqlApi mqlApi, string symbol) { _mqlApi = mqlApi; _symbol = symbol; }
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); }
public BearishEngulfing(MqlApi mqlApi, string symbol) { _mqlApi = mqlApi; _symbol = symbol; }
public FXEdgeShort(RoyalZigZagTrade _context, MqlApi mql4) : base(mql4) { this.context = _context; }
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; }
public EveningDojiStar(MqlApi mqlApi, string symbol) { _mqlApi = mqlApi; _symbol = symbol; }
public SarIndicator(MqlApi mqlApi, string symbol) { _mqlApi = mqlApi; _symbol = symbol; }
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; }
public static double getLotSize(double riskCapital, int riskPips, MqlApi mql4) { double pipValue = OrderManager.getPipValue(mql4); return riskCapital / ((double)riskPips * pipValue); }
public TrenderOrderManager(MqlApi mqlApi, string symbol) { _mqlApi = mqlApi; _symbol = symbol; }
public MorningStar(MqlApi mqlApi, string symbol) { _mqlApi = mqlApi; _symbol = symbol; }
public Final(Order context, MqlApi mql4) : base(context, mql4) { }
public OrderState(Order context, MqlApi mql4) : base(mql4) { this.context = context; }
public MACD(MqlApi api, string symbol, int period) { _mqlApi = api; _symbol = symbol; _period = period; }
public CandleStickHelper(MqlApi mqlApi, string symbol) { _mqlApi = mqlApi; _symbol = symbol; }
public SimOrder(Trade trade, MqlApi mql4) : base (trade, mql4) { }
public SIM_Pending(SimOrder context, MqlApi mql4) : base(context, mql4) { this.context = context; }
public TrenderStrategy(string symbol, MqlApi mqlApi, TrendDirectionEnum trendDirection) { _symbol = symbol; _mqlApi = mqlApi; _trenDirection = trendDirection; }
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 }
public SimFilled(SimOrder context, MqlApi mql4) : base(context, mql4) { this.context = context; }