Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 101
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
It is not clear. If it is necessary to stop the EA, then the suggested variant copes with this, if there is no need to stop it, then let it trade and do not limit it in any way. If we want to trade on demand after the stop, it is enough to switch the time, Disabled will become true and the program will continue to work
Ok, thanks.
You probably want to have the choice of specifying in the input parameters: "Trade after close, or don't trade after close"?
If so, then here you go:
// OnTick
if(OneTrade && !Disabled) return;
I didn't mess up with the flag.
You probably want to have the choice of specifying in the input parameters: "Trade after close, or don't trade after close"?
If so, then here you go:
// OnTick
if(OneTrade && !Disabled) return;
I don't seem to have done anything wrong with the flag
Thank you!
The question is: How correct is this entry, it is at the beginning of the program, while throughout the program a lot of Time[0] and Time[1] are used, and not to be called every time, it is written in a variable. There seems to be no errors outside the array, but everything is superficially defined:
//------------
void OnTimer()
ArraySetAsSeries(TM, true);
if(CopyTime(_Symbol, PERIOD_CURRENT, 0, 2, TM)==-1) return;
TIME0 = TM[0];
TIME1 = TM[1];
Thanks!
can I ask you to adjust it a bit?
Put a vertical line at the current price
or a link to an EA where this is available
I want to understand how to distribute the parameters of the bot to make it work
can I ask you to adjust it a bit?
Put a vertical line at the current price
or a link to an EA where this is available
I want to understand how to distribute the parameters of the bot to make it work
First you have to rotate the quote display by 90 degrees.
Post 998.
I don't care if it's horizontal or vertical, it's just that right now what I did there doesn't work
Post 998.
I don't care if it's horizontal or vertical, it's just that what I've done there now doesn't work
// Функцию - за пределы остальных функций программы
//+------------------------------------------------------------------+
//| Трейлинг по значению + перенос стопа на уровень безубытка |
//+------------------------------------------------------------------+
void TrailingByLevel(string symbol_name, // Имя символа
int magic_number, // Magic ордера
double level_of_trail, // Уровень, на который ставим стоп (например МА или Parabolic SAR)
int trailing_start, // Профит в пунктах для старта трала
int trailing_step, // Шаг трала в пунктах
int trailing_stop, // Отступ стоплосс от уровня МА или SAR в пунктах
int profit_for_breakeven=15, // Профит в пунктах для переноса стопа в безубыток
int breakeven_level=5, // Уровень безубытка в пунктах
bool use_trail=true, // Флаг использования трала
bool use_breakeven=false // Флаг использования безубытка
)
{
int lv=StopLevel(symbol_name)+1; // Получаем значение Stop Level по символу + 1 пункт (из отдельной функции)
for(int i=OrdersTotal()-1; i>=0; i--) {
if(OrderSelect(i,SELECT_BY_POS)) {
if(OrderMagicNumber()!=magic_number) continue; //Если Магик не наш - идем к следующему ордеру
if(OrderSymbol()!=symbol_name) continue; //Если Символ не наш - идем к следующему ордеру
//--- покупки
if(OrderType()==OP_BUY) {
int digits=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
double point=(SymbolInfoDouble(symbol_name,SYMBOL_POINT));
double pb=SymbolInfoDouble(symbol_name,SYMBOL_BID);
double profit=pb-OrderOpenPrice(); // Профит позиции в цене (без комиссий и свопов)
//--- безубыток
if(use_breakeven) {
//--- если профит в цене больше заданного
if(profit>=profit_for_breakeven*point) {
int err=ERR_NO_ERROR;
double sl=NormalizeDouble(OrderOpenPrice()+breakeven_level*point,digits);
if(pb-lv*point>sl && OrderStopLoss()<sl) {
// Сюда вписываем свою функцию модификации. Можно конечно и стандартной обойтись:
// OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration(),clrModify); ...
// ... но в ней не предусмотрены проверки кодов возврата торгового сервера и их обработка
//ModifyOrder(-1,sl,-1,err);
}
if(err==ERR_MARKET_CLOSED) return;
}
}
//--- трал
if(use_trail) {
//--- если профит в пунктах больше заданного, или изначально задан меньше ноля
if(profit>=trailing_start*point || trailing_start==EMPTY) {
int err=ERR_NO_ERROR;
double sl=NormalizeDouble(level_of_trail-trailing_stop*point,digits); // вычисляем новый уровень стоплосс по значению, переданному в функцию
//--- Если новое значение СЛ не ближе Stop Level и если новое положение СЛ больше старого+шаг СЛ, то модифицируем стоп позиции
if(pb-lv*point>sl && OrderStopLoss()+trailing_step*point<sl) {
// Сюда вписываем свою функцию модификации. Можно конечно и стандартной обойтись:
// OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration(),clrModify); ...
// ... но в ней не предусмотрены проверки кодов возврата торгового сервера и их обработка
//ModifyOrder(-1,sl,-1,err);
}
if(err==ERR_MARKET_CLOSED) return;
}
}
}
//--- Продажи
if(OrderType()==OP_SELL) {
int digits=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
double point=(SymbolInfoDouble(symbol_name,SYMBOL_POINT));
double pa=SymbolInfoDouble(symbol_name,SYMBOL_ASK);
double profit=OrderOpenPrice()-pa; // Профит позиции в цене (без комиссий и свопов)
//--- безубыток
if(use_breakeven) {
//--- если профит в цене больше заданного
if(profit>=profit_for_breakeven*point) {
int err=ERR_NO_ERROR;
double sl=NormalizeDouble(OrderOpenPrice()-breakeven_level*point,digits);
if(pa+lv*point<sl && (OrderStopLoss()>sl || OrderStopLoss()==0)) {
// Сюда вписываем свою функцию модификации. Можно конечно и стандартной обойтись:
// OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration(),clrModify); ...
// ... но в ней не предусмотрены проверки кодов возврата торгового сервера и их обработка
//ModifyOrder(-1,sl,-1,err);
}
if(err==ERR_MARKET_CLOSED) break;
}
}
//--- трал
if(use_trail) {
//--- если профит в пунктах больше заданного, или изначально задан меньше ноля
if(profit>=trailing_start*point || trailing_start==EMPTY) {
int err=ERR_NO_ERROR;
double sl=NormalizeDouble(level_of_trail+trailing_stop*point,digits); // вычисляем новый уровень стоплосс по значению, переданному в функцию
//--- Если новое значение СЛ не ближе Stop Level и если новое положение СЛ больше старого+шаг СЛ, то модифицируем стоп позиции
if(pa+lv*point<sl && (OrderStopLoss()-trailing_step*point>sl || OrderStopLoss()==0)) {
// Сюда вписываем свою функцию модификации. Можно конечно и стандартной обойтись:
// OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration(),clrModify); ...
// ... но в ней не предусмотрены проверки кодов возврата торгового сервера и их обработка
//ModifyOrder(-1,sl,-1,err);
}
if(err==ERR_MARKET_CLOSED) break;
}
}
}
}
}
}
//+------------------------------------------------------------------+
int StopLevel(string symbol_name) {
int sp=(int)SymbolInfoInteger(symbol_name,SYMBOL_SPREAD);
int lv=(int)SymbolInfoInteger(symbol_name,SYMBOL_TRADE_STOPS_LEVEL);
return((lv==0)?sp*2:lv);
}
//+------------------------------------------------------------------+
I've noticed that people often ask for a trawl or break-even function. I've created a blueprint function for moving a stop to a given breakeven level and trailing a stop position by the value of some indicator, which draws its lines on the price chart (MA or parabolic, for example), passed into the function.
In general, if anything - ask. Or correct