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

 
Craft:

Good afternoon, continuing to get to grips with coding, took the example EA from the tutorial section article, replaced the code from the example:

To an arbitrary one for training purposes:

The trades don't show up, could you please tell me what's the reason, how to fix the code.


double MA_1[]; // нет обьявления размера, не видно как (локально или глобально) обьявлен, 
// не видно оператора двигающего индекс массива.
// лучше пока не освоили работу с массивами обьявите переменные и не парьтесь

  double MA_0=iMA(NULL,0,Period_MA,0,MODE_EMA,PRICE_CLOSE,0);
  double MA_1=iMA(NULL,0,Period_MA,0,MODE_EMA,PRICE_CLOSE,1);
  
  if (MA_1 < MA_0)
     {                                          // ..МА последнего бара выше предыдущего
      Opn_B=true;                               // Критерий откр. Buy
      Cls_S=true;                               // Критерий закр. Sell
     }
   if (MA_1 > MA_0)
     {                                          // ..МА последнего бара ниже предыдущего
      Opn_S=true;                               // Критерий откр. Sell
      Cls_B=true;                               // Критерий закр. Buy
     }
 

Urain, thank you, I never cease to be amazed at the logic of mql, and if you try to use for(int i=1; to try, the script will not simplify - could you tell me how to format it, I cannot yet feel the logic of the language, how to define the operator that moves the array?

P. S. I declared the array, by mistake in the example script has removed:

   double MA_1[];
   ArrayResize(MA_1,Period_MA);

   MA_1[0]=iMA(NULL,0,Period_MA,0,MODE_EMA,PRICE_CLOSE,0);

   if (MA_1[1] < MA_1[0])
     {                                          // 
      Opn_B=true;                               // Критерий откр. Buy
      Cls_S=true;                               // Критерий закр. Sell
     }
   if (MA_1[1] > MA_1[0])
     {                                          // 
      Opn_S=true;                               // Критерий откр. Sell
      Cls_B=true;                               // Критерий закр. Buy
     }
 
Abzasc:
Differences in prices. As a consequence, different, to the contrary, indicator results...
I don't see anything different there. Forget the indicators, once again, the right one for you is the one you're trading on. You're not concentrating on the right one at all.
 
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 blue
#property indicator_color2 Red

extern int n = 20;
extern int t3_period = 5;
extern double b = 0.618;
extern int mBars = 300;
extern int Bars.Count = 0;
int i,t,c;
double Buf1[],Buf2[],CF_p[5001],CF_n[5001],Ch_p[5001],Ch_n[5001],k_n,k_p,ch_p,ch_n,cff_p,cff_n,
AcBars,t3,t32,A1,A2,b2,b3,c1,c2,c3,c4,e1,e2,e3,e4,e5,e6,n1,w1,w2,e12,e22,e32,e42,e52,e62;


//+------------------------------------------------------------------+
int init() {
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, Buf1);
SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, Buf2);
return(0); }
//+------------------------------------------------------------------+
int start() {
int limit;
if (IndicatorCounted()<0) return(-1);
limit=Bars-IndicatorCounted();
if (Bars.Count>0 && limit>Bars.Count) limit=Bars.Count;
for(int i=0; i<limit; i++)
{

b2=b*b; b3=b2*b; c1=-b3; c2=(3*(b2+b3)); c3=-3*(2*b2+b3); c4=(1+3*b+b3+3*b2); n1=t3_period;

if(n1<1) n1=1; n1=1+0.5*(n1-1); w1=2/(n1+1); w2=1-w1;

if(AcBars==0) AcBars=Bars-mBars;

for(c=AcBars; c<=Bars-1; c +++) { i=Bars-1-c; {

if(Close[i]>Close[i+1]) { Ch_p[i]=Close[i]-Close[i+1]; CF_p[i]=Ch_p[i]+CF_p[i+1]; Ch_n[i]=0; CF_n[i]=0; }
else { Ch_p[i]=0; CF_p[i]=0; Ch_n[i]=Close[i+1]-Close[i]; CF_n[i]=Ch_n[i]+CF_n[i+1]; }}

for(t=i+n; t>=i; t--) { ch_p=Ch_p[t]+ch_p; ch_n=Ch_n[t]+ch_n ; cff_p=CF_p[t]+cff_p; cff_n=CF_n[t]+cff_n; }

k_p=ch_p-cff_n; k_n=ch_n-cff_p;

A1=k_p; e1=w1*A1+w2*e1; e2=w1*e1+w2*e2; e3=w1*e2+w2*e3; e4=w1*e3+w2*e4;
e5=w1*e4+w2*e5; e6=w1*e5+w2*e6; t3=c1*e6+c2*e5+c3*e4+c4*e3; Buf1[i]=t3;

A2=k_n; e12=w1*A2+w2*e12; e22=w1*e12+w2*e22; e32=w1*e22+w2*e32; e42=w1*e32+w2*e42;
e52=w1*e42+w2*e52; e62=w1*e52+w2*e62; t32=c1*e62+c2*e52+c3*e42+c4*e32; Buf2[i]=t32;

AcBars=AcBars+1; ch_p=0; ch_n=0; cff_p=0; cff_n=0; }
}

return(0); }


Can you tell me where the error is not updating, the history is normal and the online one is not

Files:
 

Good afternoon. An array has been declared, the operator that moves the array index has been set, but the orders are not being placed. Please tell me what is wrong.

   double MA_1[];
   ArrayResize(MA_1,Period_MA);

   for(int j=0;j<=Period_MA-1;j++)
   MA_1[j]=iMA(NULL,0,Period_MA,0,MODE_EMA,PRICE_CLOSE,j);

   
   if (MA_1[j+1] < MA_1[j])
     {                                          // 
      Opn_B=true;                               // Критерий откр. Buy
      Cls_S=true;                               // Критерий закр. Sell
     }
   if (MA_1[j+1] > MA_1[j])
     {                                          // 
      Opn_S=true;                               // Критерий откр. Sell
      Cls_B=true;                               // Критерий закр. Buy
     }
 

TryOrderSend, then it works...

Have you read the standard MetaEditore helper? If not, read the whole...

Craft:

Good afternoon. I have declared an array and defined the operator that moves the array index, but the orders are not placed. Please, advise what is wrong.

 
Can you guys tell me if it's possible to rewrite Igor Kim's function, which closes all losing orders, whose loss exceeds a certain value:
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 25.04.2008                                                     |
//|  Описание : Закрытие тех позиций, у которых убыток в валюте депозита       |
//|             превысил некоторое значение                                    |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//|    pr - профит/убыток                                                      |
//+----------------------------------------------------------------------------+
void ClosePosBySizeLossInCurrency(string sy="", int op=-1, int mn=-1, double pr=0) {
  int i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=k-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) {
            if (OrderProfit()+OrderSwap()<-MathAbs(pr)) ClosePosBySelect();
          }
        }
      }
    }
  }
}
I need to find one open position that has the largest loss.
The point is that I need to find the position with more profit than the losing one and close them in counter-close.
Maybe someone has some experience with this, or has faced such a problem?
 
Why can't three indicators based on different principles show almost the same picture (spearman, stochastic, and mcdrsy) - but can't show the right movement and entry with a probability above 60%?
 
Hi there, I am wondering what code is needed to close an order after it has passed point X in profit and has started to go down to point Y>OrderOpenPrice and then needs to close it.
 
StatBars:

Try OrderSend, then it works...

Have you read the standard MetaEditore helper? If not, read it all...


Of childish age to ask a question without having addressed to help and yandex have grown. There are a lot of Sends, but the positions do not open:

double MA_1[];
   ArrayResize(MA_1,Period_MA);

   for(int j=0;j<=Period_MA-1;j++)
   MA_1[j]=iMA(NULL,0,Period_MA,0,MODE_EMA,PRICE_CLOSE,j);

   
   if (MA_1[j+1] < MA_1[j])
     {                                          // 
      Opn_B=true;                               // Критерий откр. Buy
      Cls_S=true;                               // Критерий закр. Sell
     }
   if (MA_1[j+1] > MA_1[j])
     {                                          // 
      Opn_S=true;                               // Критерий откр. Sell
      Cls_B=true;                               // Критерий закр. Buy
     }
   // Открытие ордеров
   while(true)                                  // Цикл закрытия орд.
     {
      if (Total==0 && Opn_B==true)              // Открытых орд. нет +
        {                                       // критерий откр. Buy
         RefreshRates();                        // Обновление данных
         SL=Bid - New_Stop(StopLoss);     // Вычисление SL откр.
         TP=Bid + New_Stop(TakeProfit);   // Вычисление TP откр.
         Alert("Попытка открыть Buy. Ожидание ответа..");
         Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,SL,TP);//Открытие Buy
         if (Ticket > 0)                        // Получилось :)
           {
            Alert ("Открыт ордер Buy ",Ticket);
            return;                             // Выход из start()
           }
         if (Fun_Error(GetLastError())==1)      // Обработка ошибок
            continue;                           // Повторная попытка
         return;                                // Выход из start()
        }
      if (Total==0 && Opn_S==true)              // Открытых орд. нет +
        {                                       // критерий откр. Sell
         RefreshRates();                        // Обновление данных
         SL=Ask + New_Stop(StopLoss);     // Вычисление SL откр.
         TP=Ask - New_Stop(TakeProfit);   // Вычисление TP откр.
         Alert("Попытка открыть Sell. Ожидание ответа..");
         Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,SL,TP);//Открытие Sel
         if (Ticket > 0)                        // Получилось :)
           {
            Alert ("Открыт ордер Sell ",Ticket);
            return;                             // Выход из start()
           }
         if (Fun_Error(GetLastError())==1)      // Обработка ошибок
            continue;                           // Повторная попытка
         return;                                // Выход из start()
        }
      break;                                    // Выход из while
     }
Reason: