XU DragTakeProfit
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «xu dragtakeprofit.mq5» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
XU DragTakeProfit — это скрипт для MetaTrader 5, предназначенный для оперативной установки уровня Take Profit на всех открытых позициях текущего инструмента. Пользователь запускает скрипт, перетаскивая его на график в нужную цену, и скрипт автоматически обновляет TP для каждой позиции.
Скрипт проверяет корректность нового уровня TP в зависимости от типа позиции: для BUY-позиций TP должен быть выше текущей цены, для SELL — ниже. При этом уровень Stop Loss остаётся без изменений. Результаты каждой операции выводятся в журнал торговых сообщений.
В случае ошибки отправки торгового запроса скрипт выводит код и описание ошибки. Если на текущем символе нет открытых позиций или перетащенная цена некорректна, соответствующие уведомления также отображаются в логе.
Поиск по коду файла
#property description " Barry the Baptist, Xard's AI Enforcer"
#property version "1.00"
#property description " "
#property description " What stands in the way becomes the way--This is the way (Asante/Aurelius)"
#property description " "
#property description " Welcome to the XARD UNIVERSE"
#property description " Let the light shine and illuminate your trading world"
#property description " "
#property strict
void OnStart()
{
// код доступен только после оплаты
}
double new_tp = ChartPriceOnDropped();
if(new_tp == 0.0)
{
Print("Invalid drop price or script not dropped on chart.");
return;
}
new_tp = NormalizeDouble(new_tp, _Digits);
int total = PositionsTotal();
int modified = 0;
for(int i = total - 1; i >= 0; i--)
{
if(PositionGetSymbol(i) == _Symbol)
{
ulong ticket = PositionGetTicket(i);
if(ticket != 0) // Valid ticket
{
double current_sl = PositionGetDouble(POSITION_SL);
double current_tp = PositionGetDouble(POSITION_TP);
long position_type = PositionGetInteger(POSITION_TYPE);
if(position_type == POSITION_TYPE_BUY)
{
double current_price = PositionGetDouble(POSITION_PRICE_CURRENT);
if(new_tp <= current_price)
{
PrintFormat("Invalid TP for BUY position %I64u: TP (%.5f) must be above current price (%.5f)",
ticket, new_tp, current_price);
continue;
}
}
else if(position_type == POSITION_TYPE_SELL)
{
double current_price = PositionGetDouble(POSITION_PRICE_CURRENT);
if(new_tp >= current_price)
{
PrintFormat("Invalid TP for SELL position %I64u: TP (%.5f) must be below current price (%.5f)",
ticket, new_tp, current_price);
continue;
}
}
MqlTradeRequest request = {};
MqlTradeResult result = {};
request.action = TRADE_ACTION_SLTP;
request.position = ticket;
request.symbol = _Symbol;
request.sl = NormalizeDouble(current_sl, _Digits); // Keep current SL
request.tp = new_tp; // Set new TP
if(!Показано первые 50% кода (символов: 3416)