MQLArticles/Examples/GUI/BE/Main.mqh
650 líneas
22 KiB
MQL5
Nique_372
2026-08-28 22:40:45 -05:00
//+------------------------------------------------------------------+
//| Main.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372/news |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372/news"
#property strict
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
Nique_372
2026-10-29 21:39:16 -05:00
#define CACCOUNT_STATUS_ACTIVE_ON_POSITION_MODIFIED
#define TSNMQLART_POSMGMT_BE_ELOGS
Nique_372
2026-08-28 22:40:45 -05:00
Nique_372
2026-10-29 20:10:16 -05:00
//--- Librerias externas
// breakeven
#include <TSN\\MQLArticles\\PosMgmt\\Breakeven.mqh>
// mem manage
Nique_372
2026-10-25 12:35:06 -05:00
#include <TSN\\Std\\Memory.mqh>
Nique_372
2026-10-29 20:10:16 -05:00
// std symbol
Nique_372
2026-08-28 22:40:45 -05:00
#include <Trade\\SymbolInfo.mqh>
Nique_372
2026-10-29 20:10:16 -05:00
// GUI
Nique_372
2026-08-28 22:40:45 -05:00
#define private public
#define protected public
Nique_372
2026-10-29 20:10:16 -05:00
#include <TSN\\EAFMod\\WndCreate.mqh>
Nique_372
2026-08-28 22:40:45 -05:00
#undef private
#undef protected
//+------------------------------------------------------------------+
//| Resource |
//+------------------------------------------------------------------+
#resource "\\Images\\EasyAndFastGUI\\Icons\\bmp16\\arrow_up.bmp"
#resource "\\Images\\EasyAndFastGUI\\Icons\\bmp16\\arrow_down.bmp"
#resource "\\Images\\EasyAndFastGUI\\Controls\\checkbox_off.bmp"
Nique_372
2026-10-29 20:10:16 -05:00
#resource "\\Images\\EasyAndFastGUI\\Controls\\checkbox_on.bmp"
Nique_372
2026-08-28 22:40:45 -05:00
Nique_372
2026-10-29 20:10:16 -05:00
//---
const string image_array[2] =
Nique_372
2026-08-28 22:40:45 -05:00
{
"Images\\EasyAndFastGUI\\Icons\\bmp16\\arrow_up.bmp",
"Images\\EasyAndFastGUI\\Icons\\bmp16\\arrow_down.bmp"
};
//+------------------------------------------------------------------+
//| Defines |
//+------------------------------------------------------------------+
#define YSIZE_CAPTION 40
#define X_OFFSET_PANEL 5
#define Y_OFFSET_PANEL 5
#define TABLE_P_TICKET 0
#define TABLE_P_TYPE 1
#define TABLE_P_VOLUME 2
#define TABLE_P_ENTRY 3
#define TABLE_P_TAKEPROFIT 4
#define TABLE_P_STOPLOSS 5
#define TABLE_P_TRAILINGSTOP_CHECKBOX 6
#define PANEL_TABLE_IMAGE_IDX_UP 0
#define PANEL_TABLE_IMAGE_IDX_DOWN 1
#define BREAKEVEN_PANEL_MAX_POS (256)
Nique_372
2026-10-29 20:10:16 -05:00
Nique_372
2026-08-28 22:40:45 -05:00
//+------------------------------------------------------------------+
//| Global variables |
//+------------------------------------------------------------------+
Nique_372
2026-10-29 20:10:16 -05:00
TSN::CBreakEvenCreator g_breakeven_creator;
Nique_372
2026-08-28 22:40:45 -05:00
//+------------------------------------------------------------------+
//| CBreakEvenPanel class |
//+------------------------------------------------------------------+
class CBreakEvenPanel : public CWndCreate
{
Nique_372
2026-10-29 20:10:16 -05:00
public:
struct pack(4) TicketRelations
{
int idx_in_row_positions;
int idx_in_data;
};
Nique_372
2026-08-28 22:40:45 -05:00
private:
//---
int m_width_panel;
Nique_372
2026-09-13 08:47:52 -05:00
TSN::ENUM_BREAKEVEN_TYPE m_mode_breakeven;
Nique_372
2026-08-28 22:40:45 -05:00
bool m_enable_to_trailing;
//---
Nique_372
2026-10-29 20:10:16 -05:00
TSN::CBreakEvenBase* m_breakevens[BREAKEVEN_PANEL_MAX_POS];
Nique_372
2026-08-28 22:40:45 -05:00
CSymbolInfo* m_symbol_array[BREAKEVEN_PANEL_MAX_POS];
Nique_372
2026-10-29 20:10:16 -05:00
int m_data_s; // numero de bes
// el tamño de bes=numero de symbolos usados
Nique_372
2026-08-28 22:40:45 -05:00
Nique_372
2026-10-29 20:10:16 -05:00
//--- File->Posicion (ticket)
ulong m_row_por_posicion[BREAKEVEN_PANEL_MAX_POS];
Nique_372
2026-08-28 22:40:45 -05:00
int m_row_por_posicion_s;
//---
CHashMapFast(string, int) m_hasmap_symbol_por_pos; // delveullve la poscoin en el array en base al simbolo
Nique_372
2026-10-29 20:10:16 -05:00
CHashMapFastRP(ulong, TicketRelations, _fibbo) m_hashmap_idxs; // em nase al ticket te da el idx en csymbol y be
Nique_372
2026-08-28 22:40:45 -05:00
//---
CWindow m_window;
CTabs m_tabs;
//---
CTable m_table_principal;
//---
CTextLabel m_label_text;
CComboBox m_combox_be_type;
CTextBox m_text_box1;
Nique_372
2026-10-29 20:10:16 -05:00
//---
string m_err;
Nique_372
2026-08-28 22:40:45 -05:00
//---
void OnChangeComboxTSL();
void RedrawCompletePanel();
//---
Nique_372
2026-09-13 08:47:52 -05:00
class CAccountGestorInt : public TSN::CAccountGestor
Nique_372
2026-08-28 22:40:45 -05:00
{
private:
CBreakEvenPanel* m_padre;
public:
//--- Constructor
CAccountGestorInt(CBreakEvenPanel* p) : m_padre(p)
{
Nique_372
2026-09-13 08:47:52 -05:00
TSN::account_status.RegisterEvents(&this,
ACCOUNT_STATUS_REG_FLAG_ON_CLOSE_POSITION |
ACCOUNT_STATUS_REG_FLAG_ON_OPEN_POSITION |
ACCOUNT_STATUS_REG_FLAG_ON_POSITION_MODIFY |
ACCOUNT_STATUS_REG_FLAG_ON_INIT_NEW_POS);
Nique_372
2026-08-28 22:40:45 -05:00
}
//--- Destructor
~CAccountGestorInt(void)
{
Nique_372
2026-09-13 08:47:52 -05:00
if(TSN::account_status.IsActive())
TSN::account_status.UnregisterEvents(&this,
ACCOUNT_STATUS_REG_FLAG_ON_CLOSE_POSITION |
ACCOUNT_STATUS_REG_FLAG_ON_OPEN_POSITION |
ACCOUNT_STATUS_REG_FLAG_ON_POSITION_MODIFY |
ACCOUNT_STATUS_REG_FLAG_ON_INIT_NEW_POS);
Nique_372
2026-08-28 22:40:45 -05:00
}
//---
Nique_372
2026-09-13 08:47:52 -05:00
void OnOpenPosition(const TSN::ROnOpenPosition &pos) override final { m_padre.OnOpenPosition(pos); }
void OnClosePosition(const TSN::ROnClosePosition &pos, const int global_pos_index) override final { m_padre.OnClosePosition(pos, global_pos_index); }
void OnPositionModify(const TSN::Position& pos, const uint8_t change_flags) override final { m_padre.OnPositionModify(pos, change_flags); }
void OnInitNewPos(const TSN::ROnOpenPosition &position) override final { m_padre.OnInitNewPos(position); }
Nique_372
2026-08-28 22:40:45 -05:00
};
CAccountGestorInt* m_gestor;
public:
CBreakEvenPanel();
~CBreakEvenPanel() { if(m_gestor != NULL) delete m_gestor; }
//---
void OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam) override;
void OnDeinitEvent(const int reason);
void OnTickEvent();
//
Nique_372
2026-09-13 08:47:52 -05:00
void OnOpenPosition(const TSN::ROnOpenPosition &pos);
void OnClosePosition(const TSN::ROnClosePosition &pos, const int global_pos_index);
void OnPositionModify(const TSN::Position& pos, const uint8_t change_flags);
void OnInitNewPos(const TSN::ROnOpenPosition &position);
Nique_372
2026-08-28 22:40:45 -05:00
//---
CAccountGestorInt* GetGestorInt() { return m_gestor; }
//---
Nique_372
2026-10-29 20:10:16 -05:00
void CreateGUI(int WIDTH_PANEL, int HEIGHT_PANEL, TSN::ENUM_BREAKEVEN_TYPE be_initial_type);
Nique_372
2026-08-28 22:40:45 -05:00
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
CBreakEvenPanel::CBreakEvenPanel(void)
: m_row_por_posicion_s(0), m_data_s(0),
Nique_372
2026-10-29 20:10:16 -05:00
m_hasmap_symbol_por_pos(BREAKEVEN_PANEL_MAX_POS), m_hashmap_idxs(BREAKEVEN_PANEL_MAX_POS),
Nique_372
2026-08-28 22:40:45 -05:00
m_enable_to_trailing(false)
{
m_gestor = new CAccountGestorInt(&this);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CBreakEvenPanel::OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
if(id == CHARTEVENT_CUSTOM + ON_CLICK_CHECKBOX)
{
if(m_enable_to_trailing && lparam == m_table_principal.Id())
{
Nique_372
2026-10-29 20:10:16 -05:00
//---
const bool state = (bool)dparam;
//---
Nique_372
2026-10-29 21:39:16 -05:00
int i = sparam.Find("_"), row;
if(i == -1)
{
FastLog(FUNCION_ACTUAL, WARNING_TEXT, StringFormat("Se ignoro '%s'", sparam));
return; // nada
}
i++; // suma
TSN::CStringConvert::ToValueNSigned(sparam, i, row, StringLen(sparam));
Nique_372
2026-08-28 22:40:45 -05:00
//uint col = StringToInteger(res[1]);
//Print(sparam);
Nique_372
2026-10-29 20:10:16 -05:00
//---
TicketRelations rel;
const ulong pos = m_row_por_posicion[row];
m_hashmap_idxs.TryGet(pos, rel);
//---
Nique_372
2026-11-05 17:49:32 -05:00
if(state ? (!m_breakevens[rel.idx_in_data].Add(pos)) : (!m_breakevens[rel.idx_in_data].Remove(pos)))
Nique_372
2026-08-28 22:40:45 -05:00
{
Nique_372
2026-11-05 17:49:32 -05:00
// Fallaron
StringSetLength(m_err, 0); // reset
Nique_372
2026-11-06 10:41:14 -05:00
TSN::CErrorTrace::FormatTrace(m_err);
Nique_372
2026-11-05 17:49:32 -05:00
FastLog(FUNCION_ACTUAL, ERROR_TEXT, m_err);
Nique_372
2026-08-28 22:40:45 -05:00
}
}
return;
}
if(id == CHARTEVENT_CUSTOM + ON_CLICK_COMBOBOX_ITEM)
{
if(lparam == m_combox_be_type.Id())
OnChangeComboxTSL();
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CBreakEvenPanel::OnChangeComboxTSL(void)
{
//---
const string slected = m_combox_be_type.GetValue();
const int idx = m_combox_be_type.GetListViewPointer().SelectedItemIndex();
Nique_372
2026-10-30 09:52:05 -05:00
m_mode_breakeven = (TSN::ENUM_BREAKEVEN_TYPE)idx;
Nique_372
2026-08-28 22:40:45 -05:00
//---
Nique_372
2026-10-29 20:10:16 -05:00
int idx_remove[];
ArrayResize(idx_remove, m_data_s);
int w = 0;
//---
Nique_372
2026-11-05 17:49:32 -05:00
TSN::BreakEvenCreatorRes res(NULL, false);
Nique_372
2026-08-28 22:40:45 -05:00
for(int k = 0; k < m_data_s; k++)
Nique_372
2026-10-29 20:10:16 -05:00
{
//---
delete m_breakevens[k]; // limpiamos
//--- Creamos uno nuevo
const string symbol = m_symbol_array[k].Name();
res = g_breakeven_creator.Create(m_mode_breakeven, symbol, NOT_MAGIC_NUMBER);
Nique_372
2026-11-05 17:49:32 -05:00
if(!res.ok)
Nique_372
2026-10-29 20:10:16 -05:00
{
Nique_372
2026-11-05 17:49:32 -05:00
m_err = "Error in modify breakeven mode with idx = " + string(k) + TSNSTD_ERRTRACE_SEPARATOR;
Nique_372
2026-11-06 10:41:14 -05:00
TSN::CErrorTrace::FormatTrace(m_err);
Nique_372
2026-10-29 20:10:16 -05:00
FastLog(FUNCION_ACTUAL, ERROR_TEXT, m_err);
//---
idx_remove[w++] = k;
continue;
}
//---
m_breakevens[k] = res.ptr;
}
Nique_372
2026-08-28 22:40:45 -05:00
//---
for(int k = 0; k < (int)m_table_principal.RowsTotal(); k++)
m_table_principal.ChangeImage(TABLE_P_TRAILINGSTOP_CHECKBOX, k, 0);
//---
m_table_principal.Update(true);
Nique_372
2026-11-01 17:44:41 -05:00
FastLog(FUNCION_ACTUAL, INFO_TEXT, StringFormat("Nuevo modo de breakeven = '%s'", TSN::g_breakevens_types_str[m_mode_breakeven]));
Nique_372
2026-10-29 20:10:16 -05:00
//---
ArrayResize(idx_remove, w);
RemoveMultipleIndexesWithVSize(m_breakevens, m_data_s, idx_remove);
Nique_372
2026-08-28 22:40:45 -05:00
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CBreakEvenPanel::OnDeinitEvent(const int reason)
{
//---
for(int i = 0; i < m_data_s; i++)
{
delete m_symbol_array[i];
delete m_breakevens[i]; //cuidado no se elimna rel putnero interno eso lo hace account status
}
Nique_372
2026-10-29 20:10:16 -05:00
Nique_372
2026-08-28 22:40:45 -05:00
//---
CWndEvents::Destroy();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CBreakEvenPanel::OnTickEvent(void)
{
for(int i = 0; i < m_data_s; i++)
Nique_372
2026-10-29 20:10:16 -05:00
m_breakevens[i].BreakEven();
Nique_372
2026-08-28 22:40:45 -05:00
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-10-29 20:10:16 -05:00
void CBreakEvenPanel::CreateGUI(int WIDTH_PANEL, int HEIGHT_PANEL, TSN::ENUM_BREAKEVEN_TYPE be_initial_type)
Nique_372
2026-08-28 22:40:45 -05:00
{
//---
Nique_372
2026-10-29 20:10:16 -05:00
this.m_mode_breakeven = be_initial_type;
Nique_372
2026-08-28 22:40:45 -05:00
//---
m_width_panel = fmax(WIDTH_PANEL, 200);
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
m_window.CaptionColor(clrGray);
m_window.CaptionColorHover(clrGray);
m_window.CaptionColorLocked(clrBlack);
m_window.BorderColor(C'212,212,212');
m_window.BackColorPressed(clrBlue);
m_window.Font("Arial Black");
CWndCreate::CreateWindow(m_window, "BreakevenManager", 0, 0, m_width_panel, HEIGHT_PANEL, true, false, true, true);
//--- Tabs
Nique_372
2026-10-29 20:10:16 -05:00
static string texts[2] = { "General", "Configuracion"};
Nique_372
2026-08-28 22:40:45 -05:00
int widts[2] = {100, 90};
color clrs[2] = {clrNONE, clrNONE}; // defa
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
int x = m_window.X() + X_OFFSET_PANEL;
int y = m_window.Y() + (YSIZE_CAPTION + Y_OFFSET_PANEL);
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
int xsize_tabs = (m_window.XSize()) - (X_OFFSET_PANEL * 2);
int ysize_tabs = (m_window.YSize() - YSIZE_CAPTION) - (Y_OFFSET_PANEL * 2);
m_tabs.BackColor(C'191,191,191');
m_tabs.BackColorPressed(C'201,203,205');
CWndCreate::CreateTabs(m_tabs, m_window, 0, x, y, xsize_tabs, ysize_tabs, texts, widts, clrs, clrs);
//---
#define X_OFFSET_INTERNO 7
x += X_OFFSET_INTERNO;
y += 20;
int x_table = x;
int y_table = y;
Print(m_tabs.YGap());
Print(m_tabs.XGap());
//--- Pestaña 1
#define COLS_TOTAL_TABLE 7
Nique_372
2026-10-29 20:10:16 -05:00
static string headers[COLS_TOTAL_TABLE] = {"Ticket", "Type", "Volume", "Entry", "Takeprofit", "Stoploss", "Breakeven"};
Nique_372
2026-08-28 22:40:45 -05:00
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
int xsize_table = xsize_tabs - (X_OFFSET_INTERNO * 2);
int ysize_table = ysize_tabs - (Y_OFFSET_PANEL * 2) - (20); //tamaño util | tmaaño dellos offeset | tamaño del header tabs
#define HEADER_YSIZE_TABLE 30
m_table_principal.HeaderYSize(HEADER_YSIZE_TABLE);
CWndCreate::CreateTable(m_table_principal, m_window, 0, m_tabs, 0, COLS_TOTAL_TABLE, 1, headers, x_table, y_table, xsize_table, ysize_table, false, false);
ENUM_ALIGN_MODE align[COLS_TOTAL_TABLE];
::ArrayInitialize(align, ALIGN_LEFT);
//align[TABLE_P_TYPE] = ALIGN_RIGHT;
//align[TABLE_P_TRAILINGSTOP_CHECKBOX] = ALIGN_LEFT;
//Print(xsize_table);
//---
int widths[COLS_TOTAL_TABLE];
const double col_proportions[COLS_TOTAL_TABLE] = {0.162, 0.102, 0.122, 0.142, 0.142, 0.142, 0.182};
int sum = 0;
for(int i = 0; i < COLS_TOTAL_TABLE; i++)
{
widths[i] = (int)(xsize_table * col_proportions[i]);
sum += widths[i];
}
int rest = xsize_table - sum;
widths[COLS_TOTAL_TABLE - 1] += rest < 0 ? 0 : rest;
//ArrayPrint(widths);
//Print(m_table_principal.XSize());
//--- Setemoas offeset imagen
//ofeset de los iconos imagenes
int imge_x_offset[COLS_TOTAL_TABLE] = {0, 8, 0, 0, 0, 0, 8};
int imge_y_offset[COLS_TOTAL_TABLE] = {0, 7, 0, 0, 0, 0, 7};
m_table_principal.ImageXOffset(imge_x_offset);
m_table_principal.ImageYOffset(imge_y_offset);
//--- Propiedades generales
int ysize_utilizable = ysize_table - HEADER_YSIZE_TABLE;
m_table_principal.TextAlign(align);
m_table_principal.ColumnsWidth(widths);
m_table_principal.HeadersColor(C'0x06,0x9C,0xCE');
m_table_principal.CellColor(clrWhiteSmoke);
m_table_principal.CellYSize(30);
//--- Array of text offset along the X axis in the columns
int text_x_offset[COLS_TOTAL_TABLE];
::ArrayInitialize(text_x_offset, 5);
text_x_offset[TABLE_P_TRAILINGSTOP_CHECKBOX] += 22;
text_x_offset[TABLE_P_TYPE] += 20;
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
m_table_principal.TextXOffset(text_x_offset);
m_table_principal.SetImages(TABLE_P_TYPE, 0, image_array);
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
m_table_principal.DataType(TABLE_P_TICKET, TYPE_ULONG);
m_table_principal.DataType(TABLE_P_TYPE, TYPE_STRING);
m_table_principal.DataType(TABLE_P_VOLUME, TYPE_DOUBLE);
m_table_principal.DataType(TABLE_P_ENTRY, TYPE_DOUBLE);
m_table_principal.DataType(TABLE_P_TAKEPROFIT, TYPE_DOUBLE);
m_table_principal.DataType(TABLE_P_STOPLOSS, TYPE_DOUBLE);
//---
int x_label = x;
int y_label = y;
CWndCreate::CreateTextLabel(m_label_text, "Elija el tipo de breakeven", m_window, 0, m_tabs, 1, x_label, y_label, 210, 40);
m_label_text.BackColor(C'201,203,205');
m_label_text.FontSize(12);
y += 30;
Nique_372
2026-10-29 20:10:16 -05:00
//---
static string trailign_stop_type[3] = { "Breakeven by rr", "Breakeven by fixed points", "Breakeven by atr"};
Nique_372
2026-08-28 22:40:45 -05:00
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
int pos = (int)this.m_mode_breakeven;
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
CWndCreate::CreateCombobox(m_combox_be_type, "Tipo de breakeven: ", m_window, 0, m_tabs, 1, false, x, y, 262, 150, trailign_stop_type, 65, pos);
m_combox_be_type.BackColor(C'201,203,205');
m_combox_be_type.FontSize(10);
//--- Final
CWndEvents::CompletedGUI();
}
/*
#define TABLE_P_TICKET 0
#define TABLE_P_TYPE 1
#define TABLE_P_VOLUME 2
#define TABLE_P_ENTRY 3
#define TABLE_P_TAKEPROFIT 4
#define TABLE_P_STOPLOSS 5
#define TABLE_P_TRAILINGSTOP_CHECKBOX 6
*/
Nique_372
2026-10-29 20:10:16 -05:00
//+------------------------------------------------------------------+
//| |
Nique_372
2026-08-28 22:40:45 -05:00
//+------------------------------------------------------------------+
Nique_372
2026-09-13 08:47:52 -05:00
void CBreakEvenPanel::OnOpenPosition(const TSN::ROnOpenPosition &pos)
Nique_372
2026-08-28 22:40:45 -05:00
{
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
m_enable_to_trailing = true;
Nique_372
2026-10-29 20:10:16 -05:00
//---
const ulong ticket = pos.position.ticket;
Nique_372
2026-10-25 12:35:06 -05:00
const string symbol_name = TSN::account_status.last_trans_symbol;
Nique_372
2026-08-28 22:40:45 -05:00
CSymbolInfo* ptr_symbol;
//--- Obtemos info del simbolo
Nique_372
2026-10-29 20:10:16 -05:00
int pos_symbol;
if(!m_hasmap_symbol_por_pos.ReserveSlot(symbol_name)) //obtenemos datos del simbolo
Nique_372
2026-08-28 22:40:45 -05:00
{
Nique_372
2026-10-29 20:10:16 -05:00
const uint p = m_hasmap_symbol_por_pos.m_last_pos_tbl;
pos_symbol = m_hasmap_symbol_por_pos.m_table[p].value;
Nique_372
2026-08-28 22:40:45 -05:00
ptr_symbol = m_symbol_array[pos_symbol];
}
else
{
ptr_symbol = new CSymbolInfo();
ptr_symbol.Name(symbol_name);
//--- Creacion del breakeven
Nique_372
2026-10-29 20:10:16 -05:00
TSN::BreakEvenCreatorRes res = g_breakeven_creator.Create(m_mode_breakeven, symbol_name, NOT_MAGIC_NUMBER);
Nique_372
2026-11-05 17:49:32 -05:00
if(!res.ok)
Nique_372
2026-10-29 20:10:16 -05:00
{
StringSetLength(m_err, 0);
Nique_372
2026-11-06 10:41:14 -05:00
TSN::CErrorTrace::FormatTrace(m_err);
Nique_372
2026-10-29 20:10:16 -05:00
FastLog(FUNCION_ACTUAL, ERROR_TEXT, m_err);
return;
}
//---
TSN::CBreakEvenBase* new_be = res.ptr;
new_be.Automatic(false); // No sera automatico
Nique_372
2026-08-28 22:40:45 -05:00
//---
m_symbol_array[m_data_s] = ptr_symbol;
m_breakevens[m_data_s] = new_be;
//---
Nique_372
2026-10-29 20:10:16 -05:00
const uint p = m_hasmap_symbol_por_pos.m_last_pos_tbl;
m_hasmap_symbol_por_pos.m_table[p].key = symbol_name;
m_hasmap_symbol_por_pos.m_table[p].value = m_data_s;
//---
Nique_372
2026-08-28 22:40:45 -05:00
pos_symbol = m_data_s++;
}
//--- Aumentamos el taamaño de tickets por row
Nique_372
2026-10-29 20:10:16 -05:00
m_row_por_posicion[m_row_por_posicion_s++] = ticket;
Nique_372
2026-08-28 22:40:45 -05:00
//--- obteneos el row, y si no coincide entonces resize
int row_index = int(m_table_principal.RowsTotal() - 1);
if(row_index != m_row_por_posicion_s - 1)
{
row_index++;
m_table_principal.AddRow(row_index);
m_table_principal.SetImages(TABLE_P_TYPE, row_index, image_array);
}
//---
Nique_372
2026-10-29 20:10:16 -05:00
TicketRelations relations;
relations.idx_in_data = pos_symbol;
relations.idx_in_row_positions = row_index;
//---
m_hashmap_idxs.Add(ticket, relations);
Nique_372
2026-08-28 22:40:45 -05:00
//---
//PrintFormat("Row = %d | Ticket = %I64u | Digitos %d", row_index, pos.position.ticket, ptr_symbol.Digits());
//--- ticket
Nique_372
2026-10-29 20:10:16 -05:00
m_table_principal.SetValue(TABLE_P_TICKET, row_index, IntegerToString(ticket), 0);
Nique_372
2026-08-28 22:40:45 -05:00
//--- Tipo
Nique_372
2026-10-29 20:10:16 -05:00
static const string type_entrys[2] = { "Buy", "Sell"};
const uint image_index[2] = { PANEL_TABLE_IMAGE_IDX_UP, PANEL_TABLE_IMAGE_IDX_DOWN};
const color clr_index[2] = { clrGreen, clrRed};
Nique_372
2026-08-28 22:40:45 -05:00
const uint8_t t = (uint8_t)pos.position.type;
//---
m_table_principal.SetValue(TABLE_P_TYPE, row_index, type_entrys[t]);
m_table_principal.TextColor(TABLE_P_TYPE, row_index, clr_index[t]);
m_table_principal.ChangeImage(TABLE_P_TYPE, row_index, t);
Nique_372
2026-10-29 20:10:16 -05:00
//---
Nique_372
2026-08-28 22:40:45 -05:00
m_table_principal.SetValue(TABLE_P_VOLUME, row_index, DoubleToString(pos.position.volume), 3);
m_table_principal.SetValue(TABLE_P_ENTRY, row_index, DoubleToString(pos.position.open_price), ptr_symbol.Digits());
m_table_principal.SetValue(TABLE_P_TAKEPROFIT, row_index, DoubleToString(pos.position.tp), ptr_symbol.Digits());
m_table_principal.SetValue(TABLE_P_STOPLOSS, row_index, DoubleToString(pos.position.sl), ptr_symbol.Digits());
Nique_372
2026-10-29 20:10:16 -05:00
//---
static const string image_array_chekbox[2] =
Nique_372
2026-08-28 22:40:45 -05:00
{
"Images\\EasyAndFastGUI\\Controls\\checkbox_off.bmp",
"Images\\EasyAndFastGUI\\Controls\\checkbox_on.bmp"
};
//---
m_table_principal.SetImages(TABLE_P_TRAILINGSTOP_CHECKBOX, row_index, image_array_chekbox);
m_table_principal.ChangeImage(TABLE_P_TRAILINGSTOP_CHECKBOX, row_index, 0); //0 por defecto
m_table_principal.SetValue(TABLE_P_TRAILINGSTOP_CHECKBOX, row_index, "Breakeven", 0);
m_table_principal.CellType(TABLE_P_TRAILINGSTOP_CHECKBOX, row_index, CELL_CHECKBOX);
m_table_principal.Update(true);
}
//+------------------------------------------------------------------+
Nique_372
2026-09-13 08:47:52 -05:00
void CBreakEvenPanel::OnClosePosition(const TSN::ROnClosePosition &pos, const int global_pos_index)
Nique_372
2026-08-28 22:40:45 -05:00
{
Nique_372
2026-10-29 20:10:16 -05:00
TicketRelations relations;
if(m_hashmap_idxs.TryGet(pos.position.ticket, relations)) //obtnemos el row de la posicion en base al ticket
Nique_372
2026-08-28 22:40:45 -05:00
{
//--- eliminamos la fila de la tabla
if(m_table_principal.RowsTotal() > 1) //mas de 1 fila
{
Nique_372
2026-10-29 20:10:16 -05:00
m_table_principal.DeleteRow(relations.idx_in_row_positions, true); //eliminamos la fila
Nique_372
2026-08-28 22:40:45 -05:00
}
else //1 fila
{
//--- ticket
for(int i = 0; i < COLS_TOTAL_TABLE; i++)
{
m_table_principal.SetValue(i, 0); //reset a null
}
m_table_principal.Update(true);
m_enable_to_trailing = false;
}
//---
Nique_372
2026-10-29 20:10:16 -05:00
m_hashmap_idxs.RemoveLastFindCall();
Nique_372
2026-08-28 22:40:45 -05:00
//--- eliiminamos el indice del array de posicoines [row -> (posicion = ticket)]
int index_to_remove[1];
Nique_372
2026-10-29 20:10:16 -05:00
index_to_remove[0] = relations.idx_in_row_positions;
//---
Nique_372
2026-08-28 22:40:45 -05:00
RemoveMultipleIndexesWithVSize(m_row_por_posicion, m_row_por_posicion_s, index_to_remove);
}
}
//+------------------------------------------------------------------+
// Funcion que se ejecuta en OnInit, solo si hay posiciones abiertas
Nique_372
2026-09-13 08:47:52 -05:00
void CBreakEvenPanel::OnInitNewPos(const TSN::ROnOpenPosition &position)
Nique_372
2026-08-28 22:40:45 -05:00
{
Nique_372
2026-10-29 20:10:16 -05:00
OnOpenPosition(position); // Reutilizamos
Nique_372
2026-08-28 22:40:45 -05:00
}
Nique_372
2026-10-29 20:10:16 -05:00
//+------------------------------------------------------------------+
//| |
Nique_372
2026-08-28 22:40:45 -05:00
//+------------------------------------------------------------------+
Nique_372
2026-09-13 08:47:52 -05:00
void CBreakEvenPanel::OnPositionModify(const TSN::Position &pos, const uchar change_flags)
Nique_372
2026-08-28 22:40:45 -05:00
{
Nique_372
2026-10-29 20:10:16 -05:00
TicketRelations relations;
if(m_hashmap_idxs.TryGet(pos.ticket, relations)) // En base al ticket obteneis los indices
Nique_372
2026-08-28 22:40:45 -05:00
{
//--- Obtemos info del simbolo
Nique_372
2026-10-29 20:10:16 -05:00
CSymbolInfo* ptr_symbol = m_symbol_array[relations.idx_in_data];
Nique_372
2026-08-28 22:40:45 -05:00
//---
if((change_flags & ACCOUNTSTATUS_ON_POS_MODIFY_FLAG_CHANGE_SL) != 0)
Nique_372
2026-10-29 20:10:16 -05:00
m_table_principal.SetValue(TABLE_P_STOPLOSS, relations.idx_in_row_positions, DoubleToString(pos.sl), ptr_symbol.Digits());
Nique_372
2026-08-28 22:40:45 -05:00
if((change_flags & ACCOUNTSTATUS_ON_POS_MODIFY_FLAG_CHANGE_TP) != 0)
Nique_372
2026-10-29 20:10:16 -05:00
m_table_principal.SetValue(TABLE_P_TAKEPROFIT, relations.idx_in_row_positions, DoubleToString(pos.tp), ptr_symbol.Digits());
Nique_372
2026-08-28 22:40:45 -05:00
//---
m_table_principal.Update(true);
}
}
//+------------------------------------------------------------------+