173 lines
4.9 KiB
Plaintext
173 lines
4.9 KiB
Plaintext
//+------------------------------------------------------------------+
|
|
//| ProjectName |
|
|
//| Copyright 2020, CompanyName |
|
|
//| http://www.companyname.net |
|
|
//+------------------------------------------------------------------+
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../Classes/XCObjects/x-saherelm.x-panel.class.mq5"
|
|
#include <Trade/Trade.mqh>
|
|
|
|
//
|
|
CTrade trade;
|
|
|
|
//
|
|
string mTag;
|
|
XCPanel eaPanel;
|
|
XCButton eaStateBtn;
|
|
string eaStateBtnName;
|
|
bool eaEnableLongs = true;
|
|
bool eaEnableShorts = true;
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert initialization function |
|
|
//+------------------------------------------------------------------+
|
|
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
|
|
return (INIT_SUCCEEDED);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Expert deinitialization function |
|
|
//+------------------------------------------------------------------+
|
|
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();
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//|Chart event handling function |
|
|
//+------------------------------------------------------------------+
|
|
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);
|
|
|
|
//
|
|
eaPanel.OnEvent(id, lparam, dparam, sparam);
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
|
|
//
|
|
bool InitialPanel()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Create a Panel ...
|
|
result = eaPanel.Create(
|
|
mTag,
|
|
100,
|
|
100,
|
|
300,
|
|
200 //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Create Activation Button ...
|
|
string eaStatePrefix = mTag + "_State_";
|
|
eaStateBtnName = eaStatePrefix + "lbl";
|
|
result = eaStateBtn.Create(
|
|
eaStateBtnName,
|
|
100,
|
|
120,
|
|
100,
|
|
25 //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
eaStateBtn.SetZOrder(100);
|
|
|
|
//
|
|
eaPanel.Add(eaStateBtnName);
|
|
|
|
//
|
|
return result;
|
|
} |