protected virtual void OnPositionOpened(PositionOpenedEventArgs args) { BarsSinceEntry = 0; RecentHigh = InitialRecentHigh; RecentLow = InitialRecentLow; _currentPosition = args.Position; var position = args.Position; var sl = position.StopLoss.HasValue ? string.Format(" (SL={0})", position.StopLoss.Value) : string.Empty; var tp = position.TakeProfit.HasValue ? string.Format(" (TP={0})", position.TakeProfit.Value) : string.Empty; Print("{0} {1:N} at {2}{3}{4}", position.TradeType, position.VolumeInUnits, position.EntryPrice, sl, tp); CalculateBreakEvenPrice(); CalculateDoubleRiskPrice(); CalculateTripleRiskPrice(); CalculateTrailingInitiationPrice(); _canOpenPosition = false; ShouldTrail = true; }
private void OnPositionsOpened(PositionOpenedEventArgs obj) { Position pos = obj.Position; if (pos.Label == _t_abovelabel) { var t_idx = pos.Comment.IndexOf("M_") + 2; _t_a_marklist.Add(pos.Comment.Substring(t_idx, 13)); Print("It's successful to add a mark for T-A-" + Symbol.Code + "."); } if (pos.Label == _t_belowlabel) { var t_idx = pos.Comment.IndexOf("M_") + 2; _t_b_marklist.Add(pos.Comment.Substring(t_idx, 13)); Print("It's successful to add a mark for T-B-" + Symbol.Code + "."); } if (pos.Label != _h_abovelabel && pos.Label != _h_belowlabel) { return; } var idx = pos.Comment.IndexOf("M_") + 2; _h_marklist.Add(pos.Comment.Substring(idx, 13)); Print("It's successful to add a mark for " + Symbol.Code + "."); }
private void OnPositionOpened(PositionOpenedEventArgs args) { double?stopLossPrice = null; double?takeProfitPrice = null; switch (GetPositionsSide()) { case 0: double averageBuyPrice = GetAveragePrice(TradeType.Buy); takeProfitPrice = averageBuyPrice + TakeProfit * Symbol.PipSize; stopLossPrice = averageBuyPrice - stopLoss * Symbol.PipSize; break; case 1: double averageSellPrice = GetAveragePrice(TradeType.Sell); takeProfitPrice = averageSellPrice - TakeProfit * Symbol.PipSize; stopLossPrice = averageSellPrice + stopLoss * Symbol.PipSize; break; } if (stopLossPrice.HasValue || takeProfitPrice.HasValue) { Position[] positions = GetPositions(); foreach (Position position in positions) { if (stopLossPrice != position.StopLoss || takeProfitPrice != position.TakeProfit) { ModifyPosition(position, stopLossPrice, takeProfitPrice); } } } }
/// <summary> /// Operazioni da compiere ogni volta che apro una posizione con questa label /// </summary> private void _onOpenPositions(PositionOpenedEventArgs eventArgs) { if (eventArgs.Position.SymbolName == Monitor1.Symbol.Name && eventArgs.Position.Label == Monitor1.Label) { Monitor1.OpenedInThisBar = true; } }
private void PositionsOpened(PositionOpenedEventArgs obj) { if (!IsBacktesting) { Business.Positions.Update(Account, obj.Position, "Opened"); } }
private void PositionsOnOpened(PositionOpenedEventArgs args) { if (args.Position.Label == vLabel) { //Print(vLabel + " POSITION OPENED DELEGATE CALLED"); vPos = args.Position; } }
private void PositionsOnOpened(PositionOpenedEventArgs args) { var pos = args.Position; lastPositionOpenTime = pos.EntryTime; //string txt = "OnOpened()"; //SendNotificationEmail(pos, txt); }
private void OnPositionsOpened(PositionOpenedEventArgs args) { if (args.Position.SymbolCode == Symbol.Code) { ticks = 0; OnTick(); } }
protected void OnPositionOpened(PositionOpenedEventArgs args) { var position = args.Position; double stopLoss = position.TradeType == TradeType.Buy ? position.EntryPrice - Symbol.PipSize * StopLoss : position.EntryPrice + Symbol.PipSize * StopLoss; double takeProfit = position.TradeType == TradeType.Buy ? position.EntryPrice + Symbol.PipSize * TakeProfit : position.EntryPrice - Symbol.PipSize * TakeProfit; ModifyPosition(position, stopLoss, takeProfit); }
void OnPositionsOpened(PositionOpenedEventArgs args) { var originalPosition = args.Position; if (originalPosition.Label != Label) { var tradeType = originalPosition.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy; ExecuteMarketOrder(tradeType, Symbol, originalPosition.Volume, Label); } }
/// <summary>Handle a position opened</summary> private void HandlePositionOpened(object sender, PositionOpenedEventArgs e) { var pos = e.Position; var rec = Records[pos.Id]; rec.Sign = pos.Sign(); rec.Index = Instrument.IndexAt(pos.EntryTime) - Instrument.IdxFirst; rec.Events.Add("Opened"); }
protected override void OnPositionOpened(PositionOpenedEventArgs args) { base.OnPositionOpened(args); ShouldTrail = false; //PrintLatestValues(); LogSignalData(args); }
//+------------------------------------------------------------------+ //| OnPositionOpened | //+------------------------------------------------------------------+ protected void OnPositionOpened(PositionOpenedEventArgs args) { var position = args.Position; if (position.Label == label && position.SymbolCode == Symbol.Code) { entryBar = MarketSeries.Close.Count - 1; } }
private void PositionsOnOpened(PositionOpenedEventArgs obj) { Print("Position opened."); var pos = obj.Position; if (pos.Label == Label) { currentPosition = pos; pendingOrder = null; } }
private void PositionsOnOpened(PositionOpenedEventArgs obj) { Position openedPosition = obj.Position; if (openedPosition.Label != cBotLabel) { return; } Print("position opened at {0}", openedPosition.EntryPrice); }
protected void PositionsOnOpened(PositionOpenedEventArgs args) { if (isThisBotId(args.Position.Label)) { _openedPositionsCount++; //Capture last Position Opened i.e. the furthest away _lastPositionTradeType = args.Position.TradeType; _lastPositionEntryPrice = args.Position.EntryPrice; _lastPositionLabel = args.Position.Label; } }
private void OnPositionsOpened(PositionOpenedEventArgs obj) { Position pos = obj.Position; if (pos.Label != _abovelabel && pos.Label != _belowlabel) { return; } var idx = pos.Comment.IndexOf("M_") + 2; _marklist.Add(pos.Comment.Substring(idx, 13)); Print("It's successful to add a mark for XAUXAG."); }
protected void OnPositionOpened(PositionOpenedEventArgs args) { var position = args.Position; Limits limits = new Limits(position.TradeType, position.EntryPrice, Symbol.PipSize, TakeProfit, StopLoss); //position.LimitsExt().SL_PIPS = StopLoss; //position.LimitsExt().TP_PIPS = TakeProfit; // double stopLoss = position.TradeType == TradeType.Buy ? position.EntryPrice - Symbol.PipSize * StopLoss : position.EntryPrice + Symbol.PipSize * StopLoss; // double takeProfit = position.TradeType == TradeType.Buy ? position.EntryPrice + Symbol.PipSize * TakeProfit : position.EntryPrice - Symbol.PipSize * TakeProfit; ModifyPosition(position, limits.StopLoss, limits.TakeProfit); }
private void OnPositionsOpened(PositionOpenedEventArgs args) { var position = args.Position; Print("open {0} stop with {1} lotsize", position.TradeType, position.Quantity); // ignore first order if (position.Label == "ExeTheFirstOrder") { return; } // consequence pending order PlaceStopOrder(calPos.nextType(), SymbolName, InitialVolumeInUnits * calPos.nextSize(), calPos.nextTargetPriceToLive(), "consequence"); }
private void OnPositionOpened(PositionOpenedEventArgs args) { CurrentPosition = args.Position; var sl = CurrentPosition.StopLoss.HasValue ? string.Format(" (SL={0})", CurrentPosition.StopLoss.Value) : string.Empty; var tp = CurrentPosition.TakeProfit.HasValue ? string.Format(" (TP={0})", CurrentPosition.TakeProfit.Value) : string.Empty; Print("{0} {1:N} at {2}{3}{4}", CurrentPosition.TradeType, CurrentPosition.VolumeInUnits, CurrentPosition.EntryPrice, sl, tp); _canOpenPosition = false; }
protected void OnPositionOpen(PositionOpenedEventArgs args) { tm.CancelAllPendingPositions(InstanceName); // DETERMINE DIRECTION OF REBOUND BASED ON DIRECTION OF INITIAL PENDING ORDER // EG. IF A SELL IS TRIGGERED, THE REBOUND DIRECTION WOULD BE A BUY if (args.Position.TradeType.ToString().ToLower() == "sell") { reboundDirection = "buy"; } else { reboundDirection = "sell"; } }
protected override void OnPositionOpened(PositionOpenedEventArgs args) { _closedHalf = false; base.OnPositionOpened(args); ShouldTrail = false; if (RecordSession) { _currentPositionId = SaveOpenedPositionToDatabase(args.Position); if (_currentPositionId <= 0) { throw new InvalidOperationException("Position ID was <= 0!"); } } }
protected override void OnPositionOpened(PositionOpenedEventArgs args) { base.OnPositionOpened(args); ShouldTrail = false; Print("Trailing will be initiated if price reaches {0}", TrailingInitiationPrice); if (RecordSession) { _currentPositionId = SaveOpenedPositionToDatabase(args.Position); if (_currentPositionId <= 0) { throw new InvalidOperationException("Position ID was <= 0!"); } } }
protected void PositionsOnOpened(PositionOpenedEventArgs args) { if (isThisBotId(args.Position.Label)) { _openedPositionsCount++; //Capture last Position Opened i.e. the furthest away _lastPositionTradeType = args.Position.TradeType; _lastPositionEntryPrice = args.Position.EntryPrice; _lastPositionLabel = args.Position.Label; //Set TP for all positions based on their entry point if Pending Orders are triggered if (Positions.Count > NumberOfPositions) { setCascadingTakeProfit(); } } }
private void OnPositionOpened(PositionOpenedEventArgs args) { var position = args.Position; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (Oco) { foreach (var order in PendingOrders) { if (order.Label == Label && order.SymbolCode == Symbol.Code) { CancelPendingOrderAsync(order); } } } } }
protected void OnPositionOpen(PositionOpenedEventArgs args) { // DETERMINE DIRECTION OF MOVEMENT BASED ON WHICH PENDING ORDER WAS TRIPPED // EG. IF A SELL IS TRIGGERED, WE WANT TO SIGNAL TO CANCEL ALL PENDING BUY ORDERS if (args.Position.Label == InstanceName + "PIP10") { foreach (var position in Positions) { if (args.Position.TradeType.ToString().ToLower() == "sell") { tm.CancelPendingPositions(position.Label, "buy"); } else if (args.Position.TradeType.ToString().ToLower() == "buy") { tm.CancelPendingPositions(position.Label, "sell"); } } } }
private void OnPositionOpened(PositionOpenedEventArgs positionClosedEventArgs) { try { var openedPosition = positionClosedEventArgs.Position; if (openedPosition.Label != Label || openedPosition.SymbolCode != Symbol.Code) { return; } CreatePendingOrder(openedPosition); SetTakeProfit(Label, openedPosition.TradeType); streakTrades++; } catch (Exception e) { Print("Index Error Caught"); } }
private void OnPositionOpened(PositionOpenedEventArgs args) { double?StopLossPrice = null; double?TakeProfitPrice = null; if (Positions.Count == 1) { var position = args.Position; if (position.TradeType == TradeType.Buy) { TakeProfitPrice = position.EntryPrice + TakeProfit * Symbol.TickSize; } if (position.TradeType == TradeType.Sell) { TakeProfitPrice = position.EntryPrice - TakeProfit * Symbol.TickSize; } } else { switch (GetPositionsSide()) { case 0: TakeProfitPrice = GetAveragePrice(TradeType.Buy) + TakeProfit * Symbol.TickSize; break; case 1: TakeProfitPrice = GetAveragePrice(TradeType.Sell) - TakeProfit * Symbol.TickSize; break; } } for (int i = 0; i < Positions.Count; i++) { var position = Positions[i]; if (StopLossPrice != null || TakeProfitPrice != null) { ModifyPosition(position, position.StopLoss, TakeProfitPrice); } } }
private void Positions_Opened(PositionOpenedEventArgs obj) { var pos = obj.Position; if (pos.TradeType == TradeType.Sell && pos.Label == (Sell + SymbolName)) { var buyOrder = PendingOrders.Where(x => x.Label == (Buy + SymbolName)).FirstOrDefault(); if (buyOrder != null) { var rc = CancelPendingOrder(buyOrder); if (!rc.IsSuccessful) { Print("Cancel Penidng Order Failed: " + rc.Error.Value); } } Log.WriteRpt(Server.Time, pos.Label, TradeType.Sell.ToString(), "Open", pos.EntryPrice.ToString(), pos.StopLoss.HasValue ? ((double)pos.StopLoss).ToString() : "", pos.TakeProfit.HasValue ? ((double)pos.TakeProfit).ToString() : "", pos.VolumeInUnits.ToString(), Account.Balance.ToString(), pos.Pips.ToString(), high.ToString(), low.ToString(), ""); } else if (pos.TradeType == TradeType.Buy && pos.Label == (Buy + SymbolName)) { var sellOrder = PendingOrders.Where(x => x.Label == (Sell + SymbolName)).FirstOrDefault(); if (sellOrder != null) { var rc = CancelPendingOrder(sellOrder); if (!rc.IsSuccessful) { Print("Cancel Penidng Order Failed: " + rc.Error.Value); } } Log.WriteRpt(Server.Time, pos.Label, TradeType.Buy.ToString(), "Open", pos.EntryPrice.ToString(), pos.StopLoss.HasValue ? ((double)pos.StopLoss).ToString() : "", pos.TakeProfit.HasValue ? ((double)pos.TakeProfit).ToString() : "", pos.VolumeInUnits.ToString(), Account.Balance.ToString(), pos.Pips.ToString(), high.ToString(), low.ToString(), ""); } }
public void OnPositionOpened(PositionOpenedEventArgs args) { // --> Condividiamo solo il cross corrente? if (OonlyThis && args.Position.SymbolName != SymbolName) { return; } double sl = (args.Position.StopLoss == null) ? 0 : (double)args.Position.StopLoss; double tp = (args.Position.TakeProfit == null) ? 0 : (double)args.Position.TakeProfit; string messageformat = string.Format(Message, args.Position.SymbolName, args.Position.TradeType, args.Position.EntryPrice, args.Position.Quantity, sl, tp); try { // --> Mi servono i permessi di sicurezza per il dominio, compreso i redirect Uri myuri = new Uri(Webhook); string pattern = string.Format("{0}://{1}/.*", myuri.Scheme, myuri.Host); // --> Autorizzo tutte le pagine di questo dominio Regex urlRegEx = new Regex(pattern); WebPermission p = new WebPermission(NetworkAccess.Connect, urlRegEx); p.Assert(); // --> Protocollo di sicurezza https:// ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; using (WebClient wc = new WebClient()) { wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; string HtmlResult = wc.UploadString(myuri, string.Format(PostParams, messageformat)); } } catch (Exception exc) { MessageBox.Show(string.Format("{0}\r\nstopping cBots 'Share Opened Trades To Webhook' ...", exc.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Stop(); } }
private void OnPositionOpened(PositionOpenedEventArgs args) { var position = args.Position; if (position.Label == Label && position.SymbolCode == Symbol.Code) { if (Oco) { foreach (var order in PendingOrders) { if (order.Label == Label && order.SymbolCode == Symbol.Code) { CancelPendingOrderAsync(order); } } } Stop(); } }
protected void OnPositionOpened(PositionOpenedEventArgs args) { Position position = args.Position; ModifyPosition(position, position.pipsToStopLoss(Symbol, StopLoss), position.pipsToTakeProfit(Symbol, TakeProfit)); }
private void OnPositionOpened(PositionOpenedEventArgs args) { double? stopLossPrice = null; double? takeProfitPrice = null; switch (GetPositionsSide()) { case 0: double averageBuyPrice = GetAveragePrice(TradeType.Buy); takeProfitPrice = averageBuyPrice + TakeProfit * Symbol.PipSize; stopLossPrice = averageBuyPrice - stopLoss * Symbol.PipSize; break; case 1: double averageSellPrice = GetAveragePrice(TradeType.Sell); takeProfitPrice = averageSellPrice - TakeProfit * Symbol.PipSize; stopLossPrice = averageSellPrice + stopLoss * Symbol.PipSize; break; } if (stopLossPrice.HasValue || takeProfitPrice.HasValue) { Position[] positions = GetPositions(); foreach (Position position in positions) { if (stopLossPrice != position.StopLoss || takeProfitPrice != position.TakeProfit) ModifyPosition(position, stopLossPrice, takeProfitPrice); } } }
private void PositionsOnOpened(PositionOpenedEventArgs obj) { Position openedPosition = obj.Position; if (openedPosition.Label != EALabel) return; Print("position opened at {0}", openedPosition.EntryPrice); }
protected void OnPositionOpened(PositionOpenedEventArgs args) { }
private void OnPositionOpened(PositionOpenedEventArgs args) { Position openedPosition = position = args.Position; ModifyPosition(openedPosition, GetAbsoluteStopLoss(openedPosition, StopLoss), GetAbsoluteTakeProfit(openedPosition, TakeProfit)); }