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

 
jarikn:
Thank you. I'll look into it.

And thank you, you reminded me of an old system that used to work in profit. I need to make a note of it at my leisure and test it in the current market.

 
jarikn:
Hi all. I am new to programming.
I wrote a simple Expert Advisor and now I need to add the following condition to it.
If a stop loss is triggered by a Buy order, then we open a Sell order.
Please help with this code

More options:

1. When opening Buy, put SellStop order at the level of stop loss of Buy order. Then your wish will be fulfilled by the server. But in exceptionally rare but accurate situations and not :-)

2. Not to put Stop Loss at all, and put SellStop of double volume. This will also be processed by the server quickly. At the end of the day or when the margin is depleted, you need to run some UnLock, which closes opposite orders mutually (CloseBy).

However, there is another nuance - stop orders (and stop loss, too) may not work. And this is quite often.
That is, in a "combat" robot, we still have to double-check it.
Общие принципы - Торговые операции - Справка по MetaTrader 5
Общие принципы - Торговые операции - Справка по MetaTrader 5
  • www.metatrader5.com
Перед тем как приступить к изучению торговых функций платформы, необходимо создать четкое представление об основных терминах: ордер, сделка и позиция. — это распоряжение брокерской компании купить или продать финансовый инструмент. Различают два основных типа ордеров: рыночный и отложенный. Помимо них существуют специальные ордера Тейк Профит...
 
Vladimir Simakov:

He writes that you cannot initialize a wchar_t entity with a const char* value

If you don't understand it, unfortunately, you don't have the basics of the language. It's too early for you to write a dll, especially for such a specific language as mql. Start with the basics.

I do not know what they advise you to do. There will never be a good time for this moment of learning libraries either now or never.

 
Maxim Kuznetsov:

2. do not put a stop loss at all, but put a SellStop of double volume. This will also be handled by the server and quickly. At the end of the day or when the margin is depleted, you need to run some UnLock, which closes opposite orders mutually (CloseBy).

We should be more careful with CloseBy as not all brokerage companies support this feature.

 
I'm not a programmer, so I can't solve the simplest question: how to bind zero bar to time, minutes :00, hours 00:,01:,02: etc. Can someone give me a hint?
 
Creativ:
I'm not a programmer, so I can't solve the simplest question: how to bind zero bar to time, minutes :00, hours 00:,01:,02: etc. Can someone suggest it?

There is a function for this.

iTime(символ,таймфрейм, номер бара)

It returns the bar time.

 

Hi all. Guys, please help. i am new to programming.
How to achieve this in MQL4 code.
For example, I will press button A and a cursor <Screenshot_2> will appear on a chart like this.
On the Draw Rectangle <Screenshot_1> there is no hotkey.How to get this function.

Screenshot_1

Screenshot_1

Screenshot_2.

Screenshot_2

Thank you.

 
guys, help me out with the Expert Advisor, please. i'm sick of.... I can't seem to fix it, it has only errors.
Here's the bottom line.
It works on the Tma fair indicator.
1) As soon as the price is above the upper line - open a sell order, the price is below the lower line - open a buy order.
I did it all, but the thing is,
2) As soon as I triggered a stop loss an order opens the same order! How can I fix this bug?
3) The order is not closed when the price crosses the opposite line! It seems to work, but it won't. It closes at stop loss or take profit.

I would also like to add a condition: if a Stop Loss has triggered for buy, open a Sell order. I think I can handle it myself. Just help me fix these errors.
I do not know what to do with it. I think I should do it myself.)
Files:
777.mq4  10 kb
TMA_Fair.mq4  9 kb
 

Please help with the buy-sell switch, I'm just learning!

void OnTick()

{

MAprice=iMA(Symbol(),0,MAperiod,MAshift,MODE_SMA,PRICE_CLOSE,1);

if(CountBuy() + CountSell() == 0 && Ask > MAprice)

{

if(OrderSend(Symbol(),OP_BUY,lot,Ask,slip,0,0,NULL,magic,0,clrBlue)<1)

Print("Failed to open a Buy order!");

if(CountBuy()>=1)

{

price = FindLastBuyPrice();

if((price - Ask) >= step*Point)

{

if(OrderSend(Symbol(),OP_BUY,lot,Ask,slip,0,0,NULL,magic,0,clrBlue)<1)

Print("Failed to open a Buy order!)

}

}

if(CountBuy() + CountSell() == 0 && Bid < MAprice)

{

if(OrderSend(Symbol(),OP_SELL,lot,Bid,slip,0,0,NULL,magic,0,clrRed)<1)

Print("Failed to open Sell order!)

}

}

if(CountSell()>=1)

{

price = FindLastSellPrice();

if((price -Bid) >= step*Point)

{

if(OrderSend(Symbol(),OP_SELL,lot,Bid,slip,0,0,NULL,magic,0,clrRed)<1)

Print("Failed to open Sell order!");

}

}

double op = CalculateProfit();

if(op>=profit)

{

CloseAll();

}

}


//+------------------------------------------------------------------+

void CloseAll()


or where to learn?

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Приказы на проведение торговых операций оформляются ордерами. Каждый ордер имеет множество свойств для чтения, информацию по ним можно получать с помощью функций Идентификатор позиции, который ставится на ордере при его исполнении. Каждый исполненный ордер порождает сделку, которая открывает новую или изменяет уже существующую позицию...
 
This function does not bind the bar to the time. I want Bar[0]=:00(minutes) or 01:00, 02:00 ...of each day. Thus, only when a certain time comes, the algorithm will be calculated. The rest of the time the indicator rests with me.
Seric29:

There is a function for this.

It returns the bar time.

Reason: