Example #1
0
        public BotPosition(PositionDouble position, IBot bot, Symbol symbol, TradeType tradeType, double stopLossInPips, double takeProfitInPips, double volumeInUnits)
        {
            this.bot      = bot;
            this.position = position;
            this.symbol   = symbol;
#if !cAlgo
            if (position == null)
            {
                double sl = symbol.GetStopLossFromPips(tradeType, stopLossInPips);
                double tp = symbol.GetTakeProfitFromPips(tradeType, takeProfitInPips);
                position = new PositionDouble()
                {
                    TradeType  = tradeType,
                    StopLoss   = sl,
                    TakeProfit = tp,
                    Volume     = volumeInUnits,
                };
                Debug.WriteLine($"[BOT POSITION] {this}");
            }
#endif
            this.DefaultTimeFrame = (bot as ISingleChartBot)?.TimeFrame;
            this.onBars           = new List <IOnBar>();
            this.MinStopLoss      = position.StopLoss;
            this.MinTakeProfit    = position.TakeProfit;
        }
Example #2
0
 public static bool IsTakeProfitTriggered(double?takeProfit, PositionDouble position, Symbol symbol)
 {
     if (position.TradeType == TradeType.Buy)
     {
         // REVIEW
         if (takeProfit <= symbol.Bid)
         {
             return(true);
         }
     }
     else
     {
         if (takeProfit >= symbol.Ask)
         {
             return(true);
         }
     }
     return(false);
 }
Example #3
0
 public static bool IsStopLossTriggered(double?stopLoss, PositionDouble position, Symbol symbol)
 {
     if (position.TradeType == TradeType.Buy)
     {
         // REVIEW
         if (stopLoss >= symbol.Bid)
         {
             return(true);
         }
     }
     else
     {
         if (stopLoss <= symbol.Ask)
         {
             return(true);
         }
     }
     return(false);
 }
Example #4
0
 internal _HistoricalTrade(BacktestAccount account, PositionDouble position)
 {
     this.Balance = account.Balance;
     //ClosingDealId =
     ClosingPrice = position.CurrentExitPrice;
     ClosingTime  = account.Server.Time; // REVIEW - use extrapolated time?
     Comment      = position.Comment;
     Commissions  = position.Commissions;
     EntryPrice   = position.EntryPrice;
     GrossProfit  = position.GrossProfit;
     Label        = position.Label;
     NetProfit    = position.NetProfit;
     Pips         = position.Pips;
     PositionId   = position.Id;
     Quantity     = position.Quantity;
     Swap         = position.Swap;
     SymbolCode   = position.SymbolCode;
     TradeType    = position.TradeType;
     Volume       = position.Volume;
 }
Example #5
0
 public PositionDoubleClosedEventArgs(PositionDouble position, PositionCloseReason reason)
 {
     this.Position = position;
     this.Reason   = reason;
 }