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

 

Friends, help please!!! I cannot write a code that would open a buy if the price goes from the bottom to the top of a certain level, sell the opposite. exactly where the price comes from. is it hard???

 
petrostlt:

Friends, please help!!! I cannot write a code that would open a buy if the price goes from the bottom to the top of a certain level, and for sell - vice versa. I can't decide if the price comes from the bottom or the top.

Many variations are possible.

For example:

 double price1 = iClose(NULL,0,1);           // Цена закрытия последнего сформированного бара
 double price2 = iClose(NULL,0,2);           // Цена закрытия второго (предпоследнего) бара 
 double Level = 1.7658;                      // Какой-то уровень
 
 if(price1>Level && price2<Level)OrderSend(Symbol(),OP_BUY,......); // Если цена на предпоследнем баре была ниже уровня, 
                                                                    // а на последнем выше, то покупаем...
 if(price1<Level && price2>Level)OrderSend(Symbol(),OP_SELL,......);
 
DhP:

Many variations are possible.

For example:

double price1 = iClose(NULL,0,1);           // Цена закрытия последнего сформированного бара
 double price2 = iClose(NULL,0,2);           // Цена закрытия второго (предпоследнего) бара 
 double Level = 1.7658;                      // Какой-то уровень
 
 if(price1>Level && price2<Level)OrderSend(Symbol(),OP_BUY,......); // Если цена на предпоследнем баре была ниже уровня, 
                                                                    // а на последнем выше, то покупаем...
 if(price1<Level && price2>Level)OrderSend(Symbol(),OP_SELL,......);

What if one of the prices is equal to Level ?

What about the zero bar? It is the very first one. But it has not been formed yet. You confuse the person. Then it is like this:

//----------------------------------------------------------------------------------------
int    dg=MarketInfo(Symbol(),MODE_DIGITS);
double price1 = iClose(NULL,0,1);           // Цена закрытия первого бара
double price2 = iClose(NULL,0,2);           // Цена закрытия второго бара 
double Level = 1.7658;                      // Какой-то уровень
 
   if (NormalizeDouble(price1-Level,dg)>0 && NormalizeDouble(Level-price2,dg)>=0) {
      // ... код открытия позиции Бай ...
      }
   if (NormalizeDouble(Level-price1,dg)>0 && NormalizeDouble(price2-Level,dg)>=0) {
      // ... код открытия позиции Селл ...
      }
//----------------------------------------------------------------------------------------
 
artmedia70:

What if one of the prices is equal to Level ?

What about the zero bar? It is the very first one. Only it is not yet formed. You confuse the subject. Then it is like this:



Again.

There are very(!) many variations.

By the way, the zero bar is not the first one. It is zero, i.e. it is not there yet.

 
goodnight! I suddenly found a bunch of folders on my C drive and some kind of C++, decided to install, and it's asking me something!!! I'm not good at English, no, I vaguely understood that either the original in the sense of some original version, or something there my computer and did not install for some reason ... In short, it is not clear.
 
Dimka-novitsek:
Goodnight! I suddenly found a bunch of folders and some C++ on my C drive, decided to install it, and it's asking me for something!!! I'm not good at English, no, I vaguely understood that either the original in the sense of some original version, or something there my computer and do not install for some reason ... In short, I do not understand.

Select one of the options:

Repair - "repair"/restore Visual C++ 2008

Uninstall - remove Visual C++ 2008 from your computer

 
artmedia70:

What if one of the prices is equal to Level ?

What about the zero bar? It is the very first one. Only it is not yet formed. You confuse the subject. Then put it this way:

It makes no sense to normalize the double values to compare them since the two values 1.778946 and 1.778949 will be equal after normalization and this is incorrect since the first value is smaller than the second one.

Normalize double is only needed to send a command to the Dealer, but not for "internal consumption" - comparison of the two values.

 
Got it!!! Thanks a lot!!!!Good thing you asked!!!
 
Dimka-novitsek:
Got it!!! Thanks a lot!!!!Good thing you asked!!!
Always at your service...))
 
Thank you very much for responding!!!!!!! I'll give it a try. THANKS )))))
Reason: