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

 
1Rakso >> :

1) And how do you make it disabled, through external variables?

2) Can I set it in such a way that the first order opened is closed upon opening, and the subsequent orders 2, 3, etc. are not closed? Suppose I open a Buy order - this is the first order, then I open another Buy order - the second one, etc. and then out of this series of orders only the 1st order would be closed by СorderClose ?

Check the address pages at https://www.mql5.com/ru/forum/105913

1) Approximately like this -

extern bool      AutoClose = True;
.......................................


//********* Закрытие позиций ****************************************
if ( AutoClose) {  
//----переменные для закрытия позиций ----
double Stochast_0 =iStochastic(NULL,0, Stochastic_period,3,3,MODE_SMA,0,MODE_MAIN,0);
double Stochast_1 =iStochastic(NULL,0, Stochastic_period,3,3,MODE_SMA,0,MODE_MAIN,1);
//----------------------------------------------------------------------
  for (int v=0; v<OrdersTotal(); v++)                             {       
      if (OrderSelect( v, SELECT_BY_POS, MODE_TRADES))               {           
        if (OrderSymbol()==Symbol()&& OrderMagicNumber()== MagicNum)   { 
//-----------------------------------------------------                  
if (OrderType() == OP_BUY) { 
      if( Stochast_1>75 && Stochast_0<75)     {
           OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // закрываем позицию
                // return(0); // выходим
                }       
     }  
 //--------------------------------------------------------
if (OrderType() == OP_SELL) { 
      if( Stochast_1<25 && Stochast_0>25)    {
                 OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // закрываем позицию
                // return(0); // выходим
                }       
     }  
 //-------------------------------------------------------                       
    }  // Symbol()  
  } // select
 } //total
} //Close_

2)

Remove the lock ( // ) before

// return(0); // exit

and then only the first(or last) position would be closed.

 
PyMbIH >> :

Hello, everyone ))))

Help.

I just started to program mql4.

Writing an Expert Advisor.

How to do this.

I want my Expert Advisor to work only on Mondays.

//Открытие и закрытие  позиций только в понедельник  
      if (TimeDayOfWeek(TimeCurrent()) == 1)
         return (0);  
 
rid писал(а) >>

>> thank you!

 
Vinin >> :

Thank you, Vinin =)

 
rid >> :

Look through the 'Closing Positions. On indicator signal'.

1) Approximately like this -

2)

Remove the blocking ( // ) before

// return(0); // exit

and then only the first positions will be closed.

Thanks, rid!

You helped me a lot, there are still kind people)

Got it all, I'll go read the math, I hope I didn't take up too much of your time)

 

Please help.

If during the visual testing of the EA 1.mq4 (attached) I put on a chart the indicator 3-cci-h3 (attached), then, as it would seem, with exactly the same parameters of calculated cci signals of the indicator and the actual cci (object text in the upper right corner) do not coincide.

WHY?

Why is it that alerts don't work in this indicator?

Expert Advisor code:

double lasthigh, lastlow, lasthigh2=200000, lastlow2=0, lastpos=0, t[2];

int start()
{Comment("");
lasthigh=High[1]; lastlow=Low[1];
if( lasthigh< lasthigh2) lasthigh2= lasthigh;
if( lastlow> lastlow2) lastlow2= lastlow;
t[0]= lasthigh2;
t[1]= lastlow2;  
string s1="lasthigh2 *** "+DoubleToStr( t[0],5);
string s2="lastlow2 *** "+DoubleToStr( t[1],5);
string str[2];
str[0]= s1;
str[1]= s2;
color col=Lime;
     for(int y=0; y<2; y++)
     {ObjectCreate("textSignal"+ y,OBJ_LABEL,0,0,0,0,0);    
      ObjectSet("textSignal"+ y, OBJPROP_CORNER,1);
      ObjectSet("textSignal"+ y, OBJPROP_XDISTANCE,35-25);
      ObjectSet("textSignal"+ y, OBJPROP_YDISTANCE, y*(20)+20+8);
      ObjectSetText("textSignal"+ y, str[ y],15,"Tahoma", col);
     }
  
  if( lastpos==0){if( lastlow2> lasthigh){
  Comment("PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   PRODAGA!!!",
  "PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   PRODAGA!!!   "); lasthigh2=2000000; lastlow2=0; lastpos=1;}}
  else {if( lasthigh2< lastlow){Comment("POKUPKA!!!   POKUPKA!!!   POKUPKA!!!   POKUPKA!!!   POKUPKA!!!   POKUPKA!!!   POKUPKA!!!",
  "   POKUPKA!!!   POKUPKA!!!   POKEPKA!!!   POKEPKA!!!   POKEPKA!!!"); lasthigh2=2000000; lastlow2=0; lastpos=0;}}

}


Indicator code:

//+------------------------------------------------------------------+
//|                                                     i-3CCI-h.mq4 |
//|                                               johnfantom & KimIV |
//|                                              http://www.kimiv.ru |
//|                                                                  |
//|  02.01.2006  CCI с 3-х ТФ в одном флаконе.                       |
//+------------------------------------------------------------------+
#property copyright "johnfantom & KimIV"
#property link      "http://www.kimiv.ru"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_maximum 1.4
#property indicator_level1  0
#property indicator_minimum -1.2

//------- Внешние параметры индикатора -------------------------------
extern int CCI_Period_0 = 14;     // Период CCI для текущего ТФ
extern int Level_0      = 100;    // Уровень CCI для текущего ТФ
extern int TF_1         = 60;     // Количество минут первого ТФ
extern int CCI_Period_1 = 14;     // Период CCI для первого ТФ
extern int Level_1      = 100;    // Уровень CCI для первого ТФ
extern int TF_2         = 240;    // Количество минут второго ТФ
extern int CCI_Period_2 = 14;     // Период CCI для второго ТФ
extern int Level_2      = 100;    // Уровень CCI для второго ТФ
extern int NumberOfBars = 1000;  // Количество баров обсчёта (0-все)
extern int ExtBars=3; 
int per;


//------- Буферы индикатора ------------------------------------------
double buf0[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() {
  IndicatorDigits(1);

  SetIndexBuffer(0, buf0);
  SetIndexLabel (0, "i-3CCI-h");
  SetIndexStyle (0, DRAW_HISTOGRAM, STYLE_SOLID, 2);
  SetIndexEmptyValue(0, 0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void deinit() {
  Comment("");
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start() {
  double cci0, cci1, cci2;
  int    nb1, nb2, count;
  int    LoopBegin, sh;


 	if ( NumberOfBars==0) LoopBegin=Bars-1;
  else LoopBegin= NumberOfBars-1;
  LoopBegin=MathMin(Bars-1, LoopBegin);
  count=IndicatorCounted();
  for ( sh= count; sh>=0; sh--) {
    nb1=iBarShift(NULL, TF_1, Time[ sh+1], False);
    nb2=iBarShift(NULL, TF_2, Time[ sh+1], False);

    cci0=iCCI(NULL, 0   , CCI_Period_0, PRICE_CLOSE, sh+1);
    cci1=iCCI(NULL, TF_1, CCI_Period_1, PRICE_CLOSE, nb1);
    cci2=iCCI(NULL, TF_2, CCI_Period_2, PRICE_CLOSE, nb2);
    
   /* double cci[3];
    cci[0]=cci0;
    cci[1]=cci1;
    cci[2]=cci2;
    string s1="cci-0 *** "+DoubleToStr(cci[0],3);
    string s2="cci-1 *** "+DoubleToStr(cci[1],3);
    string s3="cci-2 *** "+DoubleToStr(cci[2],3);
    string str[3];
    str[0]=s1;
    str[1]=s2;
    str[2]=s3;
    color col=Lime;
     for(int y=0;y<3;y++)
     {ObjectCreate("textSignal"+y,OBJ_LABEL,0,0,0,0,0);    
      ObjectSet("textSignal"+y,OBJPROP_CORNER,1);
      ObjectSet("textSignal"+y,OBJPROP_XDISTANCE,35-25);
      ObjectSet("textSignal"+y,OBJPROP_YDISTANCE,y*(20)+20+8);
      if(cci[y]>=0)col=Lime;else col=Red;
      if(cci[y]>Level_0) col=Aqua;
      if(cci[y]<-Level_0) col=DarkViolet;
      ObjectSetText("textSignal"+y,str[y],15,"Tahoma",col);
     }
*/
    if ( cci0> Level_0 && cci1> Level_1 && cci2> Level_2) { buf0[ sh]=1;
    if ( per != Time[0]) { per = Time[0];
    if( sh<= ExtBars && ExtBars!=-1)
    Alert(Symbol(),Period()," ",
                              TimeYear(Time[ sh]),".",
                              TimeDay(Time[ sh]),".",
                              TimeMonth(Time[ sh]),"; ",
                              TimeHour(Time[ sh]),":",
                              TimeMinute(Time[ sh])," ",
                              "Покупка");}}
    if ( cci0<- Level_0 && cci1<- Level_1 && cci2<- Level_2) { buf0[ sh]=-1;
    if ( per != Time[0]) { per = Time[0];
    if( sh<= ExtBars && ExtBars!=-1)
    Alert(Symbol(),Period()," ",
                              TimeYear(Time[ sh]),".",
                              TimeDay(Time[ sh]),".",
                              TimeMonth(Time[ sh]),"; ",
                              TimeHour(Time[ sh]),":",
                              TimeMinute(Time[ sh])," ",
                              "Продажа");}}
  }
}
//+------------------------------------------------------------------+
 
sergeev >> :

like this for bystop:




And how do you set the pending from open position itself?

 
ArtY0m >> :

How do you place the pending order itself?

First, you need to determine the opening price of the last open position programmatically.

For that, you can use a pre-defined function, e.g.

Function PriceOpenLastPos().
This function returns the open price of the last position opened. The selection of positions to be considered is specified by external parameters:
sy - Name of market instrument. If this parameter is set, the function will consider only positions of the specified instrument. The default value - "" means any market instrument. NULL value means the current instrument.
op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
mn - Position identifier, MagicNumber. The default value of -1 means any identifier.
'Useful functions from KimIV

//-------

Insert the function itself at the very end of your code.

And you call it in the START function and set the opening price of the last position you need (buy or sell), for example.

double OpenPrice=PriceOpenLastPos(NULL,OP_BUY, MAGIC) ;

 
rid >> :

First you must determine the price of the last open position programmatically.

To do this, you can use a pre-defined function, e.g.

Function PriceOpenLastPos().
This function returns the opening price of the last position opened. Selection of positions to be considered is defined by external parameters:
sy - Name of market instrument. If this parameter is set, the function will only consider positions of this instrument. The default value - "" means any market instrument. NULL value means the current instrument.
op - Trade operation, position type. Valid values: OP_BUY, OP_SELL or -1. The default value -1 means any position.
mn - Position identifier, MagicNumber. The default value of -1 means any identifier.

'Useful functions from KimIV

//-------

Insert the function itself at the very end of your code.

In the START function, you call it and set the opening price of the last position you want (buy or sell), e.g.

double OpenPrice=PriceOpenLastPos(NULL,OP_BUY, MAGIC) ;

Thank you very much!))

 

In Indicator, if a condition is met, I want to enter a line with a note in a text file (no matter what, let's say date and time).

The file is created and the line is added, but only in real time. I, on the other hand, want to make a note when working on history. Does anyone know how to do this?

Thank you!





Reason: