var58: Hello. Please advise how to prescribe in the code of MQL4 EA the rule of opening an order: there should be an order with a certain magic number in the market; if there is no such order, the EA does not open anything according to its main algorithm.
//Конечная точка ObjectCreate("#"+Ticket+" "+type+" "+DoubleToString(lots,2)+" "+symbol+" at "+DoubleToString(b,Digits)+" close at "+DoubleToString(d,Digits),OBJ_ARROW,0,c,d); ObjectSet("#"+Ticket+" "+type+" "+DoubleToString(lots,2)+" "+symbol+" at "+DoubleToString(b,Digits)+" close at "+DoubleToString(d,Digits),OBJPROP_COLOR,col); ObjectSet("#"+Ticket+" "+type+" "+DoubleToString(lots,2)+" "+symbol+" at "+DoubleToString(b,Digits)+" close at "+DoubleToString(d,Digits),OBJPROP_ARROWCODE,3);
Single trades the indicator draws correctly (line>background>profit), but in the display of closed order sets there is a small "bug" (screenshot attached), lines are superimposed on the background and profit (line(1)>background>profit>line(2)>line(3)>line(4) . . . . ).
It should be as follows: (line(1)>line(2)>line(3)>line(4) . . . >fon>profit). Various tampering has not been successful, please help me to fix it.
//------- Вернёт количество int IsCount(int type, int mg) { int p=0; for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==mg) { if(OrderType()==type) { p++; }}}} return(p); }
ORDER_TYPE_BUY_STOP is highlighted in MQL4 Editor, not in MQL4 Help. Question: Does it work in MQL4, does it correspond to OP_BUYSTOP type ? I just don't have time to check it yet.
Artyom Trishkin: ORDER_TYPE_BUY_STOP is highlighted in MQL4 Editor, but not in MQL4 Help. Question: does it work in MQL4, it corresponds to OP_BUYSTOP type ? I just don't have time to check it yet.
Yes, it works 100%, it's the only way I'm writing now. Now a lot of things have migrated from Five to Four.
Even this one works, though the compiler used to swear it was a trend line
Hello. Please advise how to prescribe in the code of MQL4 EA the rule of opening an order: there should be an order with a certain magic number in the market; if there is no such order, the EA does not open anything according to its main algorithm.
That's about as far as it goes:
{
Comment( IsCount(ORDER_TYPE_BUY_STOP, 5) ); // type - тип, mg - magic
}
//------- Вернёт количество
int IsCount(int type, int mg) {
int p=0;
for(int i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if(OrderSymbol()==Symbol() && OrderMagicNumber()==mg) {
if(OrderType()==type) {
p++;
}}}}
return(p);
}
How do I make it possible for a user to fill an array?
How do I make it possible for a user to populate an array?
Greetings, there is an indicator that draws the order history on the chart, code:
//| history.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
extern int MagicNumber = 1110;
extern datetime HistoryOrdersFromDateTime = 0;
extern color SellColor = clrRed;
extern color BuyColor = clrBlue;
extern color ProfitColor = clrWhite;
extern bool DeleteHistoryOrders = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
void start()
{
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() && OrderType()<=1)
{
if(HistoryOrdersFromDateTime<OrderCloseTime())
{
if((TimeCurrent()-OrderCloseTime())>60)
HistoryOrders();
}
}
}
}
void HistoryOrders()
{
int CountOrders=0;
double b=OrderOpenPrice(), d=OrderClosePrice(), lots=OrderLots(), Profit=0;
datetime a=OrderOpenTime(), c=OrderCloseTime(), close_time;
string Ticket=(string)OrderTicket(), type="Sell", symbol=OrderSymbol(), comment=OrderComment(), Background;
color col=SellColor;
if(OrderType()==0) {col=BuyColor; type="Buy";}
//Расчет профита
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol() && OrderType()<=1)
{
close_time=OrderCloseTime();
if(c<=close_time+60 && c>=close_time-60)
{
Profit+=OrderProfit()+OrderCommission()+OrderSwap();
Ticket=(string)OrderTicket();
}
}
}
//Размер фона
for(int i=2; i<StringLen(DoubleToString(Profit,2)); i++)
StringAdd(Background,"g");
if(DeleteHistoryOrders==false)
{
//Начальная точка
ObjectCreate("#"+Ticket+" "+type+" "+DoubleToString(lots,2)+" "+symbol+" at "+DoubleToString(b,Digits)+"\n"+comment,OBJ_ARROW,0,a,b);
ObjectSet("#"+Ticket+" "+type+" "+DoubleToString(lots,2)+" "+symbol+" at "+DoubleToString(b,Digits)+"\n"+comment,OBJPROP_COLOR,col);
ObjectSet("#"+Ticket+" "+type+" "+DoubleToString(lots,2)+" "+symbol+" at "+DoubleToString(b,Digits)+"\n"+comment,OBJPROP_ARROWCODE,1);
//Линия
ObjectCreate("#"+Ticket+" "+DoubleToString(b,Digits)+" -> "+DoubleToString(d,Digits),OBJ_TREND,0,a,b,c,d);
ObjectSet("#"+Ticket+" "+DoubleToString(b,Digits)+" -> "+DoubleToString(d,Digits),OBJPROP_COLOR,col);
ObjectSet("#"+Ticket+" "+DoubleToString(b,Digits)+" -> "+DoubleToString(d,Digits),OBJPROP_WIDTH,1);
ObjectSet("#"+Ticket+" "+DoubleToString(b,Digits)+" -> "+DoubleToString(d,Digits),OBJPROP_STYLE,STYLE_DOT);
ObjectSet("#"+Ticket+" "+DoubleToString(b,Digits)+" -> "+DoubleToString(d,Digits),OBJPROP_RAY,0);
//Конечная точка
ObjectCreate("#"+Ticket+" "+type+" "+DoubleToString(lots,2)+" "+symbol+" at "+DoubleToString(b,Digits)+" close at "+DoubleToString(d,Digits),OBJ_ARROW,0,c,d);
ObjectSet("#"+Ticket+" "+type+" "+DoubleToString(lots,2)+" "+symbol+" at "+DoubleToString(b,Digits)+" close at "+DoubleToString(d,Digits),OBJPROP_COLOR,col);
ObjectSet("#"+Ticket+" "+type+" "+DoubleToString(lots,2)+" "+symbol+" at "+DoubleToString(b,Digits)+" close at "+DoubleToString(d,Digits),OBJPROP_ARROWCODE,3);
//Фон профита
ObjectCreate("#"+Ticket+" Background",OBJ_TEXT,0,c,d);
ObjectSet("#"+Ticket+" Background",OBJPROP_ANCHOR,ANCHOR_LOWER);
ObjectSetText("#"+Ticket+" Background",Background,10,"Webdings",col);
ObjectSet("#"+Ticket+" Background",OBJPROP_PRICE1,d);
ObjectSet("#"+Ticket+" Background",OBJPROP_TIME1,c+Period());
//Профит
ObjectCreate("#"+Ticket+" Profit: "+DoubleToString(Profit,2),OBJ_TEXT,0,c,d);
ObjectSet("#"+Ticket+" Profit: "+DoubleToString(Profit,2),OBJPROP_ANCHOR,ANCHOR_LOWER);
ObjectSetText("#"+Ticket+" Profit: "+DoubleToString(Profit,2),DoubleToString(Profit,2),10,"Arial",ProfitColor);
ObjectSet("#"+Ticket+" Profit: "+DoubleToString(Profit,2),OBJPROP_PRICE1,d);
ObjectSet("#"+Ticket+" Profit: "+DoubleToString(Profit,2),OBJPROP_TIME1,c+Period());
} else ObjectsDeleteAll(0, "#"+Ticket+" ");
}
void OnDeinit(const int reason)
{
for(int i=0; i<OrdersHistoryTotal(); i++)
{
DeleteHistoryOrders=true;
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol())
HistoryOrders();
}
}
Single trades the indicator draws correctly (line>background>profit), but in the display of closed order sets there is a small "bug" (screenshot attached), lines are superimposed on the background and profit (line(1)>background>profit>line(2)>line(3)>line(4) . . . . ).
It should be as follows: (line(1)>line(2)>line(3)>line(4) . . . >fon>profit). Various tampering has not been successful, please help me to fix it.
Who else can fill it in except the user?
I mean how to fill it in via settings. Let's say through a string, and then put its value into an array...
I mean how to fill it in via settings. Let's say through a string, and then put its value into an array...
That's about as far as it goes:
{
Comment( IsCount(ORDER_TYPE_BUY_STOP, 5) ); // type - тип, mg - magic
}
//------- Вернёт количество
int IsCount(int type, int mg) {
int p=0;
for(int i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if(OrderSymbol()==Symbol() && OrderMagicNumber()==mg) {
if(OrderType()==type) {
p++;
}}}}
return(p);
}
That's about as far as it goes:
void OnTick()
{
Comment( IsCount(ORDER_TYPE_BUY_STOP, 5) ); // type - тип, mg - magic
}
//------- Вернёт количество
int IsCount(int type, int mg) {
int p=0;
for(int i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if(OrderSymbol()==Symbol() && OrderMagicNumber()==mg) {
if(OrderType()==type) {
p++;
}}}}
return(p);
}
Примерно так можно:
{
Comment( IsCount(ORDER_TYPE_BUY_STOP, 5) ); // type - тип, mg - magic
}
//------- Вернёт количество
int IsCount(int type, int mg) {
int p=0;
for(int i=0; i<OrdersTotal(); i++) {
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if(OrderSymbol()==Symbol() && OrderMagicNumber()==mg) {
if(OrderType()==type) {
p++;
}}}}
return(p);
}
Спасибо большое, попробую.
It's kind of like this.
Thank you!
ORDER_TYPE_BUY_STOP is highlighted in MQL4 Editor, but not in MQL4 Help. Question: does it work in MQL4, it corresponds to OP_BUYSTOP type ? I just don't have time to check it yet.
Yes, it works 100%, it's the only way I'm writing now. Now a lot of things have migrated from Five to Four.
Even this one works, though the compiler used to swear it was a trend line
ObjectSetDouble(chart_ID,nm,OBJPROP_PRICE,p1);
ObjectSetInteger(chart_ID,nm,OBJPROP_TIME,1,t2);
ObjectSetDouble(chart_ID,nm,OBJPROP_PRICE,1,p2);