Place Stop order

Place Stop order

Dear All,

Attached herewith the extract of Code I got from this forum (Smart Grid V3). I am trying to update this code based on my requirement, however I stuck with the following point. The following code place the order once the price move at Pip step. My request is how to place the pending order in the opposite direction in addition to the market order.

private void ProcessBuy()
        {
            if (Positions.Count(x => x.TradeType == TradeType.Buy && x.SymbolName == SymbolName && x.Label == ThiscBotLabel) == 0 && MarketSeries.Close.Last(1) > MarketSeries.Close.Last(2))
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, FirstVolume, ThiscBotLabel, StopLossPips, null);
                LastBuyTradeTime = MarketSeries.OpenTime.Last(0);
            }
            if (Positions.Count(x => x.TradeType == TradeType.Buy && x.SymbolName == SymbolName && x.Label == ThiscBotLabel) > 0)
            {
                if (Symbol.Ask < (Positions.Where(x => x.TradeType == TradeType.Buy && x.SymbolName == SymbolName && x.Label == ThiscBotLabel).Min(x => x.EntryPrice) - PipStep * Symbol.PipSize) && LastBuyTradeTime != MarketSeries.OpenTime.Last(0))
                {
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, CalculateVolume(TradeType.Buy), ThiscBotLabel, StopLossPips, null);
                    LastBuyTradeTime = MarketSeries.OpenTime.Last(0);
                }
            }
        }

private void ProcessSell()
        {
            if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == ThiscBotLabel) == 0 && MarketSeries.Close.Last(2) > MarketSeries.Close.Last(1))
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, FirstVolume, ThiscBotLabel, StopLossPips, null);
                LastSellTradeTime = MarketSeries.OpenTime.Last(0);
            }
            if (Positions.Count(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == ThiscBotLabel) > 0)
            {
                if (Symbol.Bid > (Positions.Where(x => x.TradeType == TradeType.Sell && x.SymbolName == SymbolName && x.Label == ThiscBotLabel).Max(x => x.EntryPrice) + PipStep * Symbol.PipSize) && LastSellTradeTime != MarketSeries.OpenTime.Last(0))
                {
                    ExecuteMarketOrder(TradeType.Sell, SymbolName, CalculateVolume(TradeType.Sell), ThiscBotLabel, StopLossPips, null);
                    LastSellTradeTime = MarketSeries.OpenTime.Last(0);
                }
            }
        }

Thanks in Advance

R. Vadivelan

Hi Vadivelan,

Check here how to place stop orders in a cBot.

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader