I want to create a Sell Stop order, for this I use CTrade, according to the logic (mine, it may not be correct) to place this order, we create a condition where the bid must be greater than the price. Hence Take Profit = price – take profit in points and Stop Loss = price + stop loss in points (values in points are entered because I count from the opening price of price).
As a result, I get invalid price or invalid stops. If it is not difficult, give an example specifically for SellStop().
Thank you for your attention, I understand that the question is probably too simple and obvious, but for a day I did not understand what the error is.
ivanbg
Specifies the number of points . You need to write it like this :
double stopLevel = _Point*SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL);
rosomah
SYMBOL_TRADE_STOPS_LEVEL
Minimum margin in points from the current closing price for setting Stop orders
int
int
arteinvolo
1. stop orders are placed only OUTSIDE the spread
2. a stop order for buying is always at the ASK price, for selling-BID
3. in addition, in Forex kitchens, in order not to be pipped, they came up with such a concept as Stop Level, the minimum size of a stop loss order, it SHOULD be larger than the spread, so if the opening for the purchase by ASK, then the stop loss is placed below the BID, and Vice versa
code without checking, for the exact name of the constants-in Google and documentation
string symbol = Symbol();
double ask = SymbolInfoDouble(symbol, SYMBOL_ASK);
double bid = SymbolInfoDouble(symbol, SYMBOL_BID);
double step = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
double stopLevel = SymbolInfoDouble(symbol, SYMBOL_TRADE_STOPS_LEVEL);
// Buy
double buyPrice = ask; / / buy at a price ABOVE the spread
double buyStop = bid-step; / / stop loss at the lower limit of the spread minus 1 point
double buyProfit= ask + step; / / take profit 1 point above the upper limit of the spread
buyStop = MathMin(buyStop, bid-stopLevel); / / check that the stop loss is exactly LOWER than the one allowed by the dealer
OrderSend( ... ORDER_TYPE_BUY ... )
// Sell
double sellPrice = bid; / / sell at a price BELOW the spread
double sellStop = ask + step; / / stop loss on the upper limit + 1 point
double sellProfit= bid-step; / / take profit 1 point below the spread
sellStop = MathMax(sellStop, ask + stopLevel); / / check that the stop loss is exactly HIGHER than allowed by the dealer
OrderSend( ... ORDER_TYPE_SELL ... )