Useful features from KimIV - page 81

 
KimIV >> :

On page 76...

Thank you

 

The isTradeTimeInt() function.

This function returns a flag to allow timed trading. The returned value is true or false. Function isTradeTimeInt() is similar to function isTradeTimeString() by the principle of time interval recognition, i.e. the trade start time can be both larger (time interval within a day) and smaller (time interval in different days). Function isTradeTimeInt() accepts the following optional parameters:

  • hb - Number, specifies the hours of trade start time. The default value is 0.
  • mb - A number, specifies the minutes of trade start time. Default value - 0.
  • he - A number to specify the hours of trade end time. The default value - 0.
  • me - A number to specify the minutes of trade end time. Default value - 0.
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 30.04.2009                                                     |
//|  Описание : Возвращает флаг разрешения торговли по времени.                |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    hb - часы времени начала торговли                                       |
//|    mb - минуты времени начала торговли                                     |
//|    he - часы времени окончания торговли                                    |
//|    me - минуты времени окончания торговли                                  |
//+----------------------------------------------------------------------------+
bool isTradeTimeInt(int hb=0, int mb=0, int he=0, int me=0) {
  datetime db, de;           // Время начала и окончания работы
  int      hc;               // Часы текущего времени торгового сервера

  db=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+ hb+":"+ mb);
  de=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+ he+":"+ me);
  hc=TimeHour(TimeCurrent());
  if ( db>= de) {
    if ( hc>= he) de+=24*60*60; else db-=24*60*60;
  }

  if (TimeCurrent()>= db && TimeCurrent()<= de) return( True);
  else return( False);
}
 

Examples of how to use isTradeTimeInt().

  1. Time period within a day. Current time of trade server within a period and let it be "08:30".
    if (isTradeTimeInt(6, 0, 9, 30)) Message("Торгуем...");
    else Message("Отдыхаем...");
  2. Time frame inside day. Current time of trade server outside the segment and let it be equal to "08:30".
    if (isTradeTimeInt(12, 0, 16, 30)) Message("Торгуем...");
    else Message("Отдыхаем...");
  3. Time slot includes day boundary. Current time of trade server inside the segment and let it be equal to "08:30".
    if (isTradeTimeInt(21, 15, 9, 30)) Message("Торгуем...");
    else Message("Отдыхаем...");
  4. Time slot includes day boundary. Current time of trade server outside the segment and let it be "08:30".
    if (isTradeTimeInt(22, 0, 5, 30)) Message("Торгуем...");
    else Message("Отдыхаем...");

SZY. Attached is a script to test the isTradeTimeInt() function.

Files:
 

Updated list of features with brief descriptions and links...

Files:
f_kimiv.rar  12 kb
 
KimIV >> :

The isCloseLastPosByStop() function.

This function returns a flag to close the last position by stop. Flag is up - True - StopLoss has triggered. Flag lowered - False - position has been closed for another reason. More accurate selection of positions to be taken into account is set by external parameters:


Hello

Trying to use your function for my own purposes. Small working Expert Advisor. Only sells and closes, one position. Sometimes it catches several stoplosses in a row. I want to change sell conditions after first stop, Expert Advisor opens positions but does not close them. Please tell me what I am doing wrong ?

..........................................................

if ( isCloseLastPosByStop(NULL,OP_SELL, MagicNamber) == 0)
{
if ( (StochK_0<StochD_1) && (StochD_1 > 80) ) // 1st Sell Slowly
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+SL*Point,0, "My EXP", MagicNamber,0,Green); // sell

OrderSelect(0, SELECT_BY_POS);

if (OrderSelect(0, SELECT_BY_POS)==true )
Print("SELECT_BY_POS");
else
Print("failed to select error : ",GetLastError());
RefreshRates();
if((StochK_0<30)&& (StochD_1 < 30))
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
}
else
if ( isCloseLastPosByStop(NULL,OP_SELL, MagicNamber) == 1)
{
if ((StochK_0<StochD_1) && (StochK_0 < 60) && (StochD_1 < 60) )

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0, "My EXP", MagicNamber,0,Green); //

...........................

 
KoZaNOStra писал(а) >>
Expert opens positions, but does not close them.

Print StochK_0 and StochD_1 variables. Maybe they take values that do not fall under your closing conditions.

 

to KimIV

Hello, could you please help to convert this cluster indicator into a function with the same drawing and + Pair change rate values return (upper right corner) by input parameter - Pair name. I thank you in advance.

P.S..... I've been struggling for a week now

Files:
cc_240.mq4  13 kb
 
is there any function to display news on the open window of a currency pair
 
And how do we express in the code that at the beginning of any hour, at the first second we open two differently directed positions, and at the last second of the hour we close the failed order?
 
VAM_ писал(а) >>
And how do we express in the code that at the beginning of any hour, at the first second we open two differently directed positions, and at the last second of the hour we close the failed order?

What if there isn't one, first and last second?

Reason: