Place Stop order
Place Stop order
30 Jun 2020, 09:39
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
Replies
velu130486
30 Jun 2020, 12:48
RE:
Hi Panagiotis,
I would like to place stop order. Currently the Bot place the Market order in the same direction once the price change by pip step say 10 pips. What I need at the same time place Stop order in the opposite direction with the distance of pip step from the current price.
For Ex Initially Bot place Buy order at X pips, once it is moved pip step X+10 then it place another buy order, Now I need to place sell stop order at X pips to form as a grid.
Thanks in Advance
R. Vadivelan
PanagiotisCharalampous said:
Hi Vadivelan,
What kind of order (market, stop, limit) and at which price do you want to place it?
Best Regards,
Panagiotis
PanagiotisCharalampous
30 Jun 2020, 14:14
Hi Vadivelan,
Check here how to place stop orders in a cBot.
Best Regards,
Panagiotis
@PanagiotisCharalampous
velu130486
13 Jul 2020, 14:28
RE:
Hi Panagiotis,
Now I am able to create the stop order when the position is created. However could you please help how to avoid creating the new stop order when there is already a pending order in the distance of X pips. (i.e.) If there is already a pending order at a distance of 10 pips, I want to avoid create another stop order at the same distance +- 3 pips.
I tried to cancel the pending order, but it close all pending order for the symbol.
Or is there any possibility to cancel the pending order and create the multiple pending orders like entry price + 10 pips, +20 pips, +30 pips etc in 1 line or I need to create 1 by 1 in code
Thanks and Regards
R. Vadivelan
PanagiotisCharalampous said:
Hi Vadivelan,
Check here how to place stop orders in a cBot.
Best Regards,
Panagiotis
PanagiotisCharalampous
13 Jul 2020, 14:42
Hi Vadivelan,
The condition below checks if there is a pending order in a distance less than 10 pips from the bid price before executing the code
if (PendingOrders.Min(x => Math.Abs(x.TargetPrice - Symbol.Bid) / Symbol.PipSize) > 10)
{
// do something
}
You can use it as a starting point in implementing your logic.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
30 Jun 2020, 09:48
Hi Vadivelan,
What kind of order (market, stop, limit) and at which price do you want to place it?
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous