Organising the order cycle - page 13

 
fxsaber:

The example template is specifically written with SB. So question to MT5 specialists, is the code correct?

Not a specialist, but I will point out the obvious: such code can get away with endless attempts to close a position (for example, at the end of a trading session).

Well, and complex conditions in one line of code, of course, reduce the code, but make it more difficult to read.

 
Andrey Khatimlianskii:

Not an expert, but I will point out the obvious: such code can get away with endlessly trying to close a position (e.g. at the end of a trading session).

It cannot.

Well, complex conditions in one line of code, of course, reduce the code, but make it more difficult to read.

In this case, brevity only helps - the entire TS is on the screen.

 
fxsaber:

If you take it so literally, you can also read the past tick history for each symbol in the Market Watch. But I think you actually understand the meaning of the statement.

The code kind of implements that statement. That's why I asked all who understand the MT5: is the code correct?

Well, we are the programmers.

So understood ...

No hard feelings.

 

fxsaber:

That's why I had a question for everyone who understands MT5: is the code correct?

Didn't look at the code much - who actively uses SB (me - no, not the trading classes more precisely), maybe they can tell?

 
Artyom Trishkin:

I haven't looked at the code much - who actively uses SB (me - no, not the trading classes more specifically), maybe they can tell?

This is a rare case where the SB works as it should. The template is a skeleton. Of course, you can throw in all sorts of meat in the form of filling checks, lots, etc. But the basis will remain.

A template can be rewritten on MT4 with a minimum of effort and it will work 100% on MT5. But on the other hand, on MT5 is a good question really!

 
fxsaber:

This is a rare case where the SB is working properly. The template is a skeleton. Of course, you can throw in all sorts of meat in the form of filling checks, loyalties, etc. But the main basis will remain.

A template can be rewritten on MT4 with minimum effort and it will work 100% on MT5. But on MT5 is a good question really!

I will try to use it with a clear head and not at 5 am :)

I'll wake up, if no one who knows SB well posts, I can try and figure out the likely pebbles.

 
fxsaber:

The template can be rewritten to MT4 with minimal effort and will work 100% there.

Rewritten on MT4

// Шаблон большинства ТС

#property strict // обязательно

// Сигнал на покупку
bool BuySignal( const string Symb ) { return(true); }

// Сигнал на продажу
bool SellSignal( const string Symb ) { return(false); }

// Находит ордер соответствующего типа
bool OrdersScan( const string Symb, const int Type )
{
  for (int i = OrdersTotal() - 1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS) && (OrderType() == Type) && (OrderSymbol() == Symb))
      return(true);    
    
  return(false);  
}

// Торговое действие на сигнал
bool Action( const string Symb, const int Type, const double Lots = 1 )
{
  bool Res = true;    
  
  // Закрыли противоположные сигналу позиции
  while ((OrdersScan(Symb, 1 - Type)) && (Res = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 100)));

  // Открыли позицию по сигналу
  return(Res && !OrdersScan(Symb, Type) && OrderSend(Symb, Type, Lots, SymbolInfoDouble(Symb, Type ? SYMBOL_BID : SYMBOL_ASK), 100, 0, 0));
}

// Шаблон торговой стратегии
void Strategy( const string Symb )
{
  if (BuySignal(Symb))
    Action(Symb, OP_BUY);
  else if (SellSignal(Symb))
    Action(Symb, OP_SELL);
}

void OnTick()
{
  Strategy(_Symbol);
}

But on MT5 is a good question really!

Interesting comments on MT5.
 
fxsaber:

He can't.

Yes, it can. Can just not close a position when it needs to be done.


fxsaber:

In this case, brevity only helps - the entire TS is on the screen.

You can write it in 5 lines, it will not make reading easier.

I share my perception.

 
Andrey Khatimlianskii:

Yeah, that's right. Can just not close a position when it needs to be done.

I wrote the MT4 variant on purpose to make it more familiar. It seems that MT4 and MT5 variants are identical. SB is exactly the same. We will assume that MT4 variant is 100% working. I.e. we will skip some small details.

We may write it in 5 lines, it will not make reading easier.

I am sharing my perception of it.

Yes, somebody else's code is a mystery.

 
fxsaber:

I wrote the MT4 variant on purpose to make it more familiar. It seems that MT4 and MT5 variants are identical. SB is exactly the same.

And what, OrderClose is guaranteed to close the trade?


fxsaber:

Yes, other people's code is dark.

No, it's not always like that. I mean the style.