private void CreateOrderBox(MagicBoxOrder magicBox) { /// need to refactor this messs into another class double range = magicBox.Range; double takeProfit = 0; // nullify take profit double stopLoss = 0; // nullify stop loss, should set after enter the trade. double expiredTime = magicBox.MinuteExpiracy; var moneyManagement = new MoneyManagement(1, this.Balance); double lotSize = moneyManagement.CalculateLotSize(magicBox); foreach (var currencyPairs in currencyRepository.GetRelatedCurrencyPairs(this, magicBox.Symbol)) { // check if the order has been created for this pair var buyOrder = PendingBuy(currencyPairs, lotSize, BuyOpenPriceFor(currencyPairs) + range * PointFor(currencyPairs)); var sellOrder = PendingSell(currencyPairs, lotSize, SellOpenPriceFor(currencyPairs) - range * PointFor(currencyPairs)); orderPool.Add(new OrderWatcher(buyOrder, sellOrder, expiredTime, magicBox.Config)); } }
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)); } }
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)); } }
public void Schedule(MagicBoxOrder magicBox) { var nexttime = magicBox.ExecutingTime; var jobDetail = JobBuilder.Create <MagicBoxOrderJob>() .WithIdentity(magicBox.Id, "group1") .Build(); var trigger = TriggerBuilder.Create() .WithIdentity(magicBox.Id, "group1") .StartAt(DateBuilder.TodayAt(nexttime.Hour, nexttime.Minute, nexttime.Second)) .Build(); // should group this together in one command. just execute when arrived there jobDetail.JobDataMap.Add("queue", orderQueue); jobDetail.JobDataMap.Add("orders", magicBox); scheduler.ScheduleJob(jobDetail, trigger); }
public void Schedule(MagicBoxOrder magicBox) { DateTime nexttime = magicBox.ExecutingTime; IJobDetail jobDetail = JobBuilder.Create<MagicBoxOrderJob>() .WithIdentity(magicBox.Id, "group1") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity(magicBox.Id, "group1") .StartAt(DateBuilder.TodayAt(nexttime.Hour, nexttime.Minute, nexttime.Second)) .Build(); // should group this together in one command. just execute when arrived there jobDetail.JobDataMap.Add("queue", orderQueue); jobDetail.JobDataMap.Add("orders", magicBox); scheduler.ScheduleJob(jobDetail, trigger); }
protected override int Start() { MakeSureAlreadyInitialized(); while (reminder.IsAvailable) { MagicBoxOrder result = null; reminder.OrderQueue.TryDequeue(out result); if (result == null) { continue; } CreateOrderBox(result); } orderPool.ManageAllOrder(); // 2. trailing stop and Lock Profit return(0); }
public double CalculateLotSize(MagicBoxOrder magicBoxOrder) { return Math.Round(RiskValue / (ValuePerPips * Pips(magicBoxOrder.StopLoss)), 2); }
} // should check to pips calculator public double CalculateLotSize(MagicBoxOrder magicBoxOrder) { return(Math.Round(RiskValue / (ValuePerPips * Pips(magicBoxOrder.StopLoss)), 2)); }