[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 22

 

Hello. Help for Dummies: I have an EA that can place pending orders on the min. and max. of the previous candle. Opening in the direction of the candle.

The need:

- To change the opening direction, i.e. pending buy to - pending sell.

- Make min and max of the previous candle instead of min and max of the previous day

- Leave everything else as it is, i.e. delete orders, lot parameters, stop-los, magic number

All my actions either lead to error 130 in the tester or it won't compile at all. Thanks for any advice.

Below is the working code, without my intervention.

extern double Lot = 0.01;
extern int StopLoss = 0;
extern int TakeProfit = 0;
extern int Magic = 618;

int Up_bars = 0;
int Down_bars = 0;

double StopLoss_new = 0;
double TakeProfit_new = 0;

//+------------------------------------------------------------------+
//| expert initialisation function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

for( int cnt=0;cnt<OrdersTotal();cnt++)
{
if (OrderSelect(cnt,SELECT_BY_POS, MODE_TRADES)>0)
{
if (
(OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP)
&& OrderMagicNumber() == Magic
&& OrderSymbol() == Symbol()
&& OrderComment() != DoubleToStr(Bars,0)
)
{
Comment("okkk");
OrderDelete(OrderTicket());
}
}
}

StopLoss_new = StopLoss;
TakeProfit_new = TakeProfit;

if (Up_bars != Bars)
{
if (High[1]-Ask >= MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)
{
if (StopLoss_new != 0) StopLoss_new = NormalizeDouble(High[1]-StopLoss*Point,Digits);
if (TakeProfit_new != 0) TakeProfit_new = NormalizeDouble(High[1]+TakeProfit*Point,Digits);
if (OrderSend(Symbol(),OP_BUYSTOP,Lot,NormalizeDouble(High[1],Digits),10,StopLoss_new,TakeProfit_new,DoubleToStr(Bars,0),Magic,0,Green) < 0)
{
Sleep(1000);
RefreshRates();
}
else
{
Up_bars = Bars;
}
}
}

StopLoss_new = StopLoss;
TakeProfit_new = TakeProfit;

if (Down_bars != Bars)
{
if (Bid-Low[1] >= MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)
{
if (StopLoss_new != 0) StopLoss_new = NormalizeDouble(Low[1]+StopLoss*Point,Digits);
if (TakeProfit_new != 0) TakeProfit_new = NormalizeDouble(Low[1]-TakeProfit*Point,Digits);
if (OrderSend(Symbol(),OP_SELLSTOP,Lot,NormalizeDouble(Low[1],Digits),10,StopLoss_new,TakeProfit_new,DoubleToStr(Bars,0),Magic,0,Green) < 0)
{
Sleep(1000);
RefreshRates();
}
else
{
Down_bars = Bars;
}
}
}


//----
return(0);
}
//+------------------------------------------------------------------+

 
delf:

Hello. Help a dummy figure this out:

Did you happen to confuse "Any Beginner's Question" with "Completely redo the EA"?
 
LazarevDenis:

Captain Obviousness... and yet someone give me a hint.

I'll give you a hint - put that expression in words. And you'll see that you've put it wrong.

PS.
If it is so obvious to you where to look for an error, then why ask?

 
delf:


If Error 130. Reconsider the stop and takeaway.
 
LazarevDenis:

help please, the order should close at 4 times the distance from high to orderopenprice

Where did I mess up?

all orders close within 3 pips of opening


Have you tried to calculate the result of your formula? If not, then do it, because I'm getting some bullshit. Maybe it's because I don't know all the conditions.
 

Only one error - don't know how to fix it. Where is the problem ?

'Symbol' - initialization expected C:\Program Files\MetaTrader Finam\experts\1.mq4 (8, 13)

'Symbol - initialization expected C:\Program Files\MetaTrader Finam\experts\1.mq4 (8, 13)

extern double lot=0.1;
extern double tp=0;
extern double sl=0;
int Real_Order=-1;    // Пока рыночных нет

string Symb=Symbol;                        // Финанс. инструмент

int start()     // Спец. функция start()


{                                
   OrderSend(Symbol(),OP_BUY,0.1,Ask,0,Bid-sl*Point,Ask+tp*Point); 
   if(IsDemo()) PlaySound("alert.wav");
   
      for (int i=1; i<=OrdersTotal(); i++)       //Цикл по всем ордерам,..
     {                                        //отражённым в терминале
      if(OrderSelect(i-1,SELECT_BY_POS)==true)//Если есть следующий
        {  
               //--------------------------------------------------------------                                   
         if (OrderSymbol()!= Symb) continue;    // Не наш фин.инструм.
         int Tip=OrderType();                   // Тип ордера
         if (Real_Order>1) continue;                   //отложник ордер  
         //------------------------------------------------------ 4 --
         double Price=OrderOpenPrice();         // Цена ордера
         if 
            NormalizeDouble(tp,sl,Digits)       // Выбор самого близкого орд       
           {         
            Real_Order=Tip;                     // Есть рыночный ордер
            int Ticket=OrderTicket();           // Номер ордера
            double Lot=OrderLots();             // Количество лотов
           }
        }                                       //Конец анализа ордера
     }                                          //Конец перебора орд.
     //---------------------------------------------------------------------+
    while(true)                                  // Цикл закрытия орд.
     {
      if (Real_Order==-1)                       // Если рыночных нет
        {
         Alert("По ",Symb," рыночных ордеров нет");
         break;                                 // Выход из цикла закр        
        }
      //--------------------------------------------------------- 7 --
      switch(Real_Order)                        // По типу ордера
        {
         case 0: double Price_Cls=Bid;          // Ордер Buy
            string Text="Buy ";                 // Текст для Buy
            break;                              // Из switch
         case 1: Price_Cls=Ask;                 // Ордер Sell
            Text="Sell ";                       // Текст для Sell
        }
      Alert("Попытка закрыть ",Text," ",Ticket,". Ожидание ответа..");
      bool Ans=OrderClose(Ticket,Lot,Price_Cls,2);// Закрытие ордера
      //--------------------------------------------------------- 8 --
      if (Ans==true)                            // Получилось :)
        {
         Alert ("Закрыт ордер ",Text," ",Ticket);
         break;                                 // Выход из цикла закр
        }    
       //--------------------------------------------------------- 9 --
      int Error=GetLastError();                 // Не получилось :(
      switch(Error)                             // Преодолимые ошибки
        {
         case 135:Alert("Цена изменилась. Пробуем ещё раз..");
            RefreshRates();                     // Обновим данные
            continue;                           // На след. итерацию
         case 136:Alert("Нет цен. Ждём новый тик..");
            while(RefreshRates()==false)        // До нового тика
               Sleep(1);                        // Задержка в цикле
            continue;                           // На след. итерацию
         case 146:Alert("Подсистема торговли занята. Пробуем ещё..");
            Sleep(500);                         // Простое решение
            RefreshRates();                     // Обновим данные
            continue;                           // На след. итерацию
        }
      switch(Error)                             // Критические ошибки
        {
         case 2 : Alert("Общая ошибка.");
            break;                              // Выход из switch
         case 5 : Alert("Старая версия клиентского терминала.");
            break;                              // Выход из switch
         case 64: Alert("Счет заблокирован.");
            break;                              // Выход из switch
         case 133:Alert("Торговля запрещена");
            break;                              // Выход из switch
         default: Alert("Возникла ошибка ",Error);//Другие варианты   
        }
      break;                                    // Выход из цикла закр
     }  
 
   
   return;                                   // Выход из start()
  }
 

alex12, specify something specific, like

string Symb="EURUSD";                        // Финанс. инструмент
 
alex12:

Only one error - don't know how to fix it. Where is the problem ?

'Symbol' - initialization expected C:\Program Files\MetaTrader Finam\experts\1.mq4 (8, 13)

'Symbol - initialization expected C:\Program Files\MetaTrader Finam\experts\1.mq4 (8, 13)

You have:

string Symb=Symbol;                        // Финанс. инструмен

You need to:

string Symb=Symbol();                        // Финанс. инструмент
In fact, you can double-click on the error message and the cursor will go to the specified (by the way) location where the compilation error occurred, i.e., here: (8, 13)

After that, other errors will be thrown... :)

Move the above line to the beginning of the start() function

That's a start - then deal with other errors...

 

Hi all.

Guys, we need some help. Describing the situation.

the current price is 1.4100 (for example) I need to find a bar whose open will be within (plus or minus 10 pt from 1.4100) from 1.4090 to 1.4110 - this is ok.

For example the program has found the bar with the open at 1.4105 that fits me.

Then the program should compare this bar with the bar to its left and the right and if it is lower, it will be suitable.

 

Artem, the trick here is that there is a line like this below:

if (OrderSymbol()!= Symb) continue;    // Не наш фин.инструм.

So the way you suggested doesn't make much sense - if I understood correctly what alex12 wants.

Reason: