public void Should_contain_risk_one_percent_smaller() { var moneyManagement = new MoneyManagement(1, 2000); double lot = moneyManagement.CalculateLotSize(new MagicBoxOrder { StopLoss = 200 }); Assert.AreEqual(0.1, lot); }
public void Should_contain_risk_one_percent() { var moneyManagement = new MoneyManagement(1, 10000); double lot = moneyManagement.CalculateLotSize(400); Assert.AreEqual(0.25, lot); }
public void Should_contain_risk_one_percent_smaller() { var moneyManagement = new MoneyManagement(1, 2000); double lot = moneyManagement.CalculateLotSize(new MagicBoxOrder { StopLoss = 200 }); Assert.AreEqual(0.1, lot); }
internal Order CreatePendingSellOrder() { double slPoints = (High[1] - Low[1]) / Point + 2 * Range; double tpPoints = 2 * slPoints * Point; var moneyManagement = new MoneyManagement(2, Balance); double lotSize = moneyManagement.CalculateLotSize(slPoints); Order order = PendingSell(Symbol, lotSize, Low[1] - Range * Point, High[1] + Range * Point, Low[1] - tpPoints); this.ObjectsDeleteAll(); return(order); }
internal void CreatedMagicBoxFromPreviousCandle() { double asianSessionHigh = AsianSessionHigh; double asianSessionLow = AsianSessionLow; double slPoints = (asianSessionHigh - asianSessionLow) / Point + 2 * range; var moneyManagement = new MoneyManagement(2, Balance); double lotSize = moneyManagement.CalculateLotSize(slPoints); double tpPoints = Math.Max(1000 * Point, 2 * slPoints * Point); //var tpPoints = 200 * Point; // risk reward ratio = 2 * slPoints _buyOrder = PendingBuy(Symbol, lotSize, asianSessionHigh + range * Point, asianSessionLow - range * Point, asianSessionHigh + tpPoints); _sellOrder = PendingSell(Symbol, lotSize, asianSessionLow - range * Point, asianSessionHigh + range * Point, asianSessionLow - tpPoints); this.ObjectsDeleteAll(); }
private void CreateOrderBox(MagicBoxOrder magicBox) { /// need to refactor this messs into another class double range = magicBox.Range; double takeProfit = magicBox.TakeProfit; // nullify take profit double stopLoss = magicBox.StopLoss; // nullify stop loss, should set after enter the trade. double expiredTime = magicBox.MinuteExpiracy; var moneyManagement = new MoneyManagement(1, Balance); double lotSize = moneyManagement.CalculateLotSize(magicBox.StopLoss); foreach (string currencyPairs in currencyRepository.GetRelatedCurrencyPairs(this, magicBox.Symbol)) { // check if the order has been created for this pair if (orderPool.ContainsOrderForSymbol(currencyPairs)) continue; // refactor to next class and cache the traded value ...(don't let it duplicated like tonight usdcad pairs) // the logic should be in orderPool Order buyOrder = PendingBuy(currencyPairs, lotSize, BuyOpenPriceFor(currencyPairs) + range*PointFor(currencyPairs)); buyOrder.ChangeStopLossInPoints(magicBox.StopLoss); buyOrder.ChangeTakeProfitInPoints(magicBox.TakeProfit); Order sellOrder = PendingSell(currencyPairs, lotSize, SellOpenPriceFor(currencyPairs) - range*PointFor(currencyPairs)); sellOrder.ChangeStopLossInPoints(magicBox.StopLoss); sellOrder.ChangeTakeProfitInPoints(magicBox.TakeProfit); //var buyOrder = PendingBuy(magicBox.Symbol, lotSize, // BuyOpenPriceFor(magicBox.Symbol) + range * PointFor(magicBox.Symbol), // BuyClosePriceFor(magicBox.Symbol) + ((range - stopLoss) * PointFor(magicBox.Symbol)), // BuyClosePriceFor(magicBox.Symbol) + ((range + takeProfit) * PointFor(magicBox.Symbol))); //var sellOrder = PendingSell(magicBox.Symbol, lotSize, // SellOpenPriceFor(magicBox.Symbol) - range * PointFor(magicBox.Symbol), // SellClosePriceFor(magicBox.Symbol) - ((range - stopLoss) * PointFor(magicBox.Symbol)), // SellClosePriceFor(magicBox.Symbol) - ((range + takeProfit) * PointFor(magicBox.Symbol))); orderPool.Add(new OrderWatcher(buyOrder, sellOrder, expiredTime, magicBox.Config)); } }