Last active
December 1, 2022 15:54
-
-
Save si294r/20d564612fa5eb25a4a3bcc0203e3ddb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+------------------------------------------------------------------+ | |
//| OrderSideways.mq5 | | |
//| Copyright 2009-2017, MetaQuotes Software Corp. | | |
//| http://www.mql5.com | | |
//+------------------------------------------------------------------+ | |
#property copyright "2009-2017, MetaQuotes Software Corp." | |
#property link "http://www.mql5.com" | |
//--- | |
#include <Trade\OrderInfo.mqh> | |
#include <Trade\Trade.mqh> | |
#include <ChartObjects\ChartObjectsTxtControls.mqh> | |
//--- | |
//+------------------------------------------------------------------+ | |
//| Script to testing the use of class COrderInfo. | | |
//+------------------------------------------------------------------+ | |
//--- | |
//+------------------------------------------------------------------+ | |
//| Order Sideways script class | | |
//+------------------------------------------------------------------+ | |
class COrderSideways | |
{ | |
protected: | |
COrderInfo m_order; | |
//--- chart objects | |
CChartObjectLabel m_label[7]; | |
CChartObjectLabel m_label_info[7]; | |
//--- | |
public: | |
COrderSideways(void); | |
~COrderSideways(void); | |
//--- | |
bool Init(void); | |
void Deinit(void); | |
void Processing(void); | |
void OpenAllPendingOrder(void); | |
private: | |
string init_str[7]; | |
void InfoToChart(void); | |
void OpenPendingOrder(ENUM_ORDER_TYPE type, double volume, double price, double sl, double tp); | |
}; | |
//--- | |
COrderSideways ExtScript; | |
//+------------------------------------------------------------------+ | |
//| Constructor | | |
//+------------------------------------------------------------------+ | |
COrderSideways::COrderSideways(void) | |
{ | |
} | |
//+------------------------------------------------------------------+ | |
//| Destructor | | |
//+------------------------------------------------------------------+ | |
COrderSideways::~COrderSideways(void) | |
{ | |
} | |
//+------------------------------------------------------------------+ | |
//| Method Init. | | |
//+------------------------------------------------------------------+ | |
bool COrderSideways::Init(void) | |
{ | |
int i,sy=10; | |
int dy=20; | |
color color_label; | |
color color_info; | |
//--- tuning colors | |
color_info =(color)(ChartGetInteger(0,CHART_COLOR_BACKGROUND)^0xFFFFFF); | |
color_label=(color)(color_info^0x202020); | |
//--- | |
if(ChartGetInteger(0,CHART_SHOW_OHLC)) | |
sy+=16; | |
//--- | |
sy+=20; | |
//--- creation Labels[] | |
init_str[0] = "Sell 3"; | |
init_str[1] = "Sell 2"; | |
init_str[2] = "Sell 1"; | |
init_str[3] = "Open"; | |
init_str[4] = "Buy 1"; | |
init_str[5] = "Buy 2"; | |
init_str[6] = "Buy 3"; | |
for(i=0;i<7;i++) | |
{ | |
m_label[i].Create(0,"Label"+IntegerToString(i),0,20,sy+dy*i); | |
m_label[i].Description(init_str[i]); | |
m_label[i].Color(color_label); | |
m_label[i].FontSize(12); | |
//--- | |
m_label_info[i].Create(0,"LabelInfo"+IntegerToString(i),0,80,sy+dy*i); | |
m_label_info[i].Description(" "); | |
m_label_info[i].Color(color_info); | |
m_label_info[i].FontSize(12); | |
} | |
InfoToChart(); | |
//--- redraw chart | |
ChartRedraw(); | |
//--- | |
return(true); | |
} | |
//+------------------------------------------------------------------+ | |
//| Method Deinit. | | |
//+------------------------------------------------------------------+ | |
void COrderSideways::Deinit(void) | |
{ | |
} | |
//+------------------------------------------------------------------+ | |
//| Method Processing. | | |
//+------------------------------------------------------------------+ | |
void COrderSideways::Processing(void) | |
{ | |
InfoToChart(); | |
//--- redraw chart | |
ChartRedraw(); | |
Sleep(250); | |
} | |
//+------------------------------------------------------------------+ | |
//| Method InfoToChart. | | |
//+------------------------------------------------------------------+ | |
void COrderSideways::InfoToChart(void) | |
{ | |
double open = iOpen("XAUUSD",PERIOD_D1,0); | |
double buy_1 = open - 7; | |
double buy_2 = open - 14; | |
double buy_3 = open - 24; | |
double sell_1 = open + 8; | |
double sell_2 = open + 15; | |
double sell_3 = open + 25; | |
m_label_info[0].Description(DoubleToString(sell_3, 2)); | |
m_label_info[1].Description(DoubleToString(sell_2, 2)); | |
m_label_info[2].Description(DoubleToString(sell_1, 2)); | |
m_label_info[3].Description(DoubleToString(open, 2)); | |
m_label_info[4].Description(DoubleToString(buy_1, 2)); | |
m_label_info[5].Description(DoubleToString(buy_2, 2)); | |
m_label_info[6].Description(DoubleToString(buy_3, 2)); | |
} | |
//+------------------------------------------------------------------+ | |
//| Method OpenAllPendingOrder | | |
//+------------------------------------------------------------------+ | |
void COrderSideways::OpenAllPendingOrder(void) | |
{ | |
double open = iOpen("XAUUSD",PERIOD_D1,0); | |
double buy_1 = open - 7; | |
double buy_2 = open - 14; | |
double buy_3 = open - 24; | |
double sell_1 = open + 8; | |
double sell_2 = open + 15; | |
double sell_3 = open + 25; | |
OpenPendingOrder(ORDER_TYPE_BUY_LIMIT, 0.1, buy_1, open - 35, buy_1 + 5.1); | |
OpenPendingOrder(ORDER_TYPE_BUY_LIMIT, 0.2, buy_2, open - 35, buy_2 + 5.2); | |
OpenPendingOrder(ORDER_TYPE_BUY_LIMIT, 0.5, buy_3, open - 35, buy_3 + 5.3); | |
OpenPendingOrder(ORDER_TYPE_SELL_LIMIT, 0.1, sell_1, open + 35, sell_1 - 5.1); | |
OpenPendingOrder(ORDER_TYPE_SELL_LIMIT, 0.2, sell_2, open + 35, sell_2 - 5.2); | |
OpenPendingOrder(ORDER_TYPE_SELL_LIMIT, 0.5, sell_3, open + 35, sell_3 - 5.3); | |
} | |
//+------------------------------------------------------------------+ | |
//| Method OpenPendingOrder | | |
//+------------------------------------------------------------------+ | |
void COrderSideways::OpenPendingOrder(ENUM_ORDER_TYPE type, double volume, double price, double sl, double tp) | |
{ | |
MqlTradeRequest request={}; | |
MqlTradeResult result={}; | |
request.action = TRADE_ACTION_PENDING; | |
request.type = type; | |
request.symbol = "XAUUSD"; | |
request.volume = volume; | |
request.price = price; | |
request.sl = sl; | |
request.tp = tp; | |
request.magic = 0; | |
if (!OrderSend(request, result)) { | |
PrintFormat("OrderSend Error %d", GetLastError()); | |
} else { | |
PrintFormat("retCode=%u; deal=%I64u; order=%I64u", result.retcode, result.deal, result.order); | |
} | |
Sleep(250); | |
} | |
//+------------------------------------------------------------------+ | |
//| Script program start function | | |
//+------------------------------------------------------------------+ | |
int OnStart(void) | |
{ | |
//--- call init function | |
if(ExtScript.Init()) | |
{ | |
ExtScript.OpenAllPendingOrder(); | |
//--- cycle until the script is not halted | |
while(!IsStopped()) | |
ExtScript.Processing(); | |
} | |
//--- call deinit function | |
//ExtScript.Deinit(); | |
//--- | |
return(0); | |
} | |
//+------------------------------------------------------------------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment