Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 126
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Can you tell me more about the signal, is it by MT or a third party?
Thanks for the help, fixed it.
Can autotrading be disabled/stopped on the entire terminal or on an individual EA, for example, according to a certain indicator's data?
You can use global variables of the terminal, prescribe the same GP for all of them and monitor the value, for example, when it is 0 - all EAs do not trade.
Also, you can use WinAPI to find auto-trading button on the terminal panel and press it.
Hello, is there any code to display text on a chart (sticker, reminder) that doesn't move along with the chart but is fixed? Thank you!
Thanks in advance!
extern double Lots = 0.1;
extern double Profit = 50;
extern int Step = 30;
extern int Magic = 6677;
extern int Slippage = 5;
extern int maPeriod =100;
extern int maShift =1;
double ma, FindLastBuyPrice, price;
//------------------------------------------------------------------
//___ПРОВЕРКА_ЗНАКОВ_ПОСЛЕ_ТОЧКИ___
//------------------------------------------------------------------
int OnInit()
{
if (Digits == 3 || Digits == 5)
{
Step *= 10;
Slippage *= 10;
}
return(INIT_SUCCEEDED);
}
//---------------------------------------------
void OnDeinit(const int reason)
{
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
void OnTick()
{
ma = iMA(Symbol(),0,maPeriod, maShift, MODE_SMA, PRICE_CLOSE, 0);
if (CountBuy() && CountSell() == 0 && Bid < ma)//
{
if (OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "", Magic, 0, Red) < 1)
Print ("Неудалось открыть ордер на Продажу");
}
if (CountBuy() && CountSell() == 0 && Ask < ma)
{
if (OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "", Magic, 0, Blue) < 1)
Print ("Неудалось открыть ордер на Покупку");
}
if (CountBuy() >=1)
{
price = FindLastBuyPrice();
if ((price - Ask) >= Step*Point)
{
if (OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "", Magic, 0, Blue) < 1)
Print ("Неудалось открыть ордер на Покупку");
}
}
if (CountSell() >=1)
{
price = FindLastBuyPrice();
if ((Bid - price) >= Step*Point)
{
if (OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "", Magic, 0, Red) < 1)
Print ("Неудалось открыть ордер на Ппродажу");
}
}
double op = CalculateProfit();
if (op >= Profit)
{
CloseAll();
}
}
//------------------------------------------------------------------
void CloseAll()
{
for (int i = OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if (OrderType() == OP_BUY)
{
if (!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage))
{
Print ("Не удалось закрыть ордер на ПОКУПКУ");
}
}
if (OrderType() == OP_SELL)
{
if (!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage))
{
Print ("Не удалось закрыть ордер на ПРОДАЖУ");
}
}
}
}
}
}
//------------------------------------------------------------------
double CalculateProfit() // Считаем профит по всем ордерам
{
double oProfit = 0;
for (int i=OrdersTotal() -1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if (OrderType() == OP_BUY || OrderType() == OP_SELL)
{
oProfit += OrderProfit();
}
}
}
}
return(oProfit);
}
//------------------------------------------------------------------
double FindLastBuyPrice()
{
int oldTicket, ticket = 0;
double oldopenPrice = 0;
for (int cnt = OrdersTotal()-1; cnt>=0; cnt--)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() ==Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
{
oldTicket = OrderTicket();
if (oldTicket > ticket)
{
ticket = oldTicket;
oldopenPrice = OrderOpenPrice();
}
}
}
}
return(oldopenPrice);
}
double FindLastSellPrice()
{
int oldTicket, ticket = 0;
double oldopenPrice = 0;
for (int cnt = OrdersTotal()-1; cnt>=0; cnt--)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() ==Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
{
oldTicket = OrderTicket();
if (oldTicket > ticket)
{
ticket = oldTicket;
oldopenPrice = OrderOpenPrice();
}
}
}
}
return(oldopenPrice);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int CountBuy()
{
int count = 0;
for (int trade = OrdersTotal()-1; trade >=0; trade--)
{
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES) == true)
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
int CountSell()
{
int count = 0;
for (int trade = OrdersTotal()-1; trade >=0; trade--)
{
if (OrderSelect(trade, SELECT_BY_POS, MODE_TRADES) == true)
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
Hi all. Here is a question:
I have an indicator with library and I need to write an Expert Advisor for it.
What scheme of actions is necessary to avoid multiplication of files, and there should be two or one as a result. I want to use both of them.
Hi all. Here is a question:
I have an indicator with library and I need to write an Expert Advisor for it.
What scheme of actions is necessary to avoid multiplication of files, and there should be two or one as a result. Ideally, they should be combined.
Work with custom indicators connected as resources
For the work of mql4-programs you may need one or more custom indicators, all of them can be included in the code of executable mql4-program. Inclusion of indicators as resources allows to simplify program distribution.