Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам - страница 2578

 
Andrei Sokolov #:

При частичном закрытии можно комментарий задавать?

ты можешь частично закрывать встречкой 

То есть открываешь встречную позицию меньшим объёмом с нужным коментом и об неё частично закрываешь через closeBy

(к слову - при наличии возможности, лучше вообще все входы лимитками а все закрытия closeBy)

 
Maxim Kuznetsov #:

ты можешь частично закрывать встречкой 

То есть открываешь встречную позицию меньшим объёмом с нужным коментом и об неё частично закрываешь через closeBy

(к слову - при наличии возможности, лучше вообще все входы лимитками а все закрытия closeBy)

Спасиб. А чем closeBy лучше?

 
Andrei Sokolov #:

Спасиб. А чем closeBy лучше?

входы лимитками - лимитки меньше проскальзывают, то есть берут цену точнее и вообще это ближе к нормальной торговле. Подчас (на крипте например) и комиссии меньше

а закрытия closeBy экономят 1 спред при закрытии встречных позиций (взаимозачёт происходит)

..

вообще можно закрывать позы единственный раз в день - вечером..небольшой личный клиринг - взаимозакрытия встречных 

 
Tretyakov Rostyslav #:
Спасибо большое Ростислав - залил к себе в робота - всё работает ок!
Данные с индика считывает! Формирую торговые сигналы!!!
 
Vitaly Muzichenko #:

нужны фигурные скобки

Скобки я поменял, а ошибка " 'aaa_1111' - some operator expected ", осталась.
 
Igor Nagorniuk #:
Скобки я поменял, а ошибка " 'aaa_1111' - some operator expected ", осталась.

Измените также имя переменной, только цифры не пропускает

 
Здравствуйте! При добавление индикатора на график совершенно рандомным образом начинают пропадать линии или отрисовываться не до конца. В чем может быть проблема? Брал стандартный индикатор аллигатор + сверху на синюю линию наложил две МА
Код: 
//+------------------------------------------------------------------+
//|                                                    Alligator.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 5
#property indicator_buffers 10

#property indicator_type1   DRAW_COLOR_LINE
#property indicator_color1 clrBlue,clrNONE
#property indicator_width1  1
#property indicator_label1 "Jaws"

#property indicator_type2   DRAW_COLOR_LINE
#property indicator_color2 clrRed
#property indicator_width2  1
#property indicator_label2 "Teeth"

#property indicator_type3   DRAW_COLOR_LINE
#property indicator_color3 clrLime
#property indicator_width3  1
#property indicator_label3 "Lips"

#property indicator_type4   DRAW_COLOR_LINE
#property indicator_color4 clrSeaGreen
#property indicator_width4  1
#property indicator_label4 "BuyLine"

#property indicator_type5   DRAW_COLOR_LINE
#property indicator_color5 clrPink
#property indicator_width5  1
#property indicator_label5 "SellLine"
double ExtJaws[];
double ExtColorJaws[];

double ExtTeeth[];
double ExtColorTeeth[];

double ExtLips[];
double ExtColorLips[];

double ExtBuyCr[];
double ExtClrBuyCr[];

double ExtSellCr[];
double ExtClrSellCr[];
//---- input parameters
input int                InpJawsPeriod=13;               // Jaws period
input int                InpJawsShift=8;                 // Jaws shift
input int                InpTeethPeriod=8;               // Teeth period
input int                InpTeethShift=5;                // Teeth shift
input int                InpLipsPeriod=5;                // Lips period
input int                InpLipsShift=3;                 // Lips shift
input ENUM_MA_METHOD     InpMAMethod=MODE_SMMA;          // Moving average method
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_MEDIAN;   // Applied price
//---- indicator buffers
//---- handles for moving averages
int    ExtJawsHandle;
int    ExtTeethHandle;
int    ExtLipsHandle;

int ExtBuyCRHandle;
//--- bars minimum for calculation
int    ExtBarsMinimum;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  SetIndexBuffer(0,ExtJaws,INDICATOR_DATA);
  SetIndexBuffer(1,ExtColorJaws,INDICATOR_COLOR_INDEX);
  
  SetIndexBuffer(2,ExtTeeth,INDICATOR_DATA);
  SetIndexBuffer(3,ExtColorTeeth,INDICATOR_COLOR_INDEX);  
  
  SetIndexBuffer(4,ExtLips,INDICATOR_DATA);
  SetIndexBuffer(5,ExtColorLips,INDICATOR_COLOR_INDEX);
  
  SetIndexBuffer(6,ExtBuyCr,INDICATOR_DATA);
  SetIndexBuffer(7,ExtClrBuyCr,INDICATOR_COLOR_INDEX);  
  
  SetIndexBuffer(8,ExtSellCr,INDICATOR_DATA);
  SetIndexBuffer(9,ExtClrSellCr,INDICATOR_COLOR_INDEX);    
//--- indicator buffers mapping
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpJawsPeriod-1);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpTeethPeriod-1);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpLipsPeriod-1);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,InpJawsPeriod-1);
   PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,InpJawsPeriod-1);
//---- line shifts when drawing
   PlotIndexSetInteger(0,PLOT_SHIFT,InpJawsShift);
   PlotIndexSetInteger(1,PLOT_SHIFT,InpTeethShift);
   PlotIndexSetInteger(2,PLOT_SHIFT,InpLipsShift);
   PlotIndexSetInteger(3,PLOT_SHIFT,InpJawsShift);
   PlotIndexSetInteger(4,PLOT_SHIFT,InpJawsShift);
//---- name for DataWindow
   PlotIndexSetString(0,PLOT_LABEL,"Jaws("+string(InpJawsPeriod)+")");
   PlotIndexSetString(1,PLOT_LABEL,"Teeth("+string(InpTeethPeriod)+")");
   PlotIndexSetString(2,PLOT_LABEL,"Lips("+string(InpLipsPeriod)+")");
   PlotIndexSetString(3,PLOT_LABEL,"Buy Line("+string(InpJawsPeriod)+")");
   PlotIndexSetString(4,PLOT_LABEL,"Sell Line("+string(InpJawsPeriod)+")");
//--- get MA's handles
   ExtJawsHandle=iMA(NULL,0,InpJawsPeriod,0,InpMAMethod,InpAppliedPrice);   
   ExtTeethHandle=iMA(NULL,0,InpTeethPeriod,0,InpMAMethod,InpAppliedPrice);
   ExtLipsHandle=iMA(NULL,0,InpLipsPeriod,0,InpMAMethod,InpAppliedPrice);
     
ExtBarsMinimum=InpJawsPeriod+InpJawsShift;   
   if(ExtBarsMinimum<(InpTeethPeriod+InpTeethShift))
      ExtBarsMinimum=InpTeethPeriod+InpTeethShift;
   if(ExtBarsMinimum<(InpLipsPeriod+InpLipsPeriod))
      ExtBarsMinimum=InpLipsPeriod+InpLipsPeriod;      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
//--- check for rates total
   if(rates_total<ExtBarsMinimum)
      return(0); // not enough bars for calculation
//--- not all data may be calculated
   int calculated=BarsCalculated(ExtJawsHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtJawsHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
   calculated=BarsCalculated(ExtTeethHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtTeethHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }     
   calculated=BarsCalculated(ExtLipsHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtLipsHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
      }       
//--- we can copy not all data
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
//---- get ma buffers
   if(CopyBuffer(ExtJawsHandle,0,0,to_copy,ExtJaws)<=0)
     {
      Print("getting ExtJawsHandle is failed! Error",GetLastError());
      return(0);
     }     
   if(CopyBuffer(ExtTeethHandle,0,0,to_copy,ExtTeeth)<=0)
     {
      Print("getting ExtTeethHandle is failed! Error",GetLastError());
      return(0);
     }     
   if(CopyBuffer(ExtLipsHandle,0,0,to_copy,ExtLips)<=0)
     {
      Print("getting ExtLipsHandle is failed! Error",GetLastError());
      return(0);
     }   
//Width +1
   if(CopyBuffer(ExtJawsHandle,0,0,to_copy,ExtBuyCr)<=0)
     {
      Print("getting ExtJawsHandle is failed! Error",GetLastError());
      return(0);
     }          
   if(CopyBuffer(ExtJawsHandle,0,0,to_copy,ExtSellCr)<=0)
     {
      Print("getting ExtJawsHandle is failed! Error",GetLastError());
      return(0);
     }       
      int limit,bar;

      //---- объявления локальных переменных
      //---
      if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of the indicator calculation
        {
         limit=rates_total-ExtBarsMinimum; // starting index for calculating all bars
        }
      else
        {
         limit=rates_total-prev_calculated; // starting index for calculating new bars
        }
        
      for(bar=limit; bar>=0 && !IsStopped();bar--)
        {
        if(ExtLips[bar+1+4]>ExtJaws[bar+1+4] && ExtTeeth[bar]<ExtJaws[bar]){
        ExtColorJaws[bar]=1.0;
        ExtClrBuyCr[bar]=1.0;
        }
        else if(ExtLips[bar+1+4]<ExtJaws[bar+1+4] && ExtTeeth[bar]>ExtJaws[bar]){
       ExtColorJaws[bar]=1.0;
       ExtClrSellCr[bar]=1.0;
        }
        else {ExtColorJaws[bar]=0.0;
       ExtClrSellCr[bar]=0.0;
       ExtClrBuyCr[bar]=0.0;}
        
        }      
     
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
проблема во вложениях
Файлы:
 
W1nd ReD #:
Здравствуйте! При добавление индикатора на график совершенно рандомным образом начинают пропадать линии или отрисовываться не до конца. В чем может быть проблема? Брал стандартный индикатор аллигатор + сверху на синюю линию наложил две МА
Код:  проблема во вложениях

Посмотрите что в буферах на тех участках, где, по по вашему, мнению должна быть отрисовка. Обычно, посмотреть можно через окно данных.

Возможно, это даст понимание к направлению поиска проблемы.

 
Maxim Kuznetsov #:
а закрытия closeBy экономят 1 спред при закрытии встречных позиций (взаимозачёт происходит)

Так это понятно. Я думал срабатывает как-то лучше.

 
Andrei Sokolov #:

Посмотрите что в буферах на тех участках, где, по по вашему, мнению должна быть отрисовка. Обычно, посмотреть можно через окно данных.

Возможно, это даст понимание к направлению поиска проблемы.

Данные в окне данных есть, но отрисовки красной и зеленой линии - иногда пропадают(А данные не пропали)