Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1126

 

Hi all, Can you tell me please, I want to put a stop behind the low of a particular candle, but not more than a pre-defined number of pips. how do I do that?

I do the following: I take 4 candlesticks from the low of the last closed candlestick. If it is less than 200 pips, then stop at the low of 15 pips, and if it is more, then just stop at 200 pips. I cannot use it on the chart, I don't know how to place stops, if they are below 200 pips. I'm learning the language only recently. I replaced the last candle's clout with Ask, still

if(Close[1]-Low[4]>=NormalizeDouble(StopLoss*Point,5))
   sl = (Close[1] - NormalizeDouble(StopLoss*Point, 5));  //Рассчет стопа для покупок
else
   sl = Low[4]-NormalizeDouble(15*Point,5);
tp = NormalizeDouble(Ask + TakeProfit*Point, 5);  //Рассчет тейка для покупок);
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, sl, tp, "С1 БАЙ", Magic, 0, clrBlue);
return;
 
Nikolai_korzhok:

Hi all, Can you tell me please, I want to put a stop behind the low of a particular candle, but not more than a predetermined number of pips. how do I do that?

I do the following: I take 4 candlesticks from the low of the last closed candlestick. If it is less than 200 pips, then stop at the low of 15 pips, and if it is more, then just stop at 200 pips. I cannot use it on the chart, I don't know how to place stops, if they are lower than 200 pips. I'm learning the language only recently. I have changed the last candle's clause to Asc, it still leaves the same nonsense. Where am I making a mistake?

...

I would like to ask you to insert the correct code:


 
Artyom Trishkin:

Please insert the code correctly:



Done, first post on the forum is mine) sorry

 
Nikolai_korzhok:

Done, first post on the forum is mine) sorry

I'm also going to be a nuisance (not because I am, but so that people can read your code comfortably - you need help, not them):

there's a code styler in the editor. Press Ctrl+< and your code becomes readable.

Стилизатор - Разработка программ - Справка по MetaEditor
Стилизатор - Разработка программ - Справка по MetaEditor
  • www.metatrader5.com
Стилизатор позволяет быстро привести оформление исходного кода к рекомендуемому стандарту. Это делает код легко читаемым, выглядящем профессионально. Грамотно оформленный код гораздо проще читать и анализировать в последующем как его автору, так и другим пользователям. Чтобы запустить стилизатор, нажмите " Стилизатор" в меню "Сервис" или...
 
Artyom Trishkin:

I'm also going to say a few words (not because I'm like that, but so that people can read your code comfortably - you need help, not them):

There is a code styler in the editor. Press Ctrl+< and your code becomes readable.

Done, hope it's OK...
 
Artyom Trishkin:

In MQL5, the arrays are passed into the function by reference only - the appersand is required. And it's not important where it is located.

I see, thank you. Are arrays passed to the function in MQL4?

edit.

I've been thinking and got completely lost. Where can I read about declaration of variables and arrays and references to them?

The question that puzzled me was, why do we specify type of variable/array, if we use reference? When declaring an array and a variable, we are obliged to do so, aren't we?

 
Valeriy Yastremskiy:

I see, thank you. Are arrays passed into the function in MQL4?

double AverageFromArray(constdouble& array[],int size)

I found it, but why is it an array constant? I mean const arrays can be passed into a function in 4?

 
Nikolai_korzhok:

Hi all, Can you tell me please, I want to put a stop behind the low of a particular candle, but not more than a predetermined number of pips. how do I do that?

I do the following: I take 4 candlesticks from the low of the last closed candlestick. If it is less than 200 pips, then stop at the low of 15 pips, and if it is more, then just stop at 200 pips. I cannot use it on the chart, I don't know how to place stops, if they are below 200 pips. I'm learning the language only recently. I have changed the last candlestick's clause to Asc.

I tried to do it in the same way (as an example from the https://www.mql5.com/ru/forum/111497/page1100#comment_3077789 topic), but it works. It does not place the stop just behind the low.

if(NormalizeDouble(Ask-Low[4]+200*Point,5)>=0)
   sl = (Close[1] - NormalizeDouble(StopLoss*Point, 5));  //Расчет стопа для Покупок
else
   sl = NormalizeDouble(Low[4]-10*Point,5);
tp = NormalizeDouble(Ask + TakeProfit*Point, 5);  //Расчет тейка для продаж);
ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, sl, tp, "С1 БАЙ", Magic, 0, clrBlue);
return;
[ВНИМАНИЕ, ТЕМА ЗАКРЫТА!] Любой вопрос новичка, чтоб не захламлять форум. Профи, не проходите мимо. Без вас никуда.
[ВНИМАНИЕ, ТЕМА ЗАКРЫТА!] Любой вопрос новичка, чтоб не захламлять форум. Профи, не проходите мимо. Без вас никуда.
  • 2011.01.05
  • www.mql5.com
Здрасти, вот зарегился и решил сразу создать тему. Будет думаю правильно, так как у самого куча вопросов...
 

Good day, gentlemen.

Question about trailing stop, what is the right way to do it?

Usually trailing stop is used in the function, I heard somewhere that it is not to modify on every tick, otherwise the broker will ban me for too frequent requests.

I have looked how built-in trailing stop works, it has only one setting and modifies on every tick, (sometimes several times, with broker's scolding).

I looked at the commonly known tutorials, it's a mess:

Here, if SL is set to 0, it will be modified immediately.

What I've come up with looks like this:

Is this correct?

 
Please, someone will answer my request too: # 11237
Reason: