last works on GUI ...

This commit is contained in:
2024-09-25 03:55:35 +03:30
parent 2cca497b62
commit 960ac6fd82
6 changed files with 179 additions and 98 deletions
+118 -89
View File
@@ -17,6 +17,10 @@ string mTag;
XCPanel eaPanel;
XCButton eaStateBtn;
string eaStateBtnName;
XCButton eaLongStateBtn;
string eaLongStateBtnName;
XCButton eaShortStateBtn;
string eaShortStateBtnName;
bool eaEnableLongs = true;
bool eaEnableShorts = true;
@@ -25,60 +29,13 @@ bool eaEnableShorts = true;
//+------------------------------------------------------------------+
int OnInit()
{
//
// panel.Create("XPanel", 100, 100, 300, 200);
//
// Enables mouse move events on the chart
// ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, true);
// Initialize and set properties for Title bar, main dashboard, and all other elements
// TitleBar.Create("TitleBar", 100, 100, 200, 20);
// TitleBar.SetBorderType(BORDER_FLAT);
// TitleBar.SetBGColor(C'27, 59, 146');
// MainDashboardBody.Create("MainDashboardBody", 100, 119, 200, 100);
// MainDashboardBody.SetBorderType(BORDER_FLAT);
// MainDashboardBody.SetBGColor(C'102, 152, 250');
// TitleText.Create("TitleText", 110, 101);
// TitleText.SetText("Simple Trading EA V1.0");
// TitleText.SetFontSize(10);
// TitleText.SetTextColor(clrWhite);
// LotSizeText.Create("LotSizeText", 110, 140);
// LotSizeText.SetText("Lot Size:");
// LotSizeText.SetFontSize(12);
// LotSizeText.SetTextColor(clrWhite);
// LotSize.Create("LotSize", 220, 140, 50, 20);
// LotSize.SetBorderColor(clrBlack);
// LotSize.SetBGColor(clrWhiteSmoke);
// LotSize.SetText("0.01");
// LotSize.SetTextColor(clrBlack);
// BuyButton.Create("BuyButton", 110, 180, 80, 25);
// BuyButton.SetBorderColor(clrBlack);
// BuyButton.SetText("Buy");
// BuyButton.SetBGColor(clrLime);
// SellButton.Create("SellButton", 210, 180, 80, 25);
// SellButton.SetBorderColor(clrBlack);
// SellButton.SetText("Sell");
// SellButton.SetBGColor(clrRed);
// Add the other elements to the Central Element i.e. TitleBar object in this case
// TitleBar.Add("MainDashboardBody");
// TitleBar.Add("TitleText");
// TitleBar.Add("LotSizeText");
// TitleBar.Add("LotSize");
// TitleBar.Add("BuyButton");
// TitleBar.Add("SellButton");
//
mTag = "XPanel";
InitialPanel();
ChartRedraw(0); // Redraws the chart
if (!InitialGUI()) {
return INIT_FAILED;
}
//
return (INIT_SUCCEEDED);
}
@@ -87,17 +44,7 @@ int OnInit()
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Destroys all GUI objects
// TitleBar.Destroy();
// MainDashboardBody.Destroy();
// TitleText.Destroy();
// LotSizeText.Destroy();
// LotSize.Destroy();
// BuyButton.Destroy();
// SellButton.Destroy();
//
eaPanel.Destroy();
DestroyGUI();
}
//+------------------------------------------------------------------+
@@ -105,31 +52,25 @@ void OnDeinit(const int reason)
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
// Handles click events for Buy and Sell buttons and opens corresponding positions
// if (id == CHARTEVENT_OBJECT_CLICK)
// {
// double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
// double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
// if (sparam == "BuyButton")
// {
// trade.PositionOpen(_Symbol, ORDER_TYPE_BUY, (double)LotSize.GetText(), ask, 0, 0);
// }
// if (sparam == "SellButton")
// {
// trade.PositionOpen(_Symbol, ORDER_TYPE_SELL, (double)LotSize.GetText(), bid, 0, 0);
// }
// }
// // Passes events to the TitleBar object
// TitleBar.OnEvent(id, lparam, dparam, sparam);
//
// Handle Object Movement ...
eaPanel.OnEvent(id, lparam, dparam, sparam);
//
eaPanel.OnEvent(id, lparam, dparam, sparam);
// Handle OnClick Event ...
if (id == CHARTEVENT_OBJECT_CLICK)
{
HandleOnClickEvent(sparam);
}
}
//+------------------------------------------------------------------+
//
bool InitialPanel()
/**
* Initial GUI ...
*
* @return ( bool )
*/
bool InitialGUI()
{
//
bool result = false;
@@ -151,23 +92,111 @@ bool InitialPanel()
//
// Create Activation Button ...
string eaStatePrefix = mTag + "_State_";
eaStateBtnName = eaStatePrefix + "lbl";
//
// Signalling ...
eaStateBtnName = eaStatePrefix + "btn";
result = eaStateBtn.Create(
eaStateBtnName,
100,
120,
100,
300,
25 //
);
if (!result)
{
return result;
}
eaStateBtn.SetZOrder(100);
//
eaPanel.Add(eaStateBtnName);
//
// Long Signalling ...
eaLongStateBtnName = eaStatePrefix + "_Long_btn";
result = eaLongStateBtn.Create(
eaLongStateBtnName,
100,
145,
150,
25 //
);
if (!result)
{
return result;
}
eaPanel.Add(eaLongStateBtnName);
//
// Short Signalling ...
eaShortStateBtnName = eaStatePrefix + "_Short_btn";
result = eaShortStateBtn.Create(
eaShortStateBtnName,
250,
145,
150,
25 //
);
if (!result)
{
return result;
}
eaPanel.Add(eaShortStateBtnName);
//
ChartRedraw(0);
//
return result;
}
}
/**
* Destroy GUI ...
*/
void DestroyGUI()
{
//
eaStateBtnName = NULL;
eaLongStateBtnName = NULL;
eaShortStateBtnName = NULL;
//
eaPanel.Destroy();
eaStateBtn.Destroy();
eaLongStateBtn.Destroy();
eaShortStateBtn.Destroy();
}
/**
* Handle Object's Click Events ...
*
* @param name: Clicked Object Name
*/
void HandleOnClickEvent(string name)
{
//
if (!IsValid(name))
{
return;
}
//
// State Button ...
if (name == eaStateBtnName)
{
//
Print("State Button Clicked ...");
}
//
else if (name == eaLongStateBtnName)
{
//
Print("Long State Button Clicked ...");
}
//
else if (name == eaShortStateBtnName)
{
//
Print("Short State Button Clicked ...");
}
}
//