Пример #1
0
        private static void Run()
        {
            double _accountSize            = accountSize;
            double _percentageRiskPerTrade = percentageRiskPerTrade;
            double _riskToReward           = riskToReward;
            int    _numberOfTrades         = numberOfTrades;
            int    winCounter = 0;
            Random rng        = new Random();

            for (int i = 1; i <= _numberOfTrades; i++)
            {
                double      tradedAmount = Math.Round(_accountSize * _percentageRiskPerTrade, 2);
                TradeResult result       = (TradeResult)rng.Next(2);
                if (result == TradeResult.Win)
                {
                    Print(_accountSize, tradedAmount, result.ToString());
                    _accountSize = Math.Round(_accountSize, 2) + (tradedAmount * _riskToReward);
                    winCounter++;
                }
                else if (result == TradeResult.Lose)
                {
                    Print(_accountSize, tradedAmount, result.ToString());
                    _accountSize = Math.Round(_accountSize, 2) - (tradedAmount);
                }
            }
            double winPercentage = winCounter / numberOfTrades;

            Console.WriteLine(winPercentage);
        }
 private void OnExecuted(TradeResult result)
 {
     if (result.IsSuccessful)
     {
         Print("OnExecuted(): {0}, {1}", result.ToString(), result.Position.ToString());
     }
     else
     {
         Print("Failed to execute:{0}, with error: {1}", result.ToString(), result.Error);
     }
 }
 private void OnClosedAsyncCallback(TradeResult tr)
 {
     if (tr.IsSuccessful)
     {
         Print(tr.ToString());
     }
     else
     {
         Print("Error in closing occured, error: {0}", tr.Error);
     }
 }
Пример #4
0
        //PingPongExit()

        private void CloseAllPositionsThisBotAndSymbol()
        {
            //Print("hello from CloseAllPositionsThisBotAndSymbol()");
            UpdatePositionsArray();
            foreach (var pos in allPositions)
            {
                TradeResult tr = ClosePosition(pos);
                //ClosePositionAsync(pos);
                Print(tr.ToString());
            }
            UpdatePositionsArray();
            ZeroZoneVariables();
        }
Пример #5
0
        /// <summary>
        /// Runs IMarketEntryLogic for OrderPipeline
        /// </summary>
        protected void CheckForEntry()
        {
            if (Strategy.IsInitialized() == false)
            {
                return;
            }

            // sanity check. Make sure Entry Logic is defined for this pipeline
            if (MarketEntryModule == null)
            {
                Strategy.Robot.Print("Warning: No EntryLogic defined in OrderPipeline '" + this.Name + "'");
                return;
            }

            // Check market filters  time of day, volume, news, etc.
            if (!Strategy.CheckMarketFilters() || !this.CheckMarketFilters())
            {
                return;
            }

            // on a micro level, does this entry look good.
            TradeType?marketOrderDirection = MarketEntryModule.OpenOrder();

            // no entry, we exit
            if (!marketOrderDirection.HasValue)
            {
                return;
            }

            TradeType direction = marketOrderDirection.Value;

            // Check Order Filters like spacing (time & price)
            if (!Strategy.CheckOrderFilters(direction) || !this.CheckOrderFilters(direction))
            {
                return;
            }

            // Pipeline Risk assesment should execute first!
            // Before Market Order
            if (!this.BeforeSendMarketOrder(direction,
                                            Strategy.Symbol,
                                            GetVolume(direction),
                                            Strategy.GetLabel(),
                                            GetStopLoss(direction),
                                            GetTakeProfit(direction)))
            {
                return;
            }


            var vol   = GetVolume(direction);
            var label = Strategy.GetLabel();
            var sl    = GetStopLoss(direction);
            var tp    = GetTakeProfit(direction);

            // Strategy Risk assesment should go here
            // Check strategy modules
            if (!Strategy.BeforeSendMarketOrder(direction,
                                                Strategy.Symbol,
                                                vol,
                                                label,
                                                sl,
                                                tp))
            {
                return;
            }

            // Execute trade
            TradeResult result = Strategy.Robot.ExecuteMarketOrder(
                direction,
                Strategy.Symbol,
                vol,
                label,
                sl,
                tp,
                0.5,      // slippage
                this.Name // OrderPipeline name
                );

            if (result.Error.HasValue)
            {
                Strategy.Robot.Print("Market Order Failed: " + result.Error.Value + ", " + result.ToString());
            }
        }
Пример #6
0
        private void closePositionRequest(ClosePositionRequest request)
        {
            try
            {
                Position position = Positions.Find(request.label);
                if (position == null)
                {
                    sendMessageToTelegram(new PositionResponse(request.messageId, "Position not found with label:\n" + request.label, false));
                }
                else
                {
                    TradeResult result = ClosePosition(position);
                    if (result.IsSuccessful)
                    {
                        sendMessageToTelegram(new PositionResponse(request.messageId, "Result:\n" + result.ToString() + "\n\nPosition:\n" + result.Position.ToString() + "\n\nNet Profit: " + result.Position.NetProfit + "\n\nProfit in Pips: " + result.Position.Pips, true));
                    }
                    else
                    {
                        sendMessageToTelegram(new PositionResponse(request.messageId, result.ToString(), false));
                    }
                }
            } catch (Exception e)
            {
                Print("Exception: {0}", e.Message);

                sendMessageToTelegram(new PositionResponse(request.messageId, "Exception on closing position.\nMessage: " + e.Message, false));
            }
        }