О! It's working! Thank you, comrades, for the ideas!
But I had to tweak it a bit. It even got easier, without (true). Although I can't explain this complicated MQL logic).
That's how I implemented it:
datetime timeBar = iTime(_Symbol,PERIOD_CURRENT, 0);// период можно поставить по своему усмотрениюdatetimestatic timeOpen = 0;
if((PositionsTotal()==0)&&(c0>h1)&&(rGENUP>0.30)&&(timeBar > timeOpen)) // Условие для открытия позиции.
{
MqlTradeRequest request;
MqlTradeResult result;
request.action =TRADE_ACTION_DEAL; // тип торговой операции
request.symbol =Symbol(); // символ
request.volume =1; // объем в 1 лот
request.type =ORDER_TYPE_BUY; // тип ордера
request.price =SymbolInfoDouble(Symbol(),SYMBOL_ASK); // цена для открытия
request.deviation=3;
request.sl = NormalizeDouble(Ask-50*_Point,_Digits);
request.tp = NormalizeDouble(Ask+50*_Point,_Digits);
if(!OrderSend(request,result))
PrintFormat("OrderSend error %d",GetLastError()); // если отправить запрос не удалось, вывести код ошибки//--- информация об операцииPrintFormat("retcode=%u deal=%I64u order=%I64u",result.retcode,result.deal,result.order);
// допустимое отклонение от цены
timeOpen = timeBar;
}
I wonder why there is such a big code in MQL5 for position opening. Unlike MQL4. In 4 it's just one line. Can we cut it down? For example, can we remove the error handler?
Торговая деятельность в платформе связана с формированием и отсылкой рыночных и отложенных ордеров для исполнения брокером, а также с управлением текущими позициями путем их модификации или закрытия. Платформа позволяет удобно просматривать торговую историю на счете, настраивать оповещения о событиях на рынке и многое другое. Открытие позиций...
О! It's working! Thank you, comrades, for the ideas!
But I had to tweak it a bit. It even got easier, without (true). Although I can't explain this complicated MQL logic).
That's how I implemented it:
I wonder why there is so much code in MQL5 to open a position. Unlike MQL4. In 4, it's just one line. But here... Can you make it shorter? For example, can we remove the error handler?
Use trade classes. And the code will be very short.
Example:
//+------------------------------------------------------------------+//| Only_one_purchase.mq5 |//+------------------------------------------------------------------+#property version"1.003"#property script_show_inputs#include <Trade\Trade.mqh>
CTrade m_trade; // trading object//--- input parametersinputENUM_POSITION_TYPE InpPositionType = POSITION_TYPE_BUY; // Position Typeinputdouble InpVolume = 0.0; // Volumeinputulong m_magic = 15489; // magic number//+------------------------------------------------------------------+//| Script program start function |//+------------------------------------------------------------------+voidOnStart()
{
m_trade.SetExpertMagicNumber(m_magic);
//--- open a positionif(InpPositionType==POSITION_TYPE_BUY)
m_trade.Buy(InpVolume);
else
m_trade.Sell(InpVolume);
}
//+------------------------------------------------------------------+
О! It's working! Thank you, comrades, for the ideas!
But I had to tweak it a bit. It even got easier, without (true). Although I can't explain this complicated MQL logic).
That is how I implemented it:
I wonder why there is such a big code in MQL5 for position opening. Unlike MQL4. In 4, it's just one line. But here... Can it be shortened? For example, can we remove the error handler?
So, if you have in the condition
if((PositionsTotal()==0)&&
why do you need more checks for a new bar? Or is there an option that position will be closed at the same bar and the second opening should be prohibited?
О! It's working! Thank you, comrades, for the ideas!
But I had to tweak it a bit. It even got easier, without (true). Although I can't explain this complicated MQL logic).
That's how I implemented it:
I wonder why there is such a big code in MQL5 for opening a position. Unlike MQL4. In 4, it's just one line. But here... Can it be shortened? For example, can we remove the error handler?
You know, long ago, when there was MQL4, people were indignantly saying that they hadn't been given lower-level access - so that they could do something in their own way.
Well, they did - now they gave access to OrderSend() in MQL4 - so to speak, they deployed its logic in MQL - so do what you want. But no - now I've got complaints that it's too complicated.
Complicated? No problem - give you trade classes in SB - they are almost the same as in MQL4 standard trade functions. In MQL4 such classes are the trade functions. And in MQL5 - all with open access.
You know, long time ago, when there was MQL4, people were indignantly saying that they didn't give them lower-level access - so that they could do something in their own way.
Well, they did - now they gave access to OrderSend() in MQL4 - so to speak, they deployed its logic in MQL - so do what you want. But no - now I've got complaints that it's too complicated.
Complicated? No problem - give you trade classes in SB - they are almost the same as in MQL4 standard trade functions. In MQL4 such classes are the trade functions. And in MQL5 - all with open access.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
That didn't work either.
What a hobgoblin likes kilometres of code...
Your problem can be solved in SIX lines of code, taking into account declaration of variables.
I hope you can figure out the signal variable.
О! It's working! Thank you, comrades, for the ideas!
But I had to tweak it a bit. It even got easier, without (true). Although I can't explain this complicated MQL logic).
That's how I implemented it:
I wonder why there is such a big code in MQL5 for position opening. Unlike MQL4. In 4 it's just one line. Can we cut it down? For example, can we remove the error handler?О! It's working! Thank you, comrades, for the ideas!
But I had to tweak it a bit. It even got easier, without (true). Although I can't explain this complicated MQL logic).
That's how I implemented it:
I wonder why there is so much code in MQL5 to open a position. Unlike MQL4. In 4, it's just one line. But here... Can you make it shorter? For example, can we remove the error handler?Use trade classes. And the code will be very short.
Example:
О! It's working! Thank you, comrades, for the ideas!
But I had to tweak it a bit. It even got easier, without (true). Although I can't explain this complicated MQL logic).
That is how I implemented it:
I wonder why there is such a big code in MQL5 for position opening. Unlike MQL4. In 4, it's just one line. But here... Can it be shortened? For example, can we remove the error handler?So, if you have in the condition
why do you need more checks for a new bar? Or is there an option that position will be closed at the same bar and the second opening should be prohibited?
О! It's working! Thank you, comrades, for the ideas!
But I had to tweak it a bit. It even got easier, without (true). Although I can't explain this complicated MQL logic).
That's how I implemented it:
I wonder why there is such a big code in MQL5 for opening a position. Unlike MQL4. In 4, it's just one line. But here... Can it be shortened? For example, can we remove the error handler?You know, long ago, when there was MQL4, people were indignantly saying that they hadn't been given lower-level access - so that they could do something in their own way.
Well, they did - now they gave access to OrderSend() in MQL4 - so to speak, they deployed its logic in MQL - so do what you want. But no - now I've got complaints that it's too complicated.
Complicated? No problem - give you trade classes in SB - they are almost the same as in MQL4 standard trade functions.
In MQL4 such classes are the trade functions. And in MQL5 - all with open access.
Take advantage of it.
You know, long time ago, when there was MQL4, people were indignantly saying that they didn't give them lower-level access - so that they could do something in their own way.
Well, they did - now they gave access to OrderSend() in MQL4 - so to speak, they deployed its logic in MQL - so do what you want. But no - now I've got complaints that it's too complicated.
Complicated? No problem - give you trade classes in SB - they are almost the same as in MQL4 standard trade functions.
In MQL4 such classes are the trade functions. And in MQL5 - all with open access.
Take advantage of it.
Docent, and Docent. Why are you so angry (today) ©
Docent, ah Docent. Why are you so angry (today) ©
Get in the ice hole...
So if you have a condition
why do we need to check for a new bar? Or is there an option that the position will close on the same bar and we should disallow a second opening?
Exactly right - there is an option to close the position on the same bar.
(Cut into the new wall. ) The "wall" is called breakeven.
This is how it was implemented in MQL4:
(I copied it somewhere I do not remember).
But here is how it is implemented in 5-PC. How do I do it?
I looked through the Trading Classes, I don't see it in there. But the thing is needed. What do the pros say?
How can I prevent trades from other charts from appearing on the chart?
Only the trades of the robot that is on the given chart.