[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 18

 
Figar0 >> :

>> Put all the code out there, there's no smell of stoppers here yet...

It's not about stoppers, it's about closing a position as soon as the price touches the MA

 
Novice писал(а) >>

It's not about stoplots, it's about closing the position as soon as the price touches the MA

Let it be so, it was you who wrote about the stops...) But I can't understand why it doesn't work without the code. The above piece is not very informative.

 
Figar0 >> :

So be it, it was you who wrote about stoppers...). All the same, without the code it's impossible to understand why it doesn't work, the posted piece is completely uninformative.

I must have been expressing myself very wrongly, I apologize, I meant that MA itself should serve as a stop-loss

>> :

... ... position was closed as soon as the price touched MA


And the code is extremely primitive:


         Ticket=OrderTicket();                 
         Tip   =OrderType();                   
         Lot   =OrderLots();                   

    MA2C=iMA(NULL,0, Period_MA2,0,MODE_SMA,PRICE_CLOSE,0); //Есть две MA с разным периодом.
    MA3C=iMA(NULL,0, Period_MA3,0,MODE_SMA,PRICE_CLOSE,0); //И вот с такими параметрами.
     
     //Так же есть условия, при которых по идее должны срабатывать 
     // функции закрытия ордеров.
     
     RefreshRates();                  
    if ( Tip==0 && Bid== MA2C)        //Обозначение типа ордера и условия закрытия
     {
      CloseBuy=true;                              // Закрыть Buy
     }
     RefreshRates();
    if ( Tip==0 && Bid== MA3C)
     {
      CloseBuy=true;                              // Закрыть Buy
     }
     RefreshRates();
    if ( Tip==1 && Ask== MA2C)
     {
      CloseSell=true;                               // Закрыть Sell
     }
     RefreshRates();
    if ( Tip==1 && Ask== MA3C)
     {
      CloseSell=true;                               // Закрыть Sell
     }

        // Закрытие ордеров
   while(true)                                  // Цикл закрытия орд.
     {
      if ( Tip==0 && CloseBuy==true)                // Открыт ордер Buy..
        {                                       //и есть критерий закр
         Alert("Попытка закрыть Buy ", Ticket,". Ожидание ответа..");
         RefreshRates();                        // Обновление данных
         ALERT=OrderClose( Ticket, Lot,Bid,3,Blue);      // Закрытие Buy
         if ( ALERT==true)                         // Получилось :)
           {
            Alert ("Закрыт ордер Buy ", Ticket);
            break;                              // Выход из цикла закр
           }
         if ( Fun_Error(GetLastError())==1)      // Обработка ошибок
            continue;                           // Повторная попытка
         return;                                // Выход из start()
        }
        if ( Tip==1 && CloseSell==true)                // Открыт ордер Sell..
        {                                       // и есть критерий закр
         Alert("Попытка закрыть Sell ", Ticket,". Ожидание ответа..");
         RefreshRates();                        // Обновление данных
         ALERT=OrderClose( Ticket, Lot,Ask,3,Red);      // Закрытие Sell
         if ( ALERT==true)                         // Получилось :)
           {
            Alert ("Закрыт ордер Sell ", Ticket);
            break;                              // Выход из цикла закр
           }
         if ( Fun_Error(GetLastError())==1)      // Обработка ошибок
            continue;                           // Повторная попытка
         return;                                // Выход из start()
        }
      break;                                    // Выход из while
     }

I already think that 4 conditions can be changed to 2


     RefreshRates();
    if ( Tip==0 && Bid== MA2C || Tip==0 && Bid== MA3C)
     {
      CloseBuy=true;                              // Критерий закр. Buy
     }
     RefreshRates();
    if ( Tip==1 && Ask== MA2C || Tip==1 && Ask== MA3C)
     {
      CloseSell=true;                               // Критерий закр. Sell
     }
 
     RefreshRates();
    if ( Tip==0 && (Bid== MA2C  || Bid== MA3C))
     {
      CloseBuy=true;                              // Критерий закр. Buy
     }
     RefreshRates();
    if ( Tip==1 && (Ask== MA2C ||  Ask== MA3C))
     {
      CloseSell=true;                               // Критерий закр. Sell
     }

Then it's like this) Anyway, it's a delusional piece, the wagons are built at Bid prices, and to compare them like that... I don't know.

Something in your code, OrderSelect do not see?

 

It's standard, from a textbook:


Symb=Symbol();                               // Название фин.инстр.
   Total=0;                                     // Количество ордеров
   for(int i=1; i<=OrdersTotal(); i++)          // Цикл перебора ордер
     {
      if (OrderSelect( i-1, SELECT_BY_POS)==true) // Если есть следующий
        {                                       // Анализ ордеров:
         if (OrderSymbol()!= Symb)continue;      // Не наш фин. инструм
         if (OrderType()>1)                     // Попался отложенный
           {
            Alert("Обнаружен отложенный ордер. Эксперт не работает.");
            return;                             // Выход из start()
           }
         Total++;                               // Счётчик рыночн. орд
         if ( Total>1)                           // Не более одного орд
           {
            Alert("Несколько рыночных ордеров. Эксперт не работает.");
            return;                             // Выход из start()
           }
         Ticket=OrderTicket();                  // Номер выбранн. орд.
         Tip   =OrderType();                    // Тип выбранного орд.
         Lot   =OrderLots();                    // Количество лотов
        }

//И далее как выше...
It is important for me to understand if this is possible in principle, because when tested in visualisation mode, orders do not close on MA
 
Novice писал(а) >>

I want to know if it is possible to do this in principle because during testing in visualization mode, the orders are not closed on MA

In principle it is possible. Do you only have a single order possible in your system?

Try to normalize Bid/Ask prices and MA values for equality, it's necessary...

Why don't you use your Expert Advisor? I would have corrected it long time ago.

 
Figar0 >> :

In principle it is possible. Do you only have a single order possible in your system?

Try to normalize Bid/Ask prices and MA values for equality, it's necessary...

Why don't you use your Expert Advisor? I would have corrected it long ago.

After that my head started spinning...

No) To a grail as to other galaxy, only attempts to realize and improve TC.


I couldn't get all the code into the post, so I'm attaching

Files:
g.ei.vn.gl..mq4  12 kb
 
Novice писал(а) >>

After that, my head started spinning...

No) The Grail is like another galaxy, just an attempt to implement and improve TC.

I didn't manage to put all code in this post, so I am pasting it here.

But in principle, it somehow works:

The only thing that I have removed the increase in the lot. I thought you said that orders are not closed?

 
They don't close on MA, exactly when the price touches them. On MA2C and MA3C. About the rambling, yes, I haven't finished it yet.


So how...?

Figar0 >> :

...normalise Bid/Ask prices and MA values when comparing for equality...

I just don't quite understand exactly how to normalise... NormalizeDouble(Ask, Digits) ?

 

The problem is topical, I'm still wondering how to get orders to close immediately when the MA price is reached.


After normalisation an error came out during compilation for some reason, and in the part of the code where it wasn't touched at all.