/// <summary> /// Initializes a new instance of the <see cref="TradesGetViewModel" /> class. /// </summary> /// <param name="dateTime">dateTime.</param> /// <param name="price">price.</param> /// <param name="amount">amount.</param> /// <param name="type">type.</param> public TradesGetViewModel(long dateTime = default(long), double price = default(double), double amount = default(double), TradeType?type = default(TradeType?)) { this.DateTime = dateTime; this.Price = price; this.Amount = amount; this.Type = type; }
protected override void OnTick() { manageTrailingStops(); int index = MarketSeries.Close.Count - 1; if (index <= savedIndex) return; savedIndex = index; Position position = CurrentPosition(); if (ExitOnOppositeSignal && position != null && isCloseSignal(index)) ClosePosition(position); TradeType? tradeType = signal(index); if (tradeType.HasValue) executeOrder(tradeType.Value); minPipsATR = Math.Min(minPipsATR, pipsATR.Result.LastValue); maxPipsATR = Math.Max(maxPipsATR, pipsATR.Result.LastValue); ceilSignalPipsATR = minPipsATR + ((maxPipsATR - minPipsATR) / 9) * VolFactor; RefreshData(); //foreach (var positions in Positions) //{ //if (positions.StopLoss == null) // //Print("Modifying {0}", position.Id); // ModifyPosition(positions, GetAbsoluteStopLoss(positions, 10), GetAbsoluteTakeProfit(positions, 10)); }
public override TradeType?signal() { //throw new NotImplementedException(); var upper = boll.Top.Last(1); var lower = boll.Bottom.Last(1); TradeType?tradeType = null; if (Condition == null || Condition == "Default") { if (Robot.Symbol.Mid() > upper) { tradeType = TradeType.Sell; } if (Robot.Symbol.Mid() < lower) { tradeType = TradeType.Buy; } } else if (Condition == "RisingAndFalling") { if (Robot.Symbol.Mid() > upper && !boll.Bottom.IsFalling()) { tradeType = TradeType.Sell; } if (Robot.Symbol.Mid() < lower && !boll.Top.IsRising()) { tradeType = TradeType.Buy; } } return(tradeType); }
protected override void OnTick() { if (Trade.IsExecuting) { return; } TradeType?tradeType = signal(); if (tradeType.HasValue) { openPosition(tradeType, Volume, 0, Stop_Loss, null, ""); } bool _isMacdMainAboveMacdSignal = (_macdPrbSARnoiseIndicator.Histogram.LastValue > _macdPrbSARnoiseIndicator.Signal.LastValue); bool _isParabolicSARBelowMaClose = (_macdPrbSARnoiseIndicator.ParabolicSAR.LastValue < MarketSeries.Close.LastValue); if (_position != null)// && _position.NetProfit > Math.Abs(_position.Commissions + _position.Swap)) { if (_position.TradeType == TradeType.Sell && _isMacdMainAboveMacdSignal && _isParabolicSARBelowMaClose) { closePosition(); } else if (_position.TradeType == TradeType.Buy && !_isMacdMainAboveMacdSignal && !_isParabolicSARBelowMaClose) { closePosition(); } } }
public double Convert(double amount, string from, string to, TradeType?tradeType) { var symbol = Feed.GetSymbol(to + from); bool inverse = false; if (symbol == null) { inverse = true; symbol = Feed.GetSymbol(from + to); } if (symbol == null) { return(double.NaN); } double result = amount; var bid = symbol.Bid; var ask = symbol.Ask; if (double.IsNaN(bid) || double.IsNaN(ask)) { throw new Exception("Currency conversion symbol pricing is not available for {from} to {to}"); } double conversion = !tradeType.HasValue ? ((ask + bid) / 2.0) : (!inverse ? tradeType == TradeType.Buy ? ask : bid : 1.0 / (tradeType == TradeType.Buy ? bid : ask)); // REVIEW result *= conversion; return(result); }
protected override void OnTick() { manageTrailingStops(); int index = MarketSeries.Close.Count - 1; if (index <= savedIndex) { return; } savedIndex = index; Position position = CurrentPosition(); if (ExitOnOppositeSignal && position != null && isCloseSignal(index)) { ClosePosition(position); } TradeType?tradeType = signal(index); if (tradeType.HasValue) { executeOrder(tradeType.Value); } }
public async Task <string[]> CancelAllStopOrders(string symbol = null, TradeType?tradeType = null, IEnumerable <string> orderIds = null) { // /api/v1/orders var dict = new Dictionary <string, object>(); if (orderIds != null) { var sb = new StringBuilder(); foreach (var o in orderIds) { if (sb.Length > 0) { sb.Append(","); } sb.Append(o); } dict.Add("orderIds", sb.ToString()); } if (symbol != null) { dict.Add("symbol", symbol); } if (tradeType != null) { dict.Add("tradeType", EnumToStringConverter <TradeType> .GetEnumName((TradeType)tradeType)); } var jobj = await MakeRequest(HttpMethod.Delete, "/api/v1/stop-order/cancel", reqParams : dict); return(jobj["cancelledOrderIds"].ToObject <string[]>()); }
/// <summary> /// Manage taking position. /// </summary> private void controlRobot() { TradeType?tradeType = this.signal(strategies); if (tradeType.HasValue) { if (tradeType.isBuy()) { this.closeAllSellPositions(_instanceLabel); if (this.existBuyPositions(_instanceLabel)) { return; } } else { this.closeAllBuyPositions(_instanceLabel); if (this.existSellPositions(_instanceLabel)) { return; } } initialOP.TradeType = tradeType.Value; initialOP.Volume = InitialVolume; this.splitAndExecuteOrder(initialOP); } }
/// <summary> /// Initializes a new instance of the <see cref="GetTradeHistoryResponse" /> class. /// </summary> /// <param name="dateTime">dateTime.</param> /// <param name="price">price.</param> /// <param name="amount">amount.</param> /// <param name="type">type.</param> public GetTradeHistoryResponse(long dateTime = default(long), double price = default(double), double amount = default(double), TradeType?type = default(TradeType?)) { this.DateTime = dateTime; this.Price = price; this.Amount = amount; this.Type = type; }
public async Task <IReadOnlyList <TradeModel> > GetTrades( [FromQuery] Guid walletId, [FromQuery] string assetId = null, [FromQuery] string assetPairId = null, [FromQuery] int offset = 0, [FromQuery] int limit = 100, [FromQuery] DateTime?from = null, [FromQuery] DateTime?to = null, [FromQuery(Name = "tradeType")] TradeType?tradeType = null) { bool?onlyBuyTrades = null; if (tradeType == TradeType.Buy) { onlyBuyTrades = true; } if (tradeType == TradeType.Sell) { onlyBuyTrades = false; } var data = await _historyRecordsRepository.GetTradesByWalletAsync(walletId, offset, limit, assetPairId, assetId, from, to, onlyBuyTrades); return(Mapper.Map <IReadOnlyList <TradeModel> >(data)); }
protected override void OnBar() { // Prevents running this in production if (!IsBacktesting) { return; } if ((Ask - Bid) > _maxSpreadLimitAbsolute) { return; } if (Positions.FindAll(Name, SymbolName).Any()) { return; } TradeType?tradeType = GetMLPrediction(); if (tradeType == null) { return; } ExecuteMarketOrder(tradeType.Value, Symbol.Name, Volume, Name, Pips, Pips); }
protected override void OnTick() { manageTrailingStops(); int index = MarketSeries.Close.Count - 1; if (index <= savedIndex) { return; } savedIndex = index; Position position = CurrentPosition(); if (ExitOnOppositeSignal && position != null && isCloseSignal(index)) { ClosePosition(position); } TradeType?tradeType = signal(index); if (tradeType.HasValue) { executeOrder(tradeType.Value); } minPipsATR = Math.Min(minPipsATR, pipsATR.Result.LastValue); maxPipsATR = Math.Max(maxPipsATR, pipsATR.Result.LastValue); ceilSignalPipsATR = minPipsATR + ((maxPipsATR - minPipsATR) / 9) * VolFactor; RefreshData(); }
/// <summary> /// Initializes a new instance of the <see cref="ApiGetTradeHistory" /> class. /// </summary> /// <param name="tradeType">tradeType.</param> /// <param name="pair">pair.</param> /// <param name="dateCreated">dateCreated.</param> /// <param name="dateClosed">dateClosed.</param> /// <param name="amount">amount.</param> /// <param name="price">price.</param> public ApiGetTradeHistory(TradeType?tradeType = default(TradeType?), string pair = default(string), long dateCreated = default(long), long dateClosed = default(long), double amount = default(double), double price = default(double)) { this.TradeType = tradeType; this.Pair = pair; this.DateCreated = dateCreated; this.DateClosed = dateClosed; this.Amount = amount; this.Price = price; }
// Gere la prise de position private void buyAndSell() { TradeType?tradeType = signalStrategie(); if (tradeType.HasValue) { splitAndExecuteOrder(tradeType.Value, InitialVolume, botLabel); } }
public static bool isSell(this TradeType?tradeType) { if (tradeType.HasValue) { return(TradeType.Sell == tradeType); } return(false); }
public static bool isBuy(this TradeType?tradeType) { if (tradeType.HasValue) { return(TradeType.Buy == tradeType); } return(false); }
/// <summary>Create a random trade</summary> private void CreateOrder(TradeType? preferred = null) { if (Position != null) throw new Exception("Position already exists"); // Choose a trade type var tt = preferred ?? (m_rng.Float() > 0.5f ? TradeType.Buy : TradeType.Sell); var trade = new Trade(Bot, Instrument, tt, Label); Position = Bot.Broker.CreateOrder(trade); }
public static TradeType?inverseTradeType(this TradeType?tradeType) { if (tradeType.HasValue) { return(tradeType.Value.inverseTradeType()); } else { return(null); } }
public static int factor(this TradeType?tradeType) { if (tradeType.HasValue) { return(tradeType.Value.factor()); } else { return(0); } }
internal void DrawDirection(Robot robot, TradeType?direction) { if (direction.HasValue) { robot.Print("Direction: {0}", direction.Value.ToString()); DirectionIcon = robot.Chart.DrawIcon("DirectionIcon", (direction.Value == TradeType.Buy ? ChartIconType.UpArrow : ChartIconType.DownArrow), robot.TimeInUtc, robot.Bid, (direction.Value == TradeType.Buy ? Color.Green : Color.Red)); } else { robot.Print("Direction is not defined."); } }
public double GetExposure(AccountAssetType assetType, TradeType?tradeType = null, StakeType?stakeType = null, string symbol = null) { double sum = 0.0; if ((stakeType & StakeType.Position) == StakeType.Position) { } if ((stakeType & StakeType.Order) == StakeType.Order) { } //var source return(sum); }
public async Task <IList <Fill> > ListFills( string symbol = null, Side?side = null, OrderType?type = null, TradeType?tradeType = null, DateTime?startAt = null, DateTime?endAt = null ) { var lp = new OrderListParams(null, symbol, side, type, tradeType, startAt, endAt); return(await ListFills(lp)); }
public OrderParams(TradeType?tradeType, Symbol symbol, double?volume, string label, double?stopLoss, double?takeProfit, double?slippage, string comment, int?id, List <double> parties) { TradeType = tradeType; Symbol = symbol; Volume = volume; Label = label; StopLoss = stopLoss; TakeProfit = takeProfit; Slippage = slippage; Comment = comment; Id = id; Parties = parties; }
public async Task <IList <OrderDetails> > ListOrders( OrderStatus?status = null, string symbol = null, Side?side = null, OrderType?type = null, TradeType?tradeType = null, DateTime?startAt = null, DateTime?endAt = null ) { var lp = new OrderListParams(status, symbol, side, type, tradeType, startAt, endAt); return(await ListOrders(lp)); }
protected override void OnTick() { double averageTrueRange = 100000 * Indicators.AverageTrueRange(MarketSeries, 5, MovingAverageType.VIDYA).Result.Last(0); TradeType?tradeType = signal(); if (tradeType.HasValue) { ExecuteMarketOrder(tradeType.Value, Symbol, InitialVolume, _instanceLabel, 100, 100, 2); } SetTrailingStop(averageTrueRange); ZeroLoss(); }
private TradeType?signal() { TradeType?tradeType = null; if (_macdPrbSARnoiseIndicator.Result.LastValue > 0) { tradeType = TradeType.Buy; } else if (_macdPrbSARnoiseIndicator.Result.LastValue < 0) { tradeType = TradeType.Sell; } return(tradeType); }
public override TradeType?signal1() { //throw new NotImplementedException(); Initialize(); TradeType?tradeType = null; if (Robot.Symbol.Mid() > uppermax) { tradeType = TradeType.Sell; } if (Robot.Symbol.Mid() < lowermin) { tradeType = TradeType.Buy; } return(tradeType); }
public override TradeType?signal3() { //throw new NotImplementedException(); Initialize(); TradeType?tradeType = null; if (Robot.MarketSeries.isBearCandle(1) == true && Robot.MarketSeries.isCandleOver(1, midmax)) { tradeType = TradeType.Buy; } if (Robot.MarketSeries.isBullCandle(1) == true && Robot.MarketSeries.isCandleOver(1, midmin)) { tradeType = TradeType.Sell; } return(tradeType); }
public override TradeType?signal() { var result = ee.Result.LastValue; var average = ee.Average.LastValue; TradeType?tt = null; if (Robot.Positions.Count == 0) { if (result > average + Distance) { tt = TradeType.Buy; } if (result < average - Distance) { tt = TradeType.Sell; } } else { var now = DateTime.UtcNow; if (DateTime.Compare(Robot.Positions[Robot.Positions.Count - 1].EntryTime.AddHours(1), now) < 0) { if (result > average + Distance) { tt = TradeType.Buy; } if (result < average - Distance) { tt = TradeType.Sell; } } else { var eb = Math.Abs(Robot.Positions[Robot.Positions.Count - 1].EntryPrice - Robot.Positions[Robot.Positions.Count - 2].EntryPrice) / Robot.Symbol.PipSize; if (result > average + eb + 10) { tt = TradeType.Buy; } if (result < average - eb - 10) { tt = TradeType.Sell; } } } return(tt); }
public OrderListParams( OrderStatus?status = null, string symbol = null, Side?side = null, OrderType?type = null, TradeType?tradeType = null, DateTime?startAt = null, DateTime?endAt = null ) { Status = status; Symbol = symbol; Side = side; Type = type; TradeType = tradeType; StartAt = startAt; EndAt = endAt; }