[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 440

 
// ищем самый последний закрытый ордер
datetime time=0;
int ticket=-1;
for( i=OrdersHistoryTotal()-1; i>=0; i--)
{
   if(OrderSelect( i, SELECT_BY_POS, MODE_HISTORY))
   {
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==16384)
      {
         if(OrderCloseTime()> time)
         {
            time=OrderCloseTime();
            ticket=OrderTicket();
         }
      }
   }
}
if(OrderTicket()!= ticket)OrderSelect(ticket, SELECT_BY_TICKET);
if(OrderProfit()<=0) Lots=OrderLots()*2;
//-----
The code seems like it should be... but haven't checked...
 
Vinin >>:

Может так лучше будет

Thank you so much for your help!!!



America is weeping and so is Europe!

They're thinking seriously about the future!

They think they're in financial trouble,

♪ and Russia's in the... ♪ ...frosty!

Let's get the old harmonica off the shelf,

We're not used to this kind of crisis!

If only there were vodka, bacon and potatoes.

We'll get through it all, for fuck's sake!!!

HAPPY FEBRUARY 23 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 
Summer, how did you declare the time variable in your code?
 
Necron >>:

Спасибо! Поправил в советнике на Ваш вариант. Вот допишу это чудо и выложу в Code Base как свое первое (более-менее) серьезное творение!=)) Система, по которой пишу советника называется Мутеки, только немного с моими дополнениями(по управлению позициями). Хорошо, что есть хотя бы индикатор, который построит все эти трендовые=)))

Только еще возник вопрос. Как открыть три позиции одновременно (или приблизительно по одной котировке)?Я делал следующим образом. Правильно ли, или есть другие способы? Отложенниками не получится=(( Маленькое расстояние иногда слишком:(


if(b1==0 && !IsTradeContextBusy())
{
if(Low[0]<HHL_1 && Bid>=HHL_1 && trade_buy==true)
{
ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,slippage*PointX,sl_b,BuyTarget1,"lot_1_buy",Magic,0,Lime);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("lot_1_buy order opened : ",OrderOpenPrice());
b1=1;
}
else Print("Error opening BUY order : ",GetLastError());

return(0);
}
}

You are opening one order here. Try 3 at once, it's unlikely to get faster at this stage.

I haven't experimented myself, but maybe if you parallelize 3 trading terminals and open deals in each terminal separately, you might get something out of it...

 
StatBars >>:
Код вроде бы такой должен быть... но не проверял...

there was an error, it showed that the lot always turns out to be 0.


to Necron:


found an error in the code and cleaned it up, but still it swears like this:



to Techno:

(double)

Files:
graal_3.mq4  3 kb
 
You declared the time variable as double and it should be datetime, fix it and check the version with your original code, it seems to be correct
 
Summer:

This is how it is done in one of my advisers:



double lt = getLots();//эта строчка в переменных, в ордерсенд пишем lt,


double getLots() { // это или перед start или после всего кода

double minlot = MarketInfo(Symbol(), MODE_MINLOT);
double maxlot = MarketInfo(Symbol(), MODE_MAXLOT);
int round;
if(minlot==0.01)round=2;
if(minlot==0.1) round=1;
double koeff=2;
double result=Lots;

//int round = 2;
int total = OrdersHistoryTotal();
double spread = MarketInfo(Symbol(), MODE_SPREAD);

for (int i = 0; i < total; i++) {
OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) {
if (OrderProfit() > 0) {
result = Lots;

} else {
result = OrderLots() * koeff;

}
}
}
result = NormalizeDouble(result, round);
if (result > maxlot) {
result = maxlot;
}
if (result < minlot) {
result = minlot;
}
RefreshRates();
return(result);
}

 

Techno, thanks for the tip!) StatBars and Necron thanks too.

But to make sure the martingale would work, I reworked the code a bit))

// ищем самый последний закрытый ордер
for( i=OrdersHistoryTotal(); i>=0; i--){
  if(OrderSelect( i, SELECT_BY_POS, MODE_HISTORY)){
    if(OrderSymbol()==Symbol()){
      if(OrderMagicNumber()== Magic){
        if(OrderCloseTime()!=0){
          if(OrderCloseTime()> time){
          time=OrderCloseTime();
          profit=OrderProfit();
          
            //мартин
            if( profit<0) Lots=OrderLots()*2;
            if( profit>=0) Lots=0.1; // начальный лот
            //----
            
            
          }
        }
      }
    }
  }
}
//-----
 
StatBars >>:

здесь Вы один ордер открываете. попробуйте сразу 3, быстрее наврятли получиться на данном этапе.

Сам не экспериментировал, но, возможно, если запараллелить 3 торговых терминала и открывать сделки на каждом терминале в отдельности то может и получиться что-то выгадать...

I understand, I have 6 of them=) Three to buy and three to sell.I'll try to check on the demo later. At the very least I will try to do something with pending orders.

 
Summer >>:

ошибка была, через алерт вывел, показало что лот всегда получается 0.

double getLot()
{
if(OrdersHistoryTotal()==0)return(0.1);
// ищем самый последний закрытый ордер
datetime time=0;
int ticket=-1;
for( i=OrdersHistoryTotal()-1; i>=0; i--)
{
   if(OrderSelect( i, SELECT_BY_POS, MODE_HISTORY))
   {
      if(OrderSymbol()==Symbol()/* && OrderMagicNumber()==16384*/)
      {
         if(OrderCloseTime()> time)
         {
            time=OrderCloseTime();
            ticket=OrderTicket();
         }
      }
   }
}
if(OrderTicket()!= ticket)OrderSelect( ticket, SELECT_BY_TICKET);
if(OrderProfit()<=0) return(NormalizeDouble(OrderLots()*2,2));
if(OrderProfit()>0)return(0.1);
//-----
}


Reason: