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

 
granit77:
Moved:

qaz2005 11.10.2011 09:30
Good afternoon all! Please advise, there is a custom indicator, it has two objects. Their values I can find out, but here is no way to distinguish them, whether it is the top line or bottom. I can not know the number and order of the buffers, when installing there are no settings. On the Internet read that the settings for the colour also go as buffers, how to refer to them through the function iCustom () or maybe any other function to work out this point?

Thanks in advance!

P.S. Is there any literature on the MQL4 language? I've already downloaded and almost finished an MQL4 tutorial.

buffer numbers are counted from "0",

iCustom(NULL, 0, "ind",150, 0,2);

where 150 is the period,

0 is buffer,

2 is a bar.

https://docs.mql4.com/ru/indicators/iCustom

e.g.

#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

so most likely blue = 0 buffer

and red = 1

 
skyjet:
Alexander! Thank you for sharing your experience! But along the way I have a question, how is currency enumeration done? Or is it the name of the currency in the OrderSend() f-i in place of Symbol()? And could you please explain how to put your example in the code? Thanks again for your help! :)

Roman, basically explained.

Everywhere where Symbol() is specified in Expert Advisor, put for example: SymbolMax[nnnn]. In OrderSend(), it looks like this

tick=OrderSend(SymbolMax[nnnn],OP_BUYSTOP,L,ur,0,sl,tp,CMM,MAGIC[I],0,Red);

I wrote it in my Expert Advisor, and you set your own values there. You can set the list of currencies, for example:

string SymbolMax[4] = {"EURUSD", "GBPUSD", "USDCHF", "USDJPY"};

Maybe, someone implemented it in another way but this is my currency lookup - see code below. I put start at the beginning of the function. Plus I've made a 5-second delay to prevent messages from jumping around.

if(nnnn<24) nnnn+=1; else nnnn=0;
 


I'm having a problem with a modification looping,

the modification is represented as a user defined function
The most interesting thing is that the standard trawl function works with both of these functions and i can do it alone ok, but when i use a fractal modification with breakeven, i get endless modifications with fractal and breakeven

I based it on the modification of https://book.mql4.com/ru/trading/ordermodify

I get the impression that the criterion for modifying Breakeven is not set correctly, how can I fix it to avoid looping?




//ф-я модификации ордеров безубыток

int mod_b()
{
//--------------------------------------------------------------- 2 --
for(int i=1; i<=OrdersTotal(); i++) // Цикл перебора ордер
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // Если есть следующий
{ // Анализ ордеров:
int Tip=OrderType(); // Тип ордера
if(OrderSymbol()!=Symb||Tip>1)continue;// Не наш ордер
double SL=OrderStopLoss(); // SL выбранного орд.
double TP =OrderTakeProfit(); // TP выбранного орд.
double Price =OrderOpenPrice(); // Цена выбранн. орд.
int Ticket=OrderTicket(); // Номер выбранн. орд.
//------------------------------------------------------ 3 --
while(true) // Цикл модификации
{
double TS=Tral_Stop; // Исходное значение
int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);//Миним. дист&&((SL<TS && Tip==0)||(SL>TS && Tip==1))
if (TS < Min_Dist) // Если меньше допуст.
TS=Min_Dist; // Новое значение TS
//--------------------------------------------------- 4 --
bool Modify=false; // Не назначен к модифи
switch(Tip) // По типу ордера
{
case 0 : // Ордер Buy
if (NormalizeDouble(SL,Digits)< // Если ниже желаем.
NormalizeDouble(Bid-TS*Point,Digits))
{
SL=Price+18*Point; // то модифицируем его
string Text="Buy "; // Текст для Buy
Modify=true; // Назначен к модифи.
}
break; // Выход из switch
case 1 : // Ордер Sell
if (NormalizeDouble(SL,Digits)> // Если выше желаем.
NormalizeDouble(Ask+TS*Point,Digits)
|| NormalizeDouble(SL,Digits)==0)//или равно нулю
{
SL=Price-18*Point; // то модифицируем его
Text="Sell "; // Текст для Sell
Modify=true; // Назначен к модифи.
}
} // Конец switch
if (Modify==false) // Если его не модифи
break; // Выход из while
//--------------------------------------------------- 5 --

Alert ("Модификация ",Text,Ticket,". Ждём ответ..");
bool Ans=OrderModify(Ticket,Price,SL,TP,0);//Модифи его!
//--------------------------------------------------- 6 --
if (Ans==true) // Получилось :)
{
Alert ("Ордер ",Text,Ticket," модифицирован:)");
break; // Из цикла модифи.
}

int mod_f()
{
//--------------------------------------------------------------- 2 --
for(int i=1; i<=OrdersTotal(); i++) // Цикл перебора ордер
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // Если есть следующий
{ // Анализ ордеров:
int Tip=OrderType(); // Тип ордера
if(OrderSymbol()!=Symb||Tip>1)continue;// Не наш ордер
double SL=OrderStopLoss(); // SL выбранного орд.

//------------------------------------------------------обсчет фрактала

int f = 3; //номер бара с которого идет проверка наличия фрагтала
int DnN = 0, UpN = 0; //порядковый номер присвоен к направлению(upper, lower)
double UpFr = 0, DnFr = 0; //числовое значение фрагтала выраженное в еденице валюты присвоен к направлению(upper, lower)
while (f < Bars && (UpFr == 0 || DnFr == 0))
{
if (iFractals(Symbol(), 0, MODE_UPPER, f) != 0)
if (UpFr == 0)
{
UpFr = iFractals(Symbol(), 0, MODE_UPPER, f);//фрактальная отложка вверх(buy)
UpN = f;
}
if (iFractals(Symbol(), 0, MODE_LOWER, f) != 0)
if (DnFr == 0)
{
DnFr = iFractals(Symbol(), 0, MODE_LOWER, f);//фрактальная отложка вниз(sell)
DnN = f;
}
f++;
}
//------------------------------------------------------ 3 --
while(true) // Цикл модификации
{
double UD;
double TS=UD; // Исходное значение
int Min_Dist=MarketInfo(Symb,MODE_STOPLEVEL);//Миним. дист
if(Tip==0)
UD=DnFr;
if(Tip==1)
UD=UpFr;
if (TS < Min_Dist) // Если меньше допуст.
TS=Min_Dist; // Новое значение TS
//--------------------------------------------------- 4 --
bool Modify=false; // Не назначен к модифи
switch(Tip) // По типу ордера
{
case 0 : // Ордер Buy
if (NormalizeDouble(SL,Digits)< // Если ниже желаем.
NormalizeDouble(UD,Digits))
{
SL=UD; // то модифицируем его
string Text="Buy "; // Текст для Buy
Modify=true; // Назначен к модифи.
}
break; // Выход из switch
case 1 : // Ордер Sell
if (NormalizeDouble(SL,Digits)> // Если выше желаем.
NormalizeDouble(UD,Digits)
|| NormalizeDouble(SL,Digits)==0)//или равно нулю
{
SL=UD; // то модифицируем его
Text="Sell "; // Текст для Sell
Modify=true; // Назначен к модифи.
}
} // Конец switch
if (Modify==false) // Если его не модифи
break; // Выход из while
//--------------------------------------------------- 5 --
double TP =OrderTakeProfit(); // TP выбранного орд.
double Price =OrderOpenPrice(); // Цена выбранн. орд.
int Ticket=OrderTicket(); // Номер выбранн. орд.

Alert ("Модификация ",Text,Ticket,". Ждём ответ..");
bool Ans=OrderModify(Ticket,Price,SL,TP,0);//Модифи его!
//--------------------------------------------------- 6 --
if (Ans==true) // Получилось :)
{
Alert ("Ордер ",Text,Ticket," модифицирован:)");
break; // Из цикла модифи.
}
 

Hello Dear forum users.

How can I request quotes from other timeframes? I have a template on D and my indicator needs quotes LOW, HIGH, OPEN, CLOSE from smaller timeframes (M30, H1, H4 for example).

 
Slava2007:

Hello Dear forum users.

How can I request quotes from other timeframes? I have a template on D and my indicator needs quotes LOW, HIGH, OPEN, CLOSE from smaller timeframes (M30, H1, H4 for example).

https://docs.mql4.com/ru/series
 

Good evening all. tell me what is the error here. here is a piece of code.

//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();

if (!IfTrueThenCountBarWork) return (0);
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES)
if (OrderMagicNumber() == 700000) <---- IN THIS STROKE SAYS ERROR!!!
CloseAfterSomeBar (CountBar, OrderTicket());
}

}

 
isaev-av:

Good evening, everyone. please tell me what the error is here. here is a piece of code.

//+------------------------------------------------------------------+
//| Start function |
//+------------------------------------------------------------------+
void start()
{
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
else CheckForClose();

if (!IfTrueThenCountBarWork) return (0);
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES)
if (OrderMagicNumber() == 700000) <---- IN THIS STROKE SPEAKS ERROR!!!
CloseAfterSomeBar (CountBar, OrderTicket())
}

}

Missing character ";"
 

PapaYozh:
Пропущен символ ";"

thank you!!! Didn't notice at first.)))


 

Another question to the experts. how to enter correctly the opening condition: Close[2]<Close[3] by n percent for sell. for buy the opposite of course. and n can be optimized? thanks in advance!

void CheckForOpen()
{
double ma;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0)
//---- sell conditions
if(Open[1]>ma && Close[1]<ma)
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,",MAGICMA,0,Red);
return;
}
//---- buy conditions
if(Open[1]<ma && Close[1]>ma)
{
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,",MAGICMA,0,Blue);
return;
}

 

Tell me where i went wrong plz... or if it's MT4 itself, but my Buy orders open only on High bar, and Sell orders only on Close bar =) Although I haven't even stipulated these conditions in the Expert Advisor's code =)

 extern int TP = 200; 
     extern int TS = 50; 
     extern int TF = 1; 
     extern double lots = 0.1; 
     extern int Pips = 15; 
     extern int MaxPips = 100; 


     int slip = 3; 
     int Magic = 2; 
     int cnt,ticket,total; 

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

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

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

 int start() 
    { 
  //---- 

 static double PriceOld = 0.0; 
 double PriceNow; 
 PriceNow = NormalizeDouble(Bid,6); 

 total = OrdersTotal(); 
 if(total < 1) 
 { 
    if((PriceNow-PriceOld)>=Pips*Point && (PriceNow-PriceOld)<MaxPips*Point) 
    { 
           ticket = OrderSend(Symbol(),OP_BUY,lots,Ask,slip,Bid-TS*Point,0,0,Magic,0,Green); 
           if(ticket>0) 
               { 
                  OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); 
                  Print("Ордер на покупку успешно открыт по цене:" ,OrderOpenPrice()); 
               } 
               else 
               { 
                  Print("Ордер не открыт по причине:" ,GetLastError()); 
                  return(0); 
               } 
     } 

 if((PriceNow-PriceOld)<=(-Pips)*Point && (PriceNow-PriceOld)>(-MaxPips)*Point) 
     { 
           ticket = OrderSend(Symbol(),OP_SELL,lots,Bid,slip,Ask+TS*Point,0,0,Magic,0,Red); 
           if(ticket>0) 
               { 
                  OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); 
                  Print("Ордер на покупку успешно открыт по цене:" ,OrderOpenPrice()); 
               } 
               else 
               { 
                  Print("Ордер не открыт по причине:" ,GetLastError()); 
                  return(0); 
               } 
     } 
 } 
return(0);
}