Control Panel Part 2
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «control panel part 2.mq5» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
Программа представляет собой графический торговый советник для MetaTrader 5, который размещает на графике интерактивную панель управления. Панель разделена на три раздела — Trade, Close и Information — с возможностью переключения между ними через кнопки в заголовке.
В разделе Trade пользователь может задать параметры сделки (лот, цена, стоп-лосс, тейк-профит) и выполнить ордера Buy/Sell, а также выставить отложенные ордера Buy/Sell Stop и Buy/Sell Limit. Перед отправкой ордера происходит проверка уровня стопа на допустимость.
В разделе Close предоставляются кнопки для закрытия позиций: все позиции, только Buy/Sell, убыточные/прибыльные, а также удаление отложенных ордеров. В разделе Information отображаются данные аккаунта: номер, сервер, тип, кредитное плечо, баланс, эквити и серверное время.
Советник использует библиотеку CTrade для отправки ордеров и обработку событий чарта через OnChartEvent. Обновление данных аккаунта происходит в OnTick.
Поиск по коду файла
#property version "1.00" //--- Version of the script
#include <Trade/Trade.mqh> //--- Include trade library
CTrade obj_Trade; //--- Create an instance of the CTrade class
#include <Controls/Button.mqh> //--- Include button control library
CButton obj_Btn_MAIN; //--- Main button object
CButton obj_Btn_HEADER; //--- Header button object
CButton obj_Btn_X; //--- Close button (X) object
CButton obj_Btn_TRADE; //--- Trade button object
CButton obj_Btn_CLOSE; //--- Close button object
CButton obj_Btn_INFO; //--- Information button object
CButton obj_Btn_RISK; //--- Risk button object
CButton obj_Btn_POINTS; //--- Points button object
CButton obj_Btn_SELL; //--- Sell button object
CButton obj_Btn_ENTRY; //--- Entry button object
CButton obj_Btn_BUY; //--- Buy button object
CButton obj_Btn_SELLSTOP; //--- Sell Stop button object
CButton obj_Btn_BUYSTOP; //--- Buy Stop button object
CButton obj_Btn_SELLLIMIT; //--- Sell Limit button object
CButton obj_Btn_BUYLIMIT; //--- Buy Limit button object
CButton obj_Btn_FOOTER; //--- Footer button object
CButton obj_Btn_CLOSE_ALL; //--- Close All button object
CButton obj_Btn_CLOSE_ALL_SELL; //--- Close All Sell button object
CButton obj_Btn_CLOSE_ALL_BUY; //--- Close All Buy button object
CButton obj_Btn_CLOSE_LOSS_SELL; //--- Close Loss Sell button object
CButton obj_Btn_CLOSE_LOSS_BUY; //--- Close Loss Buy button object
CButton obj_Btn_CLOSE_PROFIT_SELL; //--- Close Profit Sell button object
CButton obj_Btn_CLOSE_PROFIT_BUY; //--- Close Profit Buy button object
CButton obj_Btn_CLOSE_ALL_LOSS; //--- Close All Loss button object
CButton obj_Btn_CLOSE_ALL_PROFIT; //--- Close All Profit button object
CButton obj_Btn_CLOSE_PENDING; //--- Close Pending button object
CButton obj_Btn_ACC_NUMBER; //--- Account Number button object
CButton obj_Btn_ACC_NAME; //--- Account Name button object
CButton obj_Btn_ACC_TYPE; //--- Account Type button object
CButton obj_Btn_ACC_LEVERAGE; //--- Account Leverage button object
CButton obj_Btn_ACC_EQUITY; //--- Account Equity button object
CButton obj_Btn_ACC_BALANCE; //--- Account Balance button object
CButton obj_Btn_TIME; //--- Time button object
#include <Controls/Edit.mqh> //--- Include edit control library
CEdit obj_Edit_RISK; //--- Risk edit field object
CEdit obj_Edit_PRICE; //--- Price edit field object
CEdit obj_Edit_LOTS; //--- Lots edit field object
CEdit obj_Edit_SL; //--- Stop Loss edit field object
CEdit obj_Edit_TP; //--- Take Profit edit field object
#include <Controls/Label.mqh> //--- Include label control library
CLabel obj_Lbl_HEADER; //--- Header label object
CLabel obj_Lbl_PRICE; //--- Price label object
CLabel obj_Lbl_LOTS; //--- Lots label object
CLabel obj_Lbl_SL; //--- Stop Loss label object
CLabel obj_Lbl_TP; //--- Take Profit label object
CLabel obj_Lbl_ACC_NUMBER; //--- Account Number label object
CLabel obj_Lbl_ACC_NAME; //--- Account Name label object
CLabel obj_Lbl_ACC_TYPE; //--- Account Type label object
CLabel obj_Lbl_ACC_LEVERAGE; //--- Account Leverage label object
CLabel obj_Lbl_ACC_EQUITY; //--- Account Equity label object
CLabel obj_Lbl_ACC_BALANCE; //--- Account Balance label object
CLabel obj_Lbl_TIME; //--- Time label object
#define Btn_MAIN "Btn_MAIN" //--- Button name for the main button
#define Btn_HEADER "Btn_HEADER" //--- Button name for the header button
#define Btn_X "Btn_X" //--- Button name for the close button
#define Btn_TRADE "Btn_TRADE" //--- Button name for the trade button
#define Btn_CLOSE "Btn_CLOSE" //--- Button name for the close button
#define Btn_INFO "Btn_INFO" //--- Button name for the info button
#define Btn_RISK "Btn_RISK" //--- Button name for the risk button
#define Btn_POINTS "Btn_POINTS" //--- Button name for the points button
#define Btn_SELL "Btn_SELL" //--- Button name for the sell button
#define Btn_ENTRY "Btn_ENTRY" //--- Button name for the entry button
#define Btn_BUY "Btn_BUY" //--- Button name for the buy button
#define Btn_SELLSTOP "Btn_SELLSTOP" //--- Button name for the sell stop button
#define Btn_BUYSTOP "Btn_BUYSTOP" //--- Button name for the buy stop button
#define Btn_SELLLIMIT "Btn_SELLLIMIT" //--- Button name for the sell limit button
#define Btn_BUYLIMIT "Btn_BUYLIMIT" //--- Button name for the buy limit button
#define Btn_FOOTER "Btn_FOOTER" //--- Button name for the footer button
#define Btn_CLOSE_ALL "Btn_CLOSE_ALL" //--- Button name for closing all trades
#define Btn_CLOSE_ALL_SELL "Btn_CLOSE_ALL_SELL" //--- Button name for closing all sell trades
#define Btn_CLOSE_ALL_BUY "Btn_CLOSE_ALL_BUY" //--- Button name for closing all buy trades
#define Btn_CLOSE_LOSS_SELL "Btn_CLOSE_LOSS_SELL" //--- Button name for closing all loss sell trades
#define Btn_CLOSE_LOSS_BUY "Btn_CLOSE_LOSS_BUY" //--- Button name for closing all loss buy trades
#define Btn_CLOSE_PROFIT_SELL "Btn_CLOSE_PROFIT_SELL" //--- Button name for closing all profit sell trades
#define Btn_CLOSE_PROFIT_BUY "Btn_CLOSE_PROFIT_BUY" //--- Button name for closing all profit buy trades
#define Btn_CLOSE_ALL_LOSS "Btn_CLOSE_ALL_LOSS" //--- Button name for closing all loss trades
#define Btn_CLOSE_ALL_PROFIT "Btn_CLOSE_ALL_PROFIT" //--- Button name for closing all profit trades
#define Btn_CLOSE_PENDING "Btn_CLOSE_PENDING" //--- Button name for closing all pending trades
#define Btn_ACC_NUMBER "Btn_ACC_NUMBER" //--- Button name for the account number
#define Btn_ACC_NAME "Btn_ACC_NAME" //--- Button name for the account name
#define Btn_ACC_TYPE "Btn_ACC_TYPE" //--- Button name for the account type
#define Btn_ACC_LEVERAGE "Btn_ACC_LEVERAGE" //--- Button name for the account leverage
#define Btn_ACC_EQUITY "Btn_ACC_EQUITY" //--- Button name for the account equity
#define Btn_ACC_BALANCE "Btn_ACC_BALANCE" //--- Button name for the account balance
#define Btn_TIME "Btn_TIME" //--- Button name for the time
#define Edit_RISK "Edit_RISK" //--- Edit field name for risk input
#define Edit_PRICE "Edit_PRICE" //--- Edit field name for price input
#define Edit_LOTS "Edit_LOTS" //--- Edit field name for lots input
#define Edit_SL "Edit_SL" //--- Edit field name for stop loss input
#define Edit_TP "Edit_TP" //--- Edit field name for take profit input
#define Lbl_HEADER "Lbl_HEADER" //--- Label name for the header
#define Lbl_PRICE "Lbl_PRICE" //--- Label name for the price
#define Lbl_LOTS "Lbl_LOTS" //--- Label name for the lots
#define Lbl_SL "Lbl_SL" //--- Label name for the stop loss
#define Lbl_TP "Lbl_TP" //--- Label name for the take profit
#define Lbl_ACC_NUMBER "Lbl_ACC_NUMBER" //--- Label name for the account number
#define Lbl_ACC_NAME "Lbl_ACC_NAME" //--- Label name for the account name
#define Lbl_ACC_TYPE "Lbl_ACC_TYPE" //--- Label name for the account type
#define Lbl_ACC_LEVERAGE "Lbl_ACC_LEVERAGE" //--- Label name for the account leverage
#define Lbl_ACC_EQUITY "Lbl_ACC_EQUITY" //--- Label name for the account equity
#define Lbl_ACC_BALANCE "Lbl_ACC_BALANCE" //--- Label name for the account balance
#define Lbl_TIME "Lbl_TIME" //--- Label name for the time
int OnInit() {
// код доступен только после оплаты
}
void OnDeinit(const int reason) {
destroySection_Main_Panel(); //--- Call function to destroy the main panel section
destroySection_Trade(); //--- Call function to destroy the trade section
destroySection_Close(); //--- Call function to destroy the close section
destroySection_Information(); //--- Call function to destroy the information section
ChartRedraw(0);
}
void OnTick() {
// код доступен только после оплаты
}
void OnChartEvent(
const int id, // Event ID indicating the type of event (e.g., mouse click, timer, etc.)
const long& lparam, // Long type parameter associated with the event, usually containing data like mouse coordinates or object IDs
const double& dparam, // Double type parameter associated with the event, used for floating-point values related to the event
const string& sparam // String type parameter associated with the event, typically the name of the object that triggered the event
){
if (id == CHARTEVENT_OBJECT_CLICK){
if (sparam==obj_Btn_TRADE.Name()){
Print("OBJECT CLICKED = ", obj_Btn_TRADE.Name());
obj_Btn_TRADE.Pressed(false);
obj_Btn_CLOSE.Pressed(false);
obj_Btn_INFO.Pressed(false);
obj_Btn_TRADE.ColorBackground(clrYellow);
obj_Btn_CLOSE.ColorBackground(clrSilver);
obj_Btn_INFO.ColorBackground(clrSilver);
obj_Btn_TRADE.ColorBorder(clrYellow);
obj_Btn_CLOSE.ColorBorder(clrSilver);
obj_Btn_INFO.ColorBorder(clrSilver);
destroySection_Close();
destroySection_Information();
createSection_Trade();
}
else if (sparam==obj_Btn_CLOSE.Name()){
Print("OBJECT CLICKED = ", obj_Btn_CLOSE.Name());
obj_Btn_TRADE.Pressed(false);
obj_Btn_CLOSE.Pressed(false);
obj_Btn_INFO.Pressed(false);
obj_Btn_TRADE.ColorBackground(clrSilver);
obj_Btn_CLOSE.ColorBackground(clrYellow);
obj_Btn_INFO.ColorBackground(clrSilver);
obj_Btn_TRADE.ColorBorder(clrSilver);
obj_Btn_CLOSE.ColorBorder(clrYellow);
obj_Btn_INFO.ColorBorder(clrSilver);
destroySection_Trade();
destroySection_Information();
createSection_Close();
}
else if (sparam==obj_Btn_INFO.Name()){
Print("OBJECT CLICKED = ", obj_Btn_INFO.Name());
obj_Btn_TRADE.Pressed(false);
obj_Btn_CLOSE.Pressed(false);
obj_Btn_INFO.Pressed(false);
obj_Btn_TRADE.ColorBackground(clrSilver);
obj_Btn_CLOSE.ColorBackground(clrSilver);
obj_Btn_INFO.ColorBackground(clrYellow);
obj_Btn_TRADE.ColorBorder(clrSilver);
obj_Btn_CLOSE.ColorBorder(clrSilver);
obj_Btn_INFO.ColorBorder(clrYellow);
destroySection_Trade();
destroySection_Close();
createSection_Information();
}
else if (sparam==obj_Btn_X.Name()){
Print("OBJECT CLICKED = ", obj_Btn_X.Name());
destroySection_Trade();
destroySection_Close();
destroySection_Information();
destroySection_Main_Panel();
}
else if (sparam==obj_Btn_SELL.Name()){ //--- Check if the Sell button is clicked
Print("OBJECT CLICKED = ",obj_Btn_SELL.Name()); //--- Log the button click event
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); //--- Get and normalize the ask price
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //--- Get and normalize the bid price
double lots = StringToDouble(obj_Edit_LOTS.Text()); //--- Get the lot size from input field
double entry_price = Bid; //--- Set the entry price for selling to the current bid price
double stopLoss = Ask+StringToDouble(obj_Edit_SL.Text())*_Point; //--- Calculate stop loss based on user input
double takeprofit = Ask-StringToDouble(obj_Edit_TP.Text())*_Point; //--- Calculate take profit based on user input
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit); //--- Log order details
obj_Trade.Sell(lots,_Symbol,entry_price,stopLoss,takeprofit); //--- Execute the sell order
}
else if (sparam==obj_Btn_BUY.Name()){ //--- Check if the Buy button is clicked
Print("OBJECT CLICKED = ",obj_Btn_BUY.Name()); //--- Log the button click event
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); //--- Get and normalize the ask price
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //--- Get and normalize the bid price
double lots = StringToDouble(obj_Edit_LOTS.Text()); //--- Get the lot size from input field
double entry_price = Ask; //--- Set the entry price for buying to the current ask price
double stopLoss = Bid-StringToDouble(obj_Edit_SL.Text())*_Point; //--- Calculate stop loss based on user input
double takeprofit = Bid+StringToDouble(obj_Edit_TP.Text())*_Point; //--- Calculate take profit based on user input
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit); //--- Log order details
obj_Trade.Buy(lots,_Symbol,entry_price,stopLoss,takeprofit); //--- Execute the buy order
}
else if (sparam==obj_Btn_SELLSTOP.Name()){ //--- Check if the Sell Stop button is clicked
Print("OBJECT CLICKED = ",obj_Btn_SELLSTOP.Name()); //--- Log the button click event
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); //--- Get and normalize the ask price
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //--- Get and normalize the bid price
double user_price = StringToDouble(obj_Edit_PRICE.Text()); //--- Get the user-defined price from input field
long stopslevel = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL); //--- Get the minimum stop level for the symbol
double valid_price = Bid - stopslevel*_Point; //--- Calculate the valid price for placing a sell stop order
if (user_price > valid_price){ //--- Check if the user-defined price is valid
Print("ERROR: INVALID STOPS PRICE. ",user_price," > ",valid_price); //--- Log an error message
}
else if (user_price <= valid_price){ //--- If the user-defined price is valid
double lots = StringToDouble(obj_Edit_LOTS.Text()); //--- Get the lot size from input field
double entry_price = user_price; //--- Set the entry price for the sell stop order
double stopLoss = user_price+StringToDouble(obj_Edit_SL.Text())*_Point; //--- Calculate stop loss based on user input
double takeprofit = user_price-StringToDouble(obj_Edit_TP.Text())*_Point; //--- Calculate take profit based on user input
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit); //--- Log order details
obj_Trade.SellStop(lots,entry_price,_Symbol,stopLoss,takeprofit); //--- Execute the sell stop order
}
}
else if (sparam==obj_Btn_BUYSTOP.Name()){ //--- Check if the Buy Stop button is clicked
Print("OBJECT CLICKED = ",obj_Btn_BUYSTOP.Name()); //--- Log the button click event
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); //--- Get and normalize the ask price
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //--- Get and normalize the bid price
double user_price = StringToDouble(obj_Edit_PRICE.Text()); //--- Get the user-defined price from input field
long stopslevel = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL); //--- Get the minimum stop level for the symbol
double valid_price = Ask + stopslevel*_Point; //--- Calculate the valid price for placing a buy stop order
if (user_price < valid_price){ //--- Check if the user-defined price is valid
Print("ERROR: INVALID STOPS PRICE. ",user_price," < ",valid_price); //--- Log an error message
}
else if (user_price >= valid_price){ //--- If the user-defined price is valid
double lots = StringToDouble(obj_Edit_LOTS.Text()); //--- Get the lot size from input field
double entry_price = user_price; //--- Set the entry price for the buy stop order
double stopLoss = user_price-StringToDouble(obj_Edit_SL.Text())*_Point; //--- Calculate stop loss based on user input
double takeprofit = user_price+StringToDouble(obj_Edit_TP.Text())*_Point; //--- Calculate take profit based on user input
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit); //--- Log order details
obj_Trade.BuyStop(lots,entry_price,_Symbol,stopLoss,takeprofit); //--- Execute the buy stop order
}
}
else if (sparam==obj_Btn_SELLLIMIT.Name()){ //--- Check if the Sell Limit button is clicked
Print("OBJECT CLICKED = ",obj_Btn_SELLLIMIT.Name()); //--- Log the button click event
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); //--- Get and normalize the ask price
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //--- Get and normalize the bid price
double user_price = StringToDouble(obj_Edit_PRICE.Text()); //--- Get the user-defined price from input field
long stopslevel = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL); //--- Get the minimum stop level for the symbol
double valid_price = Bid + stopslevel*_Point; //--- Calculate the valid price for placing a sell limit order
if (user_price < valid_price){ //--- Check if the user-defined price is valid
Print("ERROR: INVALID STOPS PRICE. ",user_price," < ",valid_price); //--- Log an error message
}
else if (user_price >= valid_price){ //--- If the user-defined price is valid
double lots = StringToDouble(obj_Edit_LOTS.Text()); //--- Get the lot size from input field
double entry_price = user_price; //--- Set the entry price for the sell limit order
double stopLoss = user_price+StringToDouble(obj_Edit_SL.Text())*_Point; //--- Calculate stop loss based on user input
double takeprofit = user_price-StringToDouble(obj_Edit_TP.Text())*_Point; //--- Calculate take profit based on user input
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit); //--- Log order details
obj_Trade.SellLimit(lots,entry_price,_Symbol,stopLoss,takeprofit); //--- Execute the sell limit order
}
}
else if (sparam==obj_Btn_BUYLIMIT.Name()){ //--- Check if the Buy Limit button is clicked
Print("OBJECT CLICKED = ",obj_Btn_BUYLIMIT.Name()); //--- Log the button click event
double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); //--- Get and normalize the ask price
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); //--- Get and normalize the bid price
double user_price = StringToDouble(obj_Edit_PRICE.Text()); //--- Get the user-defined price from input field
long stopslevel = SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL); //--- Get the minimum stop level for the symbol
double valid_price = Ask - stopslevel*_Point; //--- Calculate the valid price for placing a buy limit order
if (user_price > valid_price){ //--- Check if the user-defined price is valid
Print("ERROR: INVALID STOPS PRICE. ",user_price," > ",valid_price); //--- Log an error message
}
else if (user_price <= valid_price){ //--- If the user-defined price is valid
double lots = StringToDouble(obj_Edit_LOTS.Text()); //--- Get the lot size from input field
double entry_price = user_price; //--- Set the entry price for the buy limit order
double stopLoss = user_price-StringToDouble(obj_Edit_SL.Text())*_Point; //--- Calculate stop loss based on user input
double takeprofit = user_price+StringToDouble(obj_Edit_TP.Text())*_Point; //--- Calculate take profit based on user input
Print("Lots = ",lots,", Entry = ",entry_price,", SL = ",stopLoss,", TP = ",takeprofit); //--- Log order details
obj_Trade.BuyLimit(lots,entry_price,_Symbol,stopLoss,takeprofit); //--- Execute the buy limit order
}
}
else if (sparam==obj_Btn_CLOSE_ALL.Name()){ //--- Check if the Close All button is clicked
Print("OBJECT CLICKED = ",obj_Btn_CLOSE_ALL.Name()); //--- Log the button click event
for (int i = PositionsTotal() -1; i >= 0; i--){ //--- Loop through all positions
ulong pos_ticket = PositionGetTicket(i); //--- Get the ticket of the position
if (pos_ticket > 0){ //--- Check if the position ticket is valid
if (PositionSelectByTicket(pos_ticket)){ //--- Select the position by ticket
if (PositionGetString(POSITION_SYMBOL)==_Symbol){ //--- Check if the position matches the symbol
obj_Trade.PositionClose(pos_ticket); //--- Close the position
}
}
}
}
}
else if (sparam==obj_Btn_CLOSE_ALL_SELL.Name()){ //--- Check if the Close All Sell button is clicked
Print("OBJECT CLICKED = ",obj_Btn_CLOSE_ALL_SELL.Name()); //--- Log the button click event
for (int i = PositionsTotal() -1; i >= 0; i--){ //--- Loop through all positions
ulong pos_ticket = PositionGetTicket(i); //--- Get the ticket of the position
if (pos_ticket > 0){ //--- Check if the position ticket is valid
if (PositionSelectByTicket(pos_ticket)){ //--- Select the position by ticket
if (PositionGetString(POSITION_SYMBOL)==_Symbol){ //--- Check if the position matches the symbol
ENUM_POSITION_TYPE pos_type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); //--- Get the position type
if (pos_type == POSITION_TYPE_SELL){ //--- Check if the position is a sell position
obj_Trade.PositionClose(pos_ticket); //--- Close the sell position
}
}
}
}
}
}
else if (sparam==obj_Btn_CLOSE_ALL_BUY.Name()){ //--- Check if the Close All Buy button is clicked
Print("OBJECT CLICKED = ",obj_Btn_CLOSE_ALL_BUY.Name()); //--- Log the button click event
for (int i = PositionsTotal() -1; i >= 0; i--){ //--- Loop through all positions
ulong pos_ticket = PositionGetTicket(i); //--- Get the ticket of the position
if (pos_ticket > 0){ //--- Check if the position ticket is valid
if (PositionSelectByTicket(pos_ticket)){ //--- Select the position by ticket
if (PositionGetString(POSITION_SYMBOL)==_Symbol){ //--- Check if the position matches the symbol
ENUM_POSITION_TYPE pos_type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); //--- Get the position type
if (pos_type == POSITION_TYPE_BUY){ //--- Check if the position is a buy position
obj_Trade.PositionClose(pos_ticket); //--- Close the buy position
}
}
}
}
}
}
else if (sparam==obj_Btn_CLOSE_LOSS_SELL.Name()){ //--- Check if the Close Loss Sell button is clicked
Print("OBJECT CLICKED = ",obj_Btn_CLOSE_LOSS_SELL.Name()); //--- Log the button click event
for (int i = PositionsTotal() -1; i >= 0; i--){ //--- Loop through all positions
ulong pos_ticket = PositionGetTicket(i); //--- Get the ticket of the position
if (pos_ticket > 0){ //--- Check if the position ticket is valid
if (PositionSelectByTicket(pos_ticket)){ //--- Select the position by ticket
if (PositionGetString(POSITION_SYMBOL)==_Symbol){ //--- Check if the position matches the symbol
ENUM_POSITION_TYPE pos_type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); //--- Get the position type
if (pos_type == POSITION_TYPE_SELL){ //--- Check if the position is a sell position
double profit_loss = PositionGetDouble(POSITION_PROFIT); //--- Get the profit/loss of the position
if (profit_loss < 0){ //--- Check if the position is at a loss
obj_Trade.PositionClose(pos_ticket); //--- Close the losing sell position
}
}
}
}
}
}
}
else if (sparam==obj_Btn_CLOSE_LOSS_BUY.Name()){ //--- Check if the Close Loss Buy button is clicked
Print("OBJECT CLICKED = ",obj_Btn_CLOSE_LOSS_BUY.Name()); //--- Log the button click event
for (int i = PositionsTotal() -1; i >= 0; i--){ //--- Loop through all positions
ulong pos_ticket = PositionGetTicket(i); //--- Get the ticket of the position
if (pos_ticket > 0){ //--- Check if the position ticket is valid
if (PositionSelectByTicket(pos_ticket)){ //--- Select the position by ticket
if (PositionGetString(POSITION_SYMBOL)==_Symbol){ //--- Check if the position matches the symbol
ENUM_POSITION_TYPE pos_type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); //--- Get the position type
if (pos_type == POSITION_TYPE_BUY){ //--- Check if the position is a buy position
double profit_loss = PositionGetDouble(POSITION_PROFIT); //--- Get the profit/loss of the position
if (profit_loss < 0){ //--- Check if the position is at Показано первые 50% кода (символов: 51445)
Открыть по тарифу
Купите тариф с пакетом открытий или войдите, если тариф уже есть. Открытый файл останется в вашем кабинете навсегда.
Разовая покупка файла
На этой странице откроется полный исходный код файла вместо ознакомительного фрагмента.
Зачем нужен email? После подтверждения оплаты файл сохранится в кабинете на этот email. Если аккаунта ещё нет, мы создадим его и пришлём ссылку для задания пароля. Если аккаунт уже есть, покупка добавится в него. Укажите адрес, к которому у вас есть доступ.
Чтобы оформить заказ, введите email и перейдите к оплате.