0
Views
0
Downloads
0
Favorites
Pending Min Max Previous Bar Panel
//+------------------------------------------------------------------+
//| Pending Min Max Previous Bar Panel.mq5 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#include "TradingEngine31.mqh"
CTradingEngine31 m_trading_engine; // object of CTradingEngine31 class
//---
#include <Controls\Dialog.mqh>
#include <Controls\Button.mqh>
//--- input parameters
input uint InpStopLoss = 35; // Stop Loss, in pips (1.00045-1.00055=1 pips)
input uint InpTakeProfit = 90; // Take Profit, in pips (1.00045-1.00055=1 pips)
input ushort InpTrailingFrequency = 10; // Trailing, in seconds (< "10" -> only on a new bar)
input uint InpTrailingStop = 15; // Trailing Stop (min distance from price to Stop Loss, in pips
input uint InpTrailingStep = 1; // Trailing Step, in pips (1.00045-1.00055=1 pips)
input ENUM_LOT_OR_RISK InpLotOrRisk = risk; // Money management: Lot OR Risk
input double InpVolumeLotOrRisk = 3.0; // The value for "Money management"
input ENUM_TRADE_MODE InpTradeMode = buy_sell; // Trade mode:
input ulong InpDeviation = 10; // Deviation, in points (1.00045-1.00055=10 points)
//---
input ENUM_TIMEFRAMES InpPeriod = PERIOD_H4; // Timeframe
input string InpLineMinName = "Min Previous Bar";// Line Min Previous Bar: Name
input string InpLineMaxName = "Max Previous Bar";// Line Max Previous Bar: Name
input color InpLineMinColor = clrHotPink; // Line Min Previous Bar: Color
input color InpLineMaxColor = clrCoral; // Line Max Previous Bar: Color
input ENUM_LINE_STYLE InpLineMinStyle = STYLE_DASH; // Line Min Previous Bar: Style
input ENUM_LINE_STYLE InpLineMaxStyle = STYLE_DASH; // Line Max Previous Bar: Style
input int InpLineMinWidth = 3; // Line Min Previous Bar: Width
input int InpLineMaxWidth = 3; // Line Max Previous Bar: Width
input bool InpLineMinBack = false; // Line Min Previous Bar: Background line
input bool InpLineMaxBack = false; // Line Max Previous Bar: Background line
input bool InpLineMinSelection = false; // Line Min Previous Bar: Highlight to move
input bool InpLineMaxSelection = false; // Line Max Previous Bar: Highlight to move
input bool InpLineMinHidden = true; // Line Min Previous Bar: Hidden in the object list
input bool InpLineMaxHidden = true; // Line Max Previous Bar: Hidden in the object list
input long InpLineMinZOrder = 0; // Line Min Previous Bar: Priority for mouse click
input long InpLineMaxZOrder = 0; // Line Max Previous Bar: Priority for mouse click
//---
input ushort InpPendingExpiration = 600; // Pending: Expiration, in minutes ('0' -> OFF)
input uint InpPendingIndent = 5; // Pending: Indent, in pips (1.00045-1.00055=1 pips)
input uint InpMaxSpread = 50; // Pending: Maximum spread, in points (1.00045-1.00055=10 points)
//---
input bool InpPrintLog = false; // Print log
input ulong InpMagic = 37429920; // Magic number
//+------------------------------------------------------------------+
//| defines |
//+------------------------------------------------------------------+
//--- indents and gaps
#define INDENT_LEFT (11) // indent from left (with allowance for border width)
#define INDENT_TOP (11) // indent from top (with allowance for border width)
#define CONTROLS_GAP_X (5) // gap by X coordinate
#define CONTROLS_GAP_Y (5) // gap by Y coordinate
//--- for buttons
#define BUTTON_WIDTH (60) // size by X coordinate
#define BUTTON_HEIGHT (20) // size by Y coordinate
//+------------------------------------------------------------------+
//| Class CControlsDialog |
//| Usage: main dialog of the Controls application |
//+------------------------------------------------------------------+
class CControlsDialog : public CAppDialog
{
private:
CButton m_button_place; // the button object
CButton m_button_delete; // the button object
public:
CControlsDialog(void);
~CControlsDialog(void);
//--- create
virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
//--- chart event handler
virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
protected:
//--- create dependent controls
bool CreateButtonPlace(void);
bool CreateButtonDelete(void);
//--- handlers of the dependent controls events
void OnClickButtonPlace(void);
void OnClickButtonDelete(void);
};
//+------------------------------------------------------------------+
//| Event Handling |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CControlsDialog)
ON_EVENT(ON_CLICK,m_button_place,OnClickButtonPlace)
ON_EVENT(ON_CLICK,m_button_delete,OnClickButtonDelete)
EVENT_MAP_END(CAppDialog)
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CControlsDialog::CControlsDialog(void)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CControlsDialog::~CControlsDialog(void)
{
}
//+------------------------------------------------------------------+
//| Create |
//+------------------------------------------------------------------+
bool CControlsDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
{
if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
return(false);
//--- create dependent controls
if(!CreateButtonPlace())
return(false);
if(!CreateButtonDelete())
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Button Place" buttom |
//+------------------------------------------------------------------+
bool CControlsDialog::CreateButtonPlace(void)
{
//--- coordinates
int x1=INDENT_LEFT;
int y1=INDENT_TOP;
int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- create
if(!m_button_place.Create(m_chart_id,m_name+"Button Place",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_button_place.Text("Place"))
return(false);
if(!Add(m_button_place))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Create the "Button Delete" buttom |
//+------------------------------------------------------------------+
bool CControlsDialog::CreateButtonDelete(void)
{
//--- coordinates
int x1=INDENT_LEFT+BUTTON_WIDTH+CONTROLS_GAP_X;
int y1=INDENT_TOP;
int x2=x1+BUTTON_WIDTH;
int y2=y1+BUTTON_HEIGHT;
//--- create
if(!m_button_delete.Create(m_chart_id,m_name+"Button Delete",m_subwin,x1,y1,x2,y2))
return(false);
if(!m_button_delete.Text("Delete"))
return(false);
if(!Add(m_button_delete))
return(false);
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButtonPlace(void)
{
m_trading_engine.Place();
}
//+------------------------------------------------------------------+
//| Event handler |
//+------------------------------------------------------------------+
void CControlsDialog::OnClickButtonDelete(void)
{
m_trading_engine.Delete();
}
//+------------------------------------------------------------------+
//| Global Variables |
//+------------------------------------------------------------------+
CControlsDialog ExtDialog;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
int init=m_trading_engine.OnInit(Symbol(),
InpStopLoss,
InpTakeProfit,
InpTrailingFrequency,
InpTrailingStop,
InpTrailingStep,
InpLotOrRisk,
InpVolumeLotOrRisk,
InpTradeMode,
InpDeviation,
InpPeriod,
InpLineMinName,
InpLineMaxName,
InpLineMinColor,
InpLineMaxColor,
InpLineMinStyle,
InpLineMaxStyle,
InpLineMinWidth,
InpLineMaxWidth,
InpLineMinBack,
InpLineMaxBack,
InpLineMinSelection,
InpLineMaxSelection,
InpLineMinHidden,
InpLineMaxHidden,
InpLineMinZOrder,
InpLineMaxZOrder,
InpPendingExpiration,
InpPendingIndent,
InpMaxSpread,
InpPrintLog,
InpMagic);
if(init!=INIT_SUCCEEDED)
return(init);
//--- create application dialog
if(!ExtDialog.Create(0,"Open Close Panel",0,40,90,225,160))
return(INIT_FAILED);
//--- run application
ExtDialog.Run();
//--- succeed
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
m_trading_engine.OnTick();
}
//+------------------------------------------------------------------+
//| TradeTransaction function |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
const MqlTradeRequest &request,
const MqlTradeResult &result)
{
//---
m_trading_engine.OnTradeTransaction(trans,request,result);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
m_trading_engine.OnDeinit(reason);
//--- destroy dialog
ExtDialog.Destroy(reason);
}
//+------------------------------------------------------------------+
//| Expert chart event function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, // event ID
const long& lparam, // event parameter of the long type
const double& dparam, // event parameter of the double type
const string& sparam) // event parameter of the string type
{
ExtDialog.ChartEvent(id,lparam,dparam,sparam);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---