Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 91
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
You have to sort by price, because you can't search by size, the grid may be different, and you will find either the biggest or the smallest, but not the first and not the last
I mean the function that Marina posted.
The last order is determined by time.
I mean the function that Marina posted.
The last order is determined by time.
Because I summon it this way
Dear programmers! Help me solve this question. The Expert Advisor enters a trade on M15, but takes conditions from H1 as well. When conditions on H1 are fulfilled on M15 there may be several entry points. Actually the problem is that I want to use only the first entry point, until the conditions on H1 are reversed.
k=0;
for (i=OrdersTotal()-1;i>=0;i--)
{
RefreshRates();
if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) a = 0;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) k++;
}
if( stM1 <= 20 && stM0 > 20 && stH0 > 70 && k==0 && opp != Time[0]) // purchase
Dear programmers! Help me solve this question. The Expert Advisor enters a trade on M15, but takes conditions from H1 as well. When conditions on H1 are fulfilled on M15 there may be several entry points. Actually the problem is that I want to limit the first entry point, until the conditions on H1 are not changed to the opposite.
k=0;
for (i=OrdersTotal()-1;i>=0;i--)
{
RefreshRates();
if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) a = 0;
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) k++;
}
if( stM1 <= 20 && stM0 > 20 && stH0 > 70 && k==0 && opp != Time[0]) // purchase
But what about without the code? Especially, the code is not clear.
What exactly do you want? Not in the abstract, but exactly what you want to get.
Dear programmers! Help me solve this question. The Expert Advisor enters a trade on M15, but takes conditions from H1 as well. When conditions on H1 are fulfilled on M15 there may be several entry points. Actually the problem is that I want to limit myself to the first entry point, while on H1 the conditions do not change to the opposite.
k=0;
for (i=OrdersTotal()-1;i>=0;i--)
{
RefreshRates();
if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) a = 0;
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) k++;
}
if( stM1 <= 20 && stM0 > 20 && stH0 > 70 && k==0 && opp != Time[0]) // purchase
An approximate algorithm:
bool flagH1 = true;
bool flagM15 = true;
if(!flag && flagH1 && flagM15)
{
flag = true;
}
if(!flagH1 && flag)
flag = false;
And without the code? All the more reason not to understand the code.
What exactly do you want? Not in the abstract, but exactly what you want to get.
extern double Lot= 0.1;
extern int stoploss=20;
extern int takeprofit=50;
// если stoploss и / или takeprofit = 0, то отключены.
//if stoploss and/or takeprofit = 0, are disconnected.
extern int Magic = 99999999;
// уникальный номер, кот. советник метит свои ордера и впоследствии работает только с ними. При постановке на разные графики или т/ф, межики должны быть разными
extern int Slipp = 1;
// величина максимально возможного проскальзывания.
// slippage
extern int sec = 2000;
// количество миллисекунд сна советника между повторами отправки торгового поручения в случае неудачи
// number of milliseconds sleep of the EA between repetitions of sending a trade assignment in case of failure
//============================= Stochastic
input int InpKPeriod=13; // K Period
input int InpDPeriod=3; // D Period
input int InpSlowing=3; // Slowing
//============================= Stochastic
input int InpKPeriod1=13; // K Period
input int InpDPeriod1=3; // D Period
input int InpSlowing1=3; // Slowing
int A, a, b, i, ii, o;
double SL, TP, op, stH0, stH1, stM0, stM1;
bool c;
datetime OldTime, Time0, opp;
int init()
{
OldTime = iTime(NULL,Period(),0);
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//====================================================================
stH0 = iStochastic(NULL,60,InpKPeriod,InpDPeriod,InpSlowing,MODE_EMA,1,MODE_MAIN,0);
stH1 = iStochastic(NULL,60,InpKPeriod,InpDPeriod,InpSlowing,MODE_EMA,1,MODE_MAIN,1);
stM0 = iStochastic(NULL,15,InpKPeriod1,InpDPeriod1,InpSlowing1,MODE_EMA,1,MODE_MAIN,0);
stM1 = iStochastic(NULL,15,InpKPeriod1,InpDPeriod1,InpSlowing1,MODE_EMA,1,MODE_MAIN,1);
//====================================================================
b=0;
for (i=OrdersTotal()-1;i>=0;i--)
{
RefreshRates();
if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) a = 0;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) b++;
}
if( stM1 <= 20 && stM0 > 20 && stH0 > 70 && b==0 && opp != Time[0]) // покупка
{
opp = Time[0];
RefreshRates();
op = Ask;
A = OrderSend (Symbol(), OP_BUY, Lot, Ask, Slipp, 0, 0, NULL, Magic, 0, Blue);
o = GetLastError();
while (A < 0 && o != 4109 && o != 132 && o != 133)
{
Print("Error =", o);
Sleep(sec);
RefreshRates();
op = Ask;
A = OrderSend (Symbol(), OP_BUY, Lot, Ask, Slipp, 0, 0, NULL, Magic, 0, Blue);
o = GetLastError();
}
SL = op-stoploss*Point;
if (stoploss == 0) SL = 0;
TP = op+takeprofit*Point;
if (takeprofit == 0 ) TP = 0;
if (SL != 0 || TP != 0)
{
RefreshRates();
if(OrderSelect (A, SELECT_BY_TICKET) == true) a = 0;
c = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Green);
o = GetLastError();
while (c == false && o != 4109 && o != 132 && o != 133)
{
Print("Error =", o);
Sleep(sec);
RefreshRates();
if(OrderSelect (A, SELECT_BY_TICKET) == true) a = 0;
c = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Green);
o = GetLastError();
} }
}
//---------------------------------------------------------------------------------------------------------+
b=0;
for (i=OrdersTotal()-1;i>=0;i--)
{
RefreshRates();
if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) a = 0;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) b++;
}
if( stM1 >= 80 && stM0 < 80 && stH0 < 30 && b==0 && opp != Time[0]) // продажа
{
opp = Time[0];
RefreshRates();
op = Bid;
A = OrderSend (Symbol(), OP_SELL, Lot, Bid, Slipp, 0, 0, NULL, Magic, 0, Red);
o = GetLastError();
while (A < 0 && o != 4109 && o != 132 && o != 133)
{
Print("Error =", o);
Sleep(sec);
RefreshRates();
op = Bid;
A = OrderSend (Symbol(), OP_SELL, Lot, Bid, Slipp, 0, 0, NULL, Magic, 0, Red);
o = GetLastError();
}
SL = op+stoploss*Point;
if (stoploss == 0) SL = 0;
TP = op-takeprofit*Point;
if (takeprofit == 0 ) TP = 0;
if (SL != 0 || TP != 0)
{
RefreshRates();
if(OrderSelect (A, SELECT_BY_TICKET) == true) a = 0;
c = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Green);
o = GetLastError();
while (c == false && o != 4109 && o != 132 && o != 133)
{
Print("Error =", o);
Sleep(sec);
RefreshRates();
if(OrderSelect (A, SELECT_BY_TICKET) == true) a = 0;
c = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Green);
o = GetLastError();
} }
}
return(0);
}
//+------------------------------------------------------------------+
Artyom hello! The goal is to limit the entry on M15 to one (first signal) as long as there is a signal on H1.
Hello, dear forum members. Is there any way to set the value of the trailing stop built into Metatrader4 from within the EA? I am interested in this and not in adding to the Expert Advisor the code for the execution of a trailing stop which is independent of the built-in trailing stop.
Thanks in advance for the answers.
Hello, dear forum members. Is there any way to set the value of the trailing stop built into Metatrader4 from within the EA? I am interested in this and not in adding to the EA a code for the execution of a trailing stop which is independent of the built-in trailing stop.
Thanks in advance for the answers.