[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 232

 
drknn:


You need to programmatically request the price of the level. To do this, you must have "Fibo" object put on a chart and configured (all programmatically). It is not as easy as it may seem at first sight. However, Gods do not burn the pot. I once had to play with Fibo levels. And now I am working with processing of these levels. In general, if you want you can figure it out.

Here is an example of code to create a Fibo on a chart.

I had to make a subroutine to request the price of the level. Here it is (you can figure it out if you want to)

I.e., we should programmatically add the Fibonacci object to the Fibonacci fan and find out the price of the level only that way. Have I got it right?
 
fury2006:
In other words, we need to add the Fibonacci object to the Fibonacci vector and find out the price of the level only that way. Have I got it right?
You do not need to attach a standard Fibo object to the chart. You can simply programmatically calculate all Fibo levels considering the existing conditions,
enter them into variables or an array and compare the price with these levels calculated by yourself. That's exactly what I do... Although - all this is IMHO.
 
artmedia70:
It is not necessary to put a standard Fibo object on the chart. You can simply programmatically calculate all of the Fibo levels based on the existing conditions,
put them into variables or an array and compare the price with these levels you calculated. That's exactly what I do... Although - all this is IMHO.
Can you please write a code example?
 
fury2006:
Can you please write a code example?
It's more complicated than the one Vladimir offered you... :))
 
artmedia70:
And it's more complicated than the one Vladimir suggested... :))
I might like it better :) And besides, you don't want to have extra objects on the screen. There'll be plenty of them anyway and any unnecessary ones will just get in the way
 
fury2006:
Well, maybe I will like it better :) And besides, I don't want additional objects on the screen. There will be plenty of them there already, and any unnecessary ones will only hinder

My code is tightly bound to the data obtained by the Expert Advisor for which it was written. The function is only a part of necessary calculations and won't be of any practical value for you - only as a tutorial for self-comprehension. And that's with the rest of the code, where all the preliminary calculations are made.

If I made it universal, it would work slower, but I don't want that... :)

But you're welcome. This function was rewritten from Excel, where I checked its calculations. Two parameters are passed into it - the break of ZigZag (lower or upper, depending on type of position opened) and Price level 23.6 of the fib. The fib is not plotted as is generally accepted, but price is considered to have broken through the 23.6 fib and is above the consolidation level calculated in advance. The zero of the fib is placed on the break in ZZ, and a pose is opened on 23.6 (when it is broken). The remaining levels are written in the variables declared on the global level and subsequently entered into the array of the orders, from which levels are taken for any open position.

//=========================================================================================================
void CalcFiboLevel(double priceZZ, double price23)   // Рассчитывает уровни Фибы по нулевому и 23.6 значениям цен
{
   double A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,
          B2,B3,B4,B5,B6,B7,B8,B9,B10,B11;
   
   A2 = 0;                                      // Уровни фибы  
   A3 = 23.6;
   A4 = 38.2;
   A5 = 50.0;
   A6 = 61.8;
   A7 = 78.6;
   A8 = 100.0; 
   A9 = 161.8;  
   A10= 261.8; 
   A11= 423.6;    
   B2 = priceZZ;                                // Цена нулевого уровня фибы (нижний/верхний перелом ЗигЗага)
   B3 = price23;                                // Цена уровня 23.6 фибы (цена открытия позы)
   B4 = ((B3-B2) *(A4-A2) +(A3-A2) *B2)/(A3 -A2);
   B5 = ((B4-B3) *(A5-A3) +(A4-A3) *B3)/(A4 -A3);
   B6 = ((B5-B4) *(A6-A4) +(A5-A4) *B4)/(A5 -A4);
   B7 = ((B6-B5) *(A7-A5) +(A6-A5) *B5)/(A6 -A5);
   B8 = ((B7-B6) *(A8-A6) +(A7-A6) *B6)/(A7 -A6);
   B9 = ((B8-B7) *(A9-A7) +(A8-A7) *B7)/(A8 -A7);
   B10= ((B9-B8) *(A10-A8)+(A9-A8) *B8)/(A9 -A8);
   B11= ((B10-B9)*(A11-A9)+(A10-A9)*B9)/(A10-A9);
   
   
   Fibo38_Price  = B4;                         // ((B3-B2)*(A4-A2)+(A3-A2)*B2)/(A3-A2)
   Fibo50_Price  = B5;                         // ((B4-B3)*(A5-A3)+(A4-A3)*B3)/(A4-A3)
   Fibo61_Price  = B6;                         // ((B5-B4)*(A6-A4)+(A5-A4)*B4)/(A5-A4)
   Fibo78_Price  = B7;                         // ((B6-B5)*(A7-A5)+(A6-A5)*B5)/(A6-A5)
   Fibo100_Price = B8;                         // ((B7-B6)*(A8-A6)+(A7-A6)*B6)/(A7-A6)
   Fibo161_Price = B9;                         // ((B8-B7)*(A9-A7)+(A8-A7)*B7)/(A8-A7)
   Fibo261_Price = B10;                        // ((B9-B8)*(A10-A8)+(A9-A8)*B8)/(A9-A8)
   Fibo423_Price = B11;                        // ((B10-B9)*(A11-A9)+(A10-A9)*B9)/(A10-A9)

   return;
}

As for its usage, I would have to gut the entire Expert Advisor to understand it...

 
artmedia70:

My code is tightly attached to the data obtained by the Expert Advisor it was written for. The function is only a part of the necessary calculations and will not be of any practical value to you - just as a tutorial for self-comprehension. And that's along with the rest of the code, where all the preliminary calculations are made.

If I made it universal, it would be slower, and I don't want that... :)

But you're welcome. This function is rewritten from Excel, where I checked its calculations. Two parameters are passed to it - the break of ZigZag (lower or upper, depending on type of position opened) and Price level 23.6 of the fib. The fib is not plotted as is generally accepted, but price is considered to have broken through the 23.6 fib and is above the consolidation level calculated in advance. The zero of the fib is placed on the break in ZZ, and a pose is opened on 23.6 (when it is broken). The remaining levels are written in the variables declared on the global level and subsequently entered into the array of the orders, from which levels are taken for any open position.

As to how to use it, you should gut the entire Expert Advisor to make it clear...

That's great, you gave me an idea.
 

Hi all! Please help me combine the following things. The result should be: two lines following the price, one lower than Ask by 20 pips..,

the other one is higher. Besides, I get a beep if price changes by 20 points per 1 tick.

All works fine separately. Thanks in advance!

1) The line below the Ask by 20 pips.

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int start()
{
ObjectCreate("MyPriceLine", OBJ_HLINE, 0, 0, Ask-20*Point) ;
ObjectSet("MyPriceLine", OBJPROP_PRICE1, Ask-20*Point);
return(0);
}

//+------------------------------------------------------------------+

2) The line is 20 pips above the Ask.

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int start()
{
ObjectCreate("MyPriceLine", OBJ_HLINE, 0, 0, Ask+20*Point) ;
ObjectSet("MyPriceLine", OBJPROP_PRICE1, Ask+20*Point);
return(0);
}

//+------------------------------------------------------------------+

3) Rate of price change over time.

#property show_inputs

extern int pips=2; //изменение аск
extern double Time_=0.1; //c. ~ tick
extern bool все_из_обзора_рынка=true; // только текущий символ - false

int i, l, p, количество_символов;
string val[], на_экран;
int Ask_save[];

//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
void start(){
количество_символов=SymbolsList(val, true);//запись в массив val инструменты и их количество вызов функции SymbolsList
ArrayResize(Ask_save,количество_символов);
if(количество_символов == -1){ Alert("Ошибка открытия файла в SymbolsList(string &Symbols[], bool Selected)"); return;}
if(!все_из_обзора_рынка){
количество_символов=1;
ArrayResize(Ask_save,количество_символов);
ArrayResize(val,количество_символов);
val[0]=Symbol();
}

while(true&&!IsStopped()){ //если разрешить и не отанавливать скрипт продолжим

Alert("пересчитаем через "+Time_+" сек.");

for(i=0;i<количество_символов;i++){//посчитаем стоимость спреда для инструментов из обзора рынка
if((Ask_save[i]-MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT))>=pips){
Alert(val[i]+","+Period()+" изменился вниз на "+DoubleToStr((Ask_save[i]-MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT)),0)+" pips");
PlaySound("timeout.wav");
}
if((MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT)-Ask_save[i])>=pips){
Alert(val[i]+","+Period()+" изменился вверх на "+DoubleToStr((MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT)-Ask_save[i]),0)+" pips");
PlaySound("email.wav");
}
Ask_save[i]=MarketInfo(val[i],MODE_ASK)/MarketInfo(val[i],MODE_POINT);
}
Sleep(Time_*1000);//пауза сек.
}

/*
количество_символов=SymbolsList(val, true);//запись в массив val инструменты и их количество вызов функции SymbolsList
if(количество_символов == -1){ Alert("Ошибка открытия файла в SymbolsList(string &Symbols[], bool Selected)"); return;}

while(true&&!IsStopped()){ //если разрешить и не отанавливать скрипт продолжим
на_экран="\r\n"; //отступ
for(i=0;i<количество_символов;i++)//посчитаем стоимость спреда для инструментов из обзора рынка
на_экран=на_экран+val[i]+" стоимость спреда = " + DoubleToStr(MarketInfo(val[i],MODE_SPREAD)*MarketInfo(val[i],MODE_TICKVALUE),0)+"\r\n";
Comment(на_экран);//выведем на экран
Alert("Пересчитаем");//сигнал
Sleep(3000);//пауза 3 сек.
}
*/
}
void deinit(){Comment("");}
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=


//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
// функция читает из обзора рынка все фин.инстр.
//+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
int SymbolsList(string &Symbols[], bool Selected){
int Offset, SymbolsNumber; string SymbolsFileName;
if(Selected) SymbolsFileName = "symbols.sel"; else SymbolsFileName = "symbols.raw";
int hFile = FileOpenHistory(SymbolsFileName, FILE_BIN|FILE_READ);
if(hFile < 0) return(-1); if(Selected) { SymbolsNumber = (FileSize(hFile) - 4) / 128; Offset = 116; }
else { SymbolsNumber = FileSize(hFile) / 1936; Offset = 1924; }
ArrayResize(Symbols, SymbolsNumber);
if(Selected) FileSeek(hFile, 4, SEEK_SET);
for(int i = 0; i < SymbolsNumber; i++){Symbols[i] = FileReadString(hFile, 12); FileSeek(hFile, Offset, SEEK_CUR);}
FileClose(hFile);
return(SymbolsNumber);
}
 

Can you please explain why this code sometimes freezes in one place and you have to restart the terminal to resume it?

int ticket,err;
         Alert("nachalo");
         ticket = OrderSend(Symbol (), OP_BUY, 1, Ask, 10,0,0, "dsgdsf", 0, 0, CLR_NONE);
         err = GetLastError();
         Alert (err);
         Alert("konec");
         OrderClose (ticket,1,Bid,5,CLR_NONE);
         Alert ("zakrito");
 
globad:

Hi all! Please help me combine the following things. The result should be: two lines following the price, one lower than Ask by 20 pips..,

the other one is higher. Besides, I get a beep if price changes by 20 points per 1 tick.

All works fine separately. Thanks in advance!

1) The line below the Ask by 20 pips.

2) The line is 20 pips above the Ask.

3) Rate of price change over time.


Seems to be boring already... It's elementary, Watson:

ObjectCreate("MyPriceLine", OBJ_HLINE, 0, 0, Ask-20*Point) ;

It's the name of a single line.

Hint: look up the name of the second line. Is it different from the first?

Yes, and why keep building an already-built facility?

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int start()
{
ObjectCreate("MyPriceLine", OBJ_HLINE, 0, 0, Ask+20*Point) ;
ObjectSet("MyPriceLine", OBJPROP_PRICE1, Ask+20*Point);
return(0);
}

//+------------------------------------------------------------------+

Now look at the difference:

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int start()
{
if (ObjectFind("MyPriceLine")<0) ObjectCreate("MyPriceLine", OBJ_HLINE, 0, 0, Ask+20*Point) ;
ObjectSet("MyPriceLine", OBJPROP_PRICE1, Ask+20*Point);
return(0);
}

//+------------------------------------------------------------------+