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

 
VIX XIV:
Good evening. What should the code that will find the last closed order look like? Does it look like this: "OrderSelect(OrdersHistoryTotal, SELECT_BY_POS, MODE_HISTORY"?

This is what your block should roughly look like:

int a=-1;

for(int is=OrdersHistoryTotal(); is>=0; is--)

{

if(OrderSelect(is, SELECT_BY_POS, MODE_HISTORY))

{

if(OrderType()==OP_BUY) {a=OrderType(); break;}

if(OrderType()==OP_SELL){a=OrderType(); break;}

}

}

if(a==OP_BUY) Comment("The last Buy order closed in the list was found;)

if(a==OP_SELL) Comment("The last closed Sell order in the list was found;)


 

I read a long time ago that there is no guarantee in the chronological arrangement of orders in OrdersHistoryTotal, and you have to check by the closing date.

 

@Valerius, can't you insert it as code? Or what's missing?

 
Сергей Таболин:

@Valerius, can't you insert it as code? Or what's missing?

Could you make it humanly possible to insert code as code in MT editor?

None of your buttons work the way I need them to.

 
Valerius:

Could you make it humanly possible to insert the code as code in the MT editor?

None of your buttons work the way I want them to.

There's a tricky way. Copy and paste anything you like from any code. And paste your code in there. Minus the highlighting doesn't work this way))))


if(OrderSelect(is,SELECT_BY_POS,MODE_TRADES))  Это чужой код и его можно править))))
 
Valerius:

For the first question, you need to make a function like this:


for(int is=OrdersTotal()-1; is>=0; is--)
{
if(OrderSelect(is,SELECT_BY_POS,MODE_TRADES))
{//Close orders which have been opened on Friday of the week which is not the current week. In this case, we are not closing orders on Friday of the current week.
if(OrderMagicNumber()==Magic && TimeDayOfWeek(TimeCurrent())==5 && TimeDayOfWeek(OrderOpenTime())==5 && TimeDayOfYear(OrderOpenTime())<TimeDayOfYear(TimeCurrent())
{
if (OrderType()==OP_BUY) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(nameSym,MODE_BID),MarketInfo(nameSym,MODE_DIGITS)),3,CLR_NONE);
if (OrderType()==OP_SELL) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(nameSym,MODE_ASK),MarketInfo(nameSym,MODE_DIGITS)),3,CLR_NONE);
if(!result) {error=GetLastError(); Print("LastError = ",error, ",Symbol()); }
else {error=0;}
else
{Print("NoMagic ",OrderMagicNumber();} // for Debug
else

{Print("Error when order select ", GetLastError();}


For the second question, there should be the following entry:

OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(MarketInfo(nameSym,MODE_ASK)), 3, clrNONE);

Good luck.

Thank you! It worked as expected on the first question

On the second - incorrect number of parameters. Fixed it this way - OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);

Only now I didn't quite understand the edit from my first variant (I copied it from somewhere ) ...

 
Hello
Can someone please explain how trailing take profi works? There is some information about Trailing Stop in MT5 help, but there is no information about Trailing Profit. When I set "Stop Loss trailing level (in points)" in my Expert Advisor, for example, to 100, I understand that trailing profit will be activated, when the price passes 100 points in required direction. But what does "Take Profit trailing level (in points)" = 10 mean?
 
altec3:
Hello!
Can someone please explain the principle of trailing take profi? I cannot find any information about Trailing Stop in the MT5 Reference. When I set "Stop Loss trailing level (in points)" in my Expert Advisor, for example, to 100, I understand that trailing profit will be activated, when the price passes 100 points in required direction. But what does "Take Profit trailing level (in points)" = 10 mean?

TakeProfit is calculated in pips and Trailing TakeProfit is calculated in the deposit currency. Trailing TakeProfit is profit in the currency of the deposit from one or more orders, and puts stops of orders in the amount specified in the settings, i.e. at a calculated distance.

For example, a Trailing Take Profit of $100 is specified in the settings. Once the price reaches the 100$ profit and goes further, the program calculates the distance of 100$ and places all stoplosses of orders in the calculated spot, if it allows it. As soon as the price rolls back to the stops, all orders will be closed. In principle this is the same as Trailing Stop, only it is calculated in depo currency and trails profit. I may have made a mistake somewhere, but this is the principle. I hope I have explained it.

 
How can I use python to request all the bars from the terminal of a specified timeframe?
 
Do I understand correctly, that in mt5, instead of closing time, POSITION_TIME_UPDATE should be watched?
Reason: