private void OnPositionsClosed(PositionClosedEventArgs args) { //Print("Closed"); var position = args.Position; if (position.NetProfit > 0) { currentVolume = InitialVolume; counterLoss = 0; } else { if (noActivePositions()) { counterLoss++; if (counterLoss % increaseAfter == 0) { if (counterLoss >= 16) { updateVolumePositionsManual(); } else { currentVolume *= 2; } //Print("counterloss = " + counterLoss); } } } }
private void PositionsOnClosed(PositionClosedEventArgs args) { try { var po = args.Position; Task.Factory.StartNew(() => FixAfterClose(po)).Wait(); //if (isCalculatingOnClose) //{ // lsOnClose.Add(po.Label); // return; //} //Task.Factory.StartNew(() => FixAfterClose(po)).Wait(); //while (lsOnClose.Count > 0) //{ // //Task.Factory.StartNew(() => CheckClose(po.Label)).Wait(); // lsOnClose.RemoveAt(0); //} ////Task.Factory.StartNew(() => FixAfterClose(po)).Wait(); ////NewOpenOrFixInLength(); ////CleanDupOrderAndPending(); //isCalculatingOnOpen = false; } catch (Exception ex) { Print("Error PositionsOnClosed >> " + ex.Message); } }
private void PositionsOnClosed(PositionClosedEventArgs args) { var pos = args.Position; specialPositionsList.Remove(pos); //remove position from list if there Print("Position closed with {0} comment", pos.Comment); }
protected void PositionsOnClosed(PositionClosedEventArgs args) { if (isThisBotId(args.Position.Label)) { _closedPositionsCount++; //Last position's SL has been triggered for a loss - NOT a swordfish if (_lastPositionLabel == args.Position.Label && args.Position.GrossProfit < 0) { Print("CLOSING ALL POSITIONS due to furthest position losing"); CloseAllPendingOrders(); CloseAllPositions(); _isSwordfishTerminated = true; } //Taking profit if (args.Position.GrossProfit > 0) { //capture last position take profit price setLastProfitPrice(args.Position.TradeType); //capture last closed position entry price _lastClosedPositionEntryPrice = args.Position.EntryPrice; //If the spike has retraced then close all pending and set trailing stop ManagePositionRisk(); //BreakEven SL triggered in ManageRisk() function if (_isBreakEvenStopLossActive) { setBreakEvens(_lastProfitBreakEvenPrice); } } } }
private void Positions_Closed(PositionClosedEventArgs obj) { var pos = obj.Position; string reason = string.Empty; switch (obj.Reason) { case PositionCloseReason.Closed: reason = "Position was closed by trader"; break; case PositionCloseReason.StopLoss: reason = "Position was closed by Stop Loss"; break; case PositionCloseReason.StopOut: reason = "Position was closed because Stop Out level reached"; break; case PositionCloseReason.TakeProfit: reason = "Position was closed by Take Profit"; break; } if (pos.TradeType == TradeType.Sell && pos.Label == (Sell + SymbolName)) { Log.WriteRpt(Server.Time, pos.Label, TradeType.Sell.ToString(), "Close", 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(), reason); } else if (pos.TradeType == TradeType.Buy && pos.Label == (Buy + SymbolName)) { Log.WriteRpt(Server.Time, pos.Label, TradeType.Buy.ToString(), "Close", 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(), reason); } }
/// <summary> /// Event Handler for positions closed event /// NOTE :: This event is called when a position is closed, whether that position /// was closed by this bot or another bot or by a user manually /// </summary> /// <param name="obj"></param> private void Positions_Closed(PositionClosedEventArgs obj) { // null check event argument if (obj == null) { return; } if (obj.Position == null) { return; } // check if event was meant for this bot, using the position label if (obj.Position.Label != this.BotID) { return; } // continue to handle event var closedPosition = obj.Position; var closeReason = obj.Reason; this.LogInformation(closedPosition.TradeType.ToString() + " Position closed for " + this.BotName + " bot with id " + this.BotID + ", Reason: " + closeReason.ToString()); // re-activate bot CanSendOrders flag if no positions or orders are open if (this.CountPositions() == 0 && this.CountPedingOrders() == 0) { this.ClearAllLines(); this.Zero_Line = 0; this.Buy_Line = 0; this.Sell_Line = 0; this.CanOpenPosition = true; } }
private void OnPositionsClosed(PositionClosedEventArgs args) { OneShot = false; state = "WaitingCross"; //Print("Closed"); var position = args.Position; if (position.Pips > 0 || position.NetProfit > 0) { currentVolume = InitialVolume; counterLoss = 0; Print("piplossbag win = " + PipsLossBag); } else { //increment the loss counter counterLoss++; if (counterLoss % increaseAfter == 0) { //updateVolumePositionsManual(); currentVolume *= 2; } } }
private void PositionsOnClosed(PositionClosedEventArgs args) { var position = args.Position; //Print("Position closed with {0} profit", position.GrossProfit); if (position.Label.ToString() == "ZephynScalper") { OpenTrades--; } if (position.TradeType == TradeType.Sell) { Sellingongoing = false; } if (position.TradeType == TradeType.Buy) { Buyingongoing = false; } if (OpenTrades < 0) { OpenTrades = 0; } }
private void Positions_Closed(PositionClosedEventArgs result) { if (tm != null) { tm.PositionsClosed(result); } }
protected void OnPositionClosed(PositionClosedEventArgs args) { //Send Closed Position, Positions and Pending Orders double closePrice = this.History.FindLast(args.Position.Label, Symbol, args.Position.TradeType).ClosingPrice; TestTradeManager.PublishOnPositionClosed(args.Position, closePrice, Positions, PendingOrders, Server.Time, this.IsBacktesting); }
private void Positions_Closed(PositionClosedEventArgs obj) { var sst = SimpleScalpingTrades.Where(x => x.T1Label == obj.Position.Label || x.T2Label == obj.Position.Label).FirstOrDefault(); if (sst != null) { if (sst.T1Label == obj.Position.Label && obj.Position.GrossProfit.IsPositive()) { sst.Status = SimpleScalpingTrade.State.AdvancedActive; var pos2 = SimpleScalpingPositions.Where(x => x.Label == sst.T2Label).FirstOrDefault(); if (pos2 != null) { if (pos2.TradeType == TradeType.Buy) { pos2.ModifyStopLossPrice(Symbol.ShiftPriceInPips(sst.HighestBuffer, -sst.Risk + BufferInPips)); } else { pos2.ModifyStopLossPrice(Symbol.ShiftPriceInPips(sst.LowestBuffer, sst.Risk - BufferInPips)); } } } else if (sst.T2Label == obj.Position.Label) { sst.Status = SimpleScalpingTrade.State.Finished; } } }
private void OnPositionClosed(PositionClosedEventArgs args) { var position = args.Position; Print("Closed {0:N} {1} at {2} for {3} profit", position.Volume, position.TradeType, position.EntryPrice, position.GrossProfit); _canOpenPosition = true; }
private void OnPositionsClosed(PositionClosedEventArgs args) { var position = args.Position; //IF a win position triggered with TP THEN reinitialize the volume and count the gain if (position.Pips >= TP - 20 && position.Pips <= TP + 20) { //put all counters to 0 and volume to initial currentVolume = InitialVolume; //counterLoss = 0; } else if (position.Pips >= 0) { } //IF position lost THEN increment the right counter to update thr volume if (position.Pips < -1) { counterLoss++; if (counterLoss % increaseAfter == 0) { currentVolume *= 2; } } }
//End FUNCTION On_TICK ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //// ON POSITION CLOSED /////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// private void OnPositionsClosed(PositionClosedEventArgs args) { var pos = args.Position; //if (pos.Label == label && pos.SymbolCode == Symbol.Code) //{ if (pos.TradeType == TradeType.Buy) { //if (pos.Pips <= StopLoss_1) //{ //Logic for counting Buy Positions Stop-Loss Hit //} //if (pos.Pips >= TakeProfit_1) //{ //Logic for counting Buy Positions Take-Loss Hit //} } if (pos.TradeType == TradeType.Buy) { //if (pos.Pips <= SellStopLoss) //{ //Logic for counting SELL Positions Stop-Loss Hit //} //if (pos.Pips >= SellTakeProfit) //{ //Logic for counting SELL Positions TAKE-Loss Hit //} } //} //Refresh Order count //Refresh_Order_Count(); }
private void PositionsOnClosed(PositionClosedEventArgs args) { var pos = args.Position; Print("Position closed with €{0} profit", pos.GrossProfit); is_position_open = false; }
private void OnPositionsClosed(PositionClosedEventArgs args) { // Print("newBalance = " + newBalance + " - oldBalance = " + oldBalance); var position = args.Position; //IF a win position triggered with TP THEN reinitialize the volume and count the gain if (position.Pips >= 30) { counterLoss = 0; currentVolume = InitialVolume; } //IF position lost THEN increment the right counter to update thr volume if (position.Pips < -1) { counterLoss++; if (counterLoss % increaseAfter == 0) { currentVolume *= 2; } } }
private void PositionsOnClosed(PositionClosedEventArgs args) { var pos = args.Position; string txt = "OnClosed(), {0}, P/L" + pos.NetProfit.ToString(); SendNotificationEmail(pos, txt); }
private void PositionsClosed(PositionClosedEventArgs obj) { if (!IsBacktesting) { Business.Positions.Update(Account, obj.Position, "Closed"); } }
private void OnPositionsClosed(PositionClosedEventArgs obj) { Position pos = obj.Position; if (pos.Label == _t_abovelabel) { var t_idx = pos.Comment.IndexOf("M_") + 2; if (_t_a_marklist.Remove(pos.Comment.Substring(t_idx, 13))) { Print("It's successful to remove a mark for T-A-" + Symbol.Code + "."); } } if (pos.Label == _t_belowlabel) { var t_idx = pos.Comment.IndexOf("M_") + 2; if (_t_b_marklist.Remove(pos.Comment.Substring(t_idx, 13))) { Print("It's successful to remove a mark for T-B-" + Symbol.Code + "."); } } if (pos.Label != _h_abovelabel && pos.Label != _h_belowlabel) { return; } var idx = pos.Comment.IndexOf("M_") + 2; if (_h_marklist.Remove(pos.Comment.Substring(idx, 13))) { Print("It's successful to remove a mark for " + Symbol.Code + "."); } }
private void Positions_Closed(PositionClosedEventArgs obj) { if (bs != null) { bs.PositionsClosed(obj); } }
private void PositionsOnClosed(PositionClosedEventArgs args) { var pos = args.Position; var reas = args.Reason; Print("Position closed with {0} profit. Reason : {1}", pos.GrossProfit, reas); }
/// <summary>Handle position closed</summary> private void HandlePositionClosed(object sender, PositionClosedEventArgs args) { if (args.Position.Id != Position.Id) { return; } Done = true; }
//internal void CheckForExit() //{ // if (allPositions != null && allPositions.Length > 0) // PingPongExit(); //} //CheckForExit() internal void PositionsOnClosed(PositionClosedEventArgs args) { //var position = args.Position; UpdatePositionsArray(); //in Even Gvirol TLV Aroma after WATEC 15/10/2015 dataOps.Reconcile(); }
protected override void OnPositionClosed(PositionClosedEventArgs args) { base.OnPositionClosed(args); if (RecordSession) { SaveClosedPositionToDatabase(args.Position); } }
private void PositionsOnClosed(PositionClosedEventArgs obj) { var pos = obj.Position; if (currentPosition != null && currentPosition.Id == pos.Id) { currentPosition = null; } }
//trailAllPositions(); /* if (Account.UnrealizedNetProfit >= 800) * { * Print("Account.UnrealizedNetProfit" + Account.UnrealizedNetProfit); * foreach (var p in Positions) * { * ClosePosition(p); * } * } */ private void OnPositionsClosed(PositionClosedEventArgs args) { var position = args.Position; //IF a win position triggered with TP THEN reinitialize the volume and count the profits if (position.Pips >= TP - 20 && position.Pips <= TP + 20) { //put all counters to 0 and volume to initial currentVolume = InitialVolume; balance = Account.Balance; //it is a win so reinitilize counterLoss for next cycle counterLoss = 0; } else if (position.Pips >= 0) { } //IF position lost THEN increment the right counter to update thr volume if (position.Pips < -1) { // unrealized += position.GrossProfit; //update roundLoss so we know how much is lost after each loss for each round countRoundMoney(position); //Print("roundLoss" + roundLosses); if (noActivePositions()) { //updateVolumePositions(); counterLoss++; trailed = 0; //updateVolumePositionsAuto the volume after a number "increaseAfter" of consecutive losses if (counterLoss % increaseAfter == 0) { //store the previous round losses so we can take them as a target for future critical TP if needed //and use roundLosses for next round previousRoundLosses = roundLosses; roundLosses = 0; updateVolumePositionsAuto(); } } if (currentVolume > 1000000000) { criticalPhaseMod = true; } } }
internal void PositionsClosed(PositionClosedEventArgs result) { if (result.Position.Label.StartsWith(TMLabel + TMLabelSeparator)) { if (result.Position.Label.EndsWith(GetPositionIndexNumber(-tmPositions.Count() + 1) + PositionSessionNumber)) { //EndTunnel(); //not on, due to cyclic reference } } }
private void PositionsOnClosed(PositionClosedEventArgs obj) { var pos = obj.Position; if (currentPosition != null && currentPosition.Id == pos.Id) { currentPosition = null; } //ignorableIds.Remove(pos.Id); }
private void OnClosePosition(PositionClosedEventArgs args) { var position = args.Position; var stopLoss = position.GrossProfit < 0; if (stopLoss) { totalStopLossToday += Math.Abs(position.GrossProfit); } }
private void PositionsOnClosed(PositionClosedEventArgs obj) { Position closedPosition = obj.Position; if (closedPosition.Label != cBotLabel) { return; } Print("position closed with {0} gross profit", closedPosition.GrossProfit); }
private void OnPositionsClosed(PositionClosedEventArgs args) { Print("Closed"); var position = args.Position; if (position.Label != "Martingale" || position.SymbolCode != Symbol.Code) return; if (position.GrossProfit > 0) { ExecuteOrder(InitialQuantity, GetRandomTradeType()); } else { ExecuteOrder(position.Quantity * 2, position.TradeType); } }
private void OnPositionsClosed(PositionClosedEventArgs args) { var position = args.Position; if (position.Label != "Alembex" || position.SymbolCode != Symbol.Code) return; if (position.GrossProfit > 0) { nombreDeGain += 1; Print("Gain"); if (nombreDeGain == 1) { Print("Premier Gain (Cumul de pertes depuis le dernier gain : ", pertesVolume, ")"); ExecuteOrder(pertesVolume, GetRandomTradeType()); } else { ExecuteOrder(InitialVolume, GetRandomTradeType()); } pertesVolume = InitialVolume; } else { nombreDeGain = 0; Print("Perte"); pertesVolume += position.Volume; ExecuteOrder((int)position.Volume, position.TradeType); } Print("Volume : ", position.Volume); Print("Volume pertes : ", pertesVolume); Print("---"); }
private void OnPositionsClosed(PositionClosedEventArgs args) { // If position being closed is in the Partial_Positions list, remove it from the list for (i = 0; i < Partial_Positions.Count; i++) if (Partial_Positions[i] == args.Position.Id) Partial_Positions.RemoveAt(i); }
private void PositionsOnClosed(PositionClosedEventArgs args) { var position = args.Position; switch (position.TradeType) { case TradeType.Buy: LongPositions--; Print("Closed LONG position. {0} of {1} remain open.", LongPositions, MaxLong); break; case TradeType.Sell: ShortPositions--; Print("Closed SHORT position. {0} of {1} remain open.", ShortPositions, MaxShort); break; } if (position.GrossProfit < 0) { if (WaitOnLoss > 0) Count = -WaitOnLoss; if (Martingale) { MartingaleActive++; BuyVolume = BuyVolume * 2; } } else if (MartingaleActive > 0) { MartingaleActive--; BuyVolume = (int)(BuyVolume / 2); } Print("Period {0}, Long {1} of {2}, Short {3} of {4}", t1ix, LongPositions, MaxLong, ShortPositions, MaxShort); }
private void OnPositionsClosed4(PositionClosedEventArgs args) { if (StartAutomate2 == false) { Print("Closed"); var position = args.Position; if (position.Label != "sell" || position.SymbolCode != Symbol.Code) return; if (position.Pips > 0) return; { if (position.GrossProfit < 0) { if (change2 == true) { TradeType AA = TradeType.Sell; if (position.TradeType == TradeType.Sell) AA = TradeType.Buy; ExecuteMarketOrder(AA, Symbol, Symbol.NormalizeVolume(position.Volume * Multiplier2), "sell", StopLoss2, TakeProfit2); } else if (change2 == false) { TradeType BB = TradeType.Buy; BB = TradeType.Sell; ExecuteMarketOrder(BB, Symbol, Symbol.NormalizeVolume(position.Volume * Multiplier2), "sell", StopLoss2, TakeProfit2); } } } } }
// Gere une Martingale selective. protected void OnPositionClosed(PositionClosedEventArgs args) { Position position = args.Position; bool isBuy = TradeType.Buy == position.TradeType; if (Martingale && (position.Pips < 0)) splitAndExecuteOrder(position.TradeType==TradeType.Buy ?TradeType.Sell:TradeType.Buy, position.Volume * 1.2, botPrefix + "Mart-"); Print("{0}, Volume : {1}, G/P : {2}, open : {3}, close : {4}, {5}", Symbol.Code, position.Volume, position.Pips, position.EntryPrice, isBuy ? Symbol.Bid : Symbol.Ask, position.Id); }
private void OnPositionClosed(PositionClosedEventArgs args) { }
private void PositionsOnClosed(PositionClosedEventArgs obj) { Position closedPosition = obj.Position; if (closedPosition.Label != EALabel) return; Print("position closed with {0} gross profit", closedPosition.GrossProfit); }
private void PositionsOnClosed(PositionClosedEventArgs args) { var position = args.Position; //Print("Position closed with {0} profit", position.GrossProfit); if (position.Label.ToString() == "ZephynScalper") { OpenTrades--; } if (position.TradeType == TradeType.Sell) { Sellingongoing = false; } if (position.TradeType == TradeType.Buy) { Buyingongoing = false; } if (OpenTrades < 0) OpenTrades = 0; }
/// <summary> /// /// </summary> /// <param name="args"></param> protected void OnPositionClosed(PositionClosedEventArgs args) { Position position = args.Position; // Manage a selective Martingale. if (Martingale) { OrderParams op = this.martingale(position); op.Slippage = initialOP.Slippage; this.splitAndExecuteOrder(op); } Print(position.log(this, false)); }
private void OnPositionClosed(PositionClosedEventArgs args) { Position closedPosition = args.Position; if (closedPosition.GrossProfit > 0) { ExecuteOrder(InitialVolume, closedPosition.TradeType); } else { ExecuteOrder((int)closedPosition.Volume * 2, closedPosition.TradeType); } }
protected void OnPositionClosed(PositionClosedEventArgs args) { Position position = args.Position; // Gere une Martingale selective. if (Martingale && (position.Pips < 0)) splitAndExecuteOrder(position.isBuy() ? TradeType.Sell : TradeType.Buy, position.Volume * 1.5, botPrefix + "Mart-"); Print(position.log(this,true)); }
protected void OnPositionClosed(PositionClosedEventArgs args) { Position position = args.Position; if (position.Pips < 0) manageOpen(position.inverseTradeType(), position.Volume, botLabel + "Mart-"); if (Positions.Count == 0) relanceOrders(); }