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

 

Help me add, Horizintal shift
and vertical shift
If it also works..........cloud

//+------------------------------------------------------------------+
//|                                                Price Channel.mq4 |
//+------------------------------------------------------------------+



#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 DodgerBlue
//---- input parameters
extern int ChannelPeriod = 14;
//---- buffers
double UpBuffer[];
double DnBuffer[];
double MdBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(0, UpBuffer);
   SetIndexBuffer(1, DnBuffer);
   SetIndexBuffer(2, MdBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="Price Channel("+ChannelPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0, "UpCh");
   SetIndexLabel(1, "DownCh");
   SetIndexLabel(2, "MidCh");
//----
   SetIndexDrawBegin(0, ChannelPeriod);
   SetIndexDrawBegin(1, ChannelPeriod);
   SetIndexDrawBegin(2, ChannelPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Price Channel                                                         |
//+------------------------------------------------------------------+
int start()
  {
   int i, counted_bars = IndicatorCounted();
   int    k;
   double high, low, price;
//----
   if(Bars <= ChannelPeriod) 
       return(0);
//---- initial zero
   if(counted_bars < 1)
      for(i = 1;i <= ChannelPeriod; i++) 
          UpBuffer[Bars-i] = 0.0;
//----
   i = Bars - ChannelPeriod - 1;
   if(counted_bars >= ChannelPeriod) 
       i = Bars - counted_bars - 1;
   while(i >= 0)
     {
       high = High[i]; 
       low = Low[i]; 
       k = i - 1 + ChannelPeriod;
       while(k >= i)
         {
           price = High[k];
           if(high < price) 
               high = price;
           price = Low[k];
           if(low > price)  
               low = price;
           k--;
         } 
       UpBuffer[i] = high;
       DnBuffer[i] = low;
       MdBuffer[i] = (high + low) / 2;
       i--;
     }
   return(0);
  }
//+------------------------------------------------------------------+
 
splxgf >>:

Можно сделать горячий старт сразу в

init(){

while (true) {

//Вечный кайф

}

Thanks splxgf. I tried, but ... Well, I guess I'll have to leave this venture until better times. Or maybe someone else will show interest in this, in my opinion, useful refinement of many experts.

 
hedger писал(а) >>

Thanks splxgf. I tried, but ... Well, I guess I'll have to leave this venture until better times. And maybe someone else will show interest in this, in my opinion, useful refinement of many experts.


see how it should be done
int start()
{
while(true)
{
Sleep(5000); // 5 seconds delay until next iteration
RefreshRates(); // Refresh data
// rest of the code. Conditions to open, close, etc.
}
}
 
Djonon >>:

ПОмогите добавить, Сдвиг по горозинтали
и вертикали
Если ещё и работать бутет..........клювоо

extern int Сдвиг_по_горозинтали = 14; //КОЛ-ВО БАРОВ
extern int и_вертикали = 14; //КОЛ-ВО ПУНКТОВ
Files:
 
hedger >>:

Для закрытия ордеров я пользуюсь советником JimsCloseOrders, который может закрывать любые ордера по выбору – или профитные, или убыточные, или все подряд, правда пришлось его немного подкорректировать - вот в этих двух строках кода

extern bool CloseOpenOrders = true;

extern bool CloseOrdersWithPlusProfit = false;

false и true надо поменять местами, иначе, если такую настройку выполнять при установке на график, почему-то начинает закрывать все ордера (видимо из-за последовательности выполнения команд программой, но не уверен, не спец).

У меня вопрос к профи.

Требуется, как можно быстрее запустить, например, советника, о котором шла речь выше, но все советники и скрипты начинают действовать с момента поступления первого тика на график. Если же выбранная для установки советника валютная пара оказалась не очень "активной" в этот момент, то потери могут быть значительными.

Существует ли возможность создания "общего" графика для всех валют, или воспользоваться поступающим тикам любой другой пары? Тики же в терминал поступают почти непрерывно. Где их можно перехватить?

It's simple in

int init()
  {
    трали вали..
    start();
  }
When initialising, immediately execute the function
start();
See also tick emulation but that's not it ...

start() is the main function. In Expert Advisors it is called after the next tick. For custom indicators it is called during recalculation after attaching the indicator to the chart, at opening of the client terminal (if the indicator is attached to the chart), as well as after the coming of the next tick. In scripts it is executed immediately after attaching to the chart and initialization. If there is no start() function in the module, this module (Expert Advisor, script or custom indicator) cannot be launched.
 
int start()
{
double bid =MarketInfo("GBPUSD",MODE_BID);
double ask =MarketInfo("GBPUSD",MODE_ASK);
double point =MarketInfo("GBPUSD",MODE_POINT);
OrderSend("GBPUSD",OP_BUY,0.01,ask,2,bid-15*Point,bid+15*Point);
return;
}

I took this script from the tutorial; I wanted to see how it worked; I compiled and saved it. When I run it, it fails, why?
It doesn't give me any errors, it just doesn't work...
 
Gentlemen. Good evening, everyone. I'm having absolutely no luck at all in mastering the language. (((((((
I try to rewrite something out of heaps of Expert Advisors, but when I need to write something concrete, I feel dumb...(((
And now...
I would like to make the following line in Expert Advisor:
I have an algorithm of opening, I have profit, and I want it to close after a certain time, no matter what the result will be,
- this is how to add it now?????????
I want to be able to set this time in Expert Advisor. For example, I want the deal to close itself after two, three or four hours... Depending on news release time for example. I think you understand what I mean.
If someone knows, maybe such questions have already been asked on the forum, at least give me the link. Tried to read the textbook, one only nerves, written for advanced programmers, well, certainly not for the ladies.
And if someone is not difficult and it seems a trifle, then write the lines, I at least glue them, then maybe something will work.
A big female please.......
 
Magiyanka >>:
Господа. Всем добрый вечер. У меня прям совсем ничего не получается в освоении языка. (((((((

extern int Час=2; //В начало кода
extern int Мин=6;
extern int Slippage  =  25;
extern int STUPID= 12830454;
//В конец кода отдельной функцией
//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж
void  OrdersCloseByTime(int MagicNumber)
{
   for(int i = 0; i < OrdersTotal(); i++)
   {
      // already closed
      if(OrderSelect(i, SELECT_BY_POS,MODE_TRADES ) == false) continue;
      // not current symbol
      if(OrderSymbol() != Symbol()) continue;
      // order was opened in another way
      if(OrderMagicNumber() != MagicNumber) continue;
      if(Time[0]-OrderOpenTime( )>=Час*60*60+Мин*60){
        if(OrderType() == OP_SELL)
        OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask,Digits), Slippage, Red);
        if(OrderType() == OP_BUY)
        OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid,Digits), Slippage, Blue);
        }
   }
   
}
//жжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжжж
int start()
{
 OrdersCloseByTime(STUPID);//STUPID это мажик номер Вашего советчика
 трали вали ...
Closing time positions, where would you put it so it doesn't get lost?!
 
Lim1 >>:

int start()
{
double bid =MarketInfo("GBPUSD",MODE_BID);
double ask =MarketInfo("GBPUSD",MODE_ASK);
double point =MarketInfo("GBPUSD",MODE_POINT);
OrderSend("GBPUSD",OP_BUY,0.01,ask,2,bid-15*Point,bid+15*Point);
Alert (GetLastError());
return;
}

Взял этот скрипт из учебника, хотел посмотреть как он работает - скомпилировал, сохранил. Запускаю - безрезультатно, почему?
Ошибок не выдает, просто не работает...

Try it this way.

int start()
{
double bid =MarketInfo("GBPUSD",MODE_BID);
double ask =MarketInfo("GBPUSD",MODE_ASK);
double point =MarketInfo("GBPUSD",MODE_POINT);
int tickkkkkkk=OrderSend("GBPUSD",OP_BUY,1,ask,2,bid-15*Point,bid+15*Point);
if(tickkkkkkk==-1){
 Alert ("Ошибка № "+GetLastError());
 if(GetLastError()==131)
 Alert ("Неправильный объем");
 if(GetLastError()==6)
 Alert ("Нет связи с торговым сервером");
 }
 else Alert ("Все ОК!!!");
return;
}
 
it doesn't work, it doesn't close on time and that's it