protected override int Start() { if (IsNewBar()) { Print("Hei theres a new bar"); if (IsThereOpenOrder()) { CloseOpenOrder(); } if (IsPreviouslyBulishCandle()) { //order = Buy(0.1, BuyClosePrice - stopLoss, BuyClosePrice + 2 * stopLoss); //order = Buy(0.1, BuyClosePrice - (stopLoss * Point), BuyClosePrice + (4 * stopLoss * Point)); double buyStopPrice = BuyOpenPrice + 50 * Point; double buyStopClosePrice = BuyClosePrice + 50 * Point; //order = PendingBuy(0.1, buyStopPrice, buyStopClosePrice - (stopLoss * Point), buyStopClosePrice + (4 * stopLoss * Point)); order = PendingBuy(lotSize, buyStopPrice, buyStopClosePrice - (stopLoss * Point), buyStopClosePrice + (takeProfit * Point)); trailingMethod = new BuyTrailingMethod(order, this); Print("Buy"); } else { //order = Sell(0.1, SellClosePrice + stopLoss, SellClosePrice - 2 * stopLoss); //order = Sell(0.1, SellClosePrice + (stopLoss * Point), SellClosePrice - (4 * stopLoss * Point)); double sellStopPrice = SellOpenPrice - 50 * Point; double sellStopClosePrice = SellClosePrice - 50 * Point; order = PendingSell(lotSize, sellStopPrice, sellStopClosePrice + (stopLoss * Point), sellStopClosePrice - (takeProfit * Point)); //order = PendingSell(0.1, sellStopPrice, sellStopClosePrice + (stopLoss * Point), sellStopClosePrice - (4 * stopLoss * Point)); trailingMethod = new SellTrailingMethod(order, this); Print("Sell"); } } else { //if (IsThereOpenOrder()) //{ // trailingMethod.Trail(); //} if (IsThereRunningOrder()) { trailingMethod.Trail(); } Print("Wait pal"); } return (0); }
public OrderAlreadyRunning(OrderWatcher orderManager, Order order, ITrailingMethod trailing) { this.orderManager = orderManager; this.order = order; this.trailing = trailing; }
// we should use event based for this internal void OrderRunning(Order order, ITrailingMethod trailing) { ResetExpiracy(); state = new OrderAlreadyRunning(this, order, trailing); }