Useful features from KimIV - page 75

 

Hello, dear Igor! My system uses trend suppressors. And both the time and the price of the crossover are important in it.
A sequence of bars does not always have a "continuous" time. Exits, holes, etc.
The use of CrossPointOfLines ( in test_CrossPointOfLines.mq4) for calculation of time in its natural form leads to the following results

to the left of the zero bar

(The position of the trend lines on the charts has nothing to do with the system - random selection. The reference points of the trend line can

being one on the left side of the zero bar, the other one on the right).


and to the right

Calculations should not be performed in hours, but according to the situation: both in bars and in hours . The unit of time on the left is bar. And for the right side, after the zero bar, it should be measured in hours.

Search for ready-made solutions hasn't yielded anything yet. The CrossPointOfLines function is the only one on the site so far. It requires a perfect history :(

 

Good day Igor!

Please help me with advice or a solution. I am trying to make the Expert Advisor give a signal when a previous bar "absorbs" the previous one.

1 - if absorption occurred upwards
2 - if absorption occurred downwards.

I thought it was very simple, just compare open and close prices and voila ... but it's not. When I hover my mouse over the previous 2 bars, it's clear that the last one is eating the penultimate one.

Very much hope for help, and thank you in advance


Here is the text:

int start()
{
//----
if (SShort()==1)
Alert("1");
}
if (SLong()==1)
Alert("2");
}
//----
return(0);
}
//+------------------------------------------------------------------+
int SShort()
{int MS=0;
if (Open[1]>Close[2] && Close[1]<Open[2] && Open[1]>Close[1] && Open[2]<Close[2])
MS=1;
return(MS);
}
//+------------------------------------------------------------------+
int SLong()
{
int ML=0;
if(Open[1]<Close[2] && Close[1]>Open[2] && Open[1]<Close[1] && Open[2]>Close[2])
ML=1;
return(ML);
}
//+------------------------------------------------------------------+
 

Time filter set: C and PO

(and more...).

Once asked what's up, here's the result I came up with myself.


1. Prohibit or allow daily activities.


Option 1.

// Закрыть все позиции в конце дня в указанное время
if (Hour()==23 && Minute()>=45) 
{ ЗакрытьДень();}


// Запретить эксперту торговать С и ПО
if ( (Hour()==22 && Minute()>=00) && (Hour()==23 && Minute()>=59) ) return;

Note that the "expiry time" in these options extends to the end of the hour and 59 seconds of the number of minutes.

i.e. the end time of the event indicated as 23:59 is actually 23:59:59

And to the end of the hour because the minutes use the comparison operator ">=", which however is not a problem and you can specify "==",

but wiping the time to 59 seconds will still work in any case...


Option 2.

More precise from the point of view of setting conditions...

// Выборка ОТ и ДО
if( OtTime(2,15,21) < OrderCloseTime() && OrderCloseTime() < DoTime(4,58,33) )
{ Действия;}

// Функции преобразования 
datetime OtTime(int h=0, int m=0, int s=0) {datetime ot;
ot=( h*3600)+( m*60)+ s+StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
return ( ot);}
//--------------
datetime DoTime(int h=0, int m=0, int s=0) { datetime dt;
//if(h>23||h<0) Alert("Должно быть от 0 до 23"); h=0; 
//if(m>59||m<0) Alert("Должно быть от 0 до 59"); m=0;
dt=( h*3600)+( m*60)+ s+StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
return ( dt);}

The time is set by specifying in passing parameters to function, for example 21:15:23 as (21,15,23).

It's clear that it's not cool, but it's quite workable code...

SZY: the validity check of entered parameters is not accidental.

For if you enter wrong one, it blows your mind. I couldn't find any other way, so I've commented it out.

Therefore, I would be very grateful for a way to solve this problem...


Variant #3.

As it turns out, it's the simplest and the most exact.

// Внешние параметры, могут быть экстернами
string ВН="02:15"; // начало события
string ВК="04:58"; // конец события

int start()
{
int m;
datetime vn=StrToTime( ВН);
datetime vk=StrToTime( ВК);
// либо напрямую указывать время по типу:
//  datetime vn=StrToTime("02:15");
//  datetime vk=StrToTime("04:58");

for (int m=0; m < OrdersHistoryTotal() ; m++) 
{
OrderSelect( m, SELECT_BY_POS, MODE_HISTORY);
if( (OrderCloseTime()> vn) && (OrderCloseTime()< vk) )
{ Действия;}
}

return()
}

The thing about simplicity, it seems, is in peculiarities of transformation of parameters passed to it by function StrToTime().

For example, if you enter only the time "HH:MM:SS" then the output will be the time of each current day...


By the way...

// можно написать и так:
if( (OrderCloseTime()>StrToTime( ВН)) && (OrderCloseTime()<StrToTime( ВК)) )
// или даже так:
if( (OrderCloseTime()>StrToTime("02:15")) && (OrderCloseTime()<StrToTime("04:58")) )

By combining sampling by hours with days you can filter by type:

- what was at 18:00 of each day, or what was every day in specified period from C and up hours:minutes:seconds

However, the range of days can also be crammed in from and to...


2. Function DateFirstDayMonday()

(based on DateOfMonday() )

datetime DateFirstDayMonday() 
{ 
datetime dfdm;
dfdm=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE))-((Day()-1)*86400);
return ( dfdm);
}

Returns date of the first day as 00:00:00 of the current month.

Needed to filter events from BEFORE the start of the month...

// выборка закрытых ордеров с начала месяца:
if( DateFirstDayMonday() < OrderCloseTime() )
{ Действия;}

// выборка ДО начала месяца (с начала истории счёта):
if( DateFirstDayMonday()-1 > OrderCloseTime() )
{ Действия;}

DateFirstDayMonday()-1 in the second sample prints "last day of previous month 23:59:59".


...

Please don't kick me in advance, because I'm a dummy.

:)))

 
Igor please help to attach an alert to this indicator
Files:
 
kombat >> :

Please don't kick me in advance, because I am a dummy. :)))

Chayneg not chayneg, but if you've taken up the bush, follow it to the end. We'd like to move permitted operation time and closing time to separate Boolean functions of this type:

bool TradeTime(Trade start time, Trade end time)

Then it will be very convenient to use, if (TradeTime(.,...)) and work!

 
granit77 >> :

Chyneg is not a chyneg, but if you've taken up the rudder, follow through. It begs to put allowed operation time, closing time into separate Boolean functions of sorts:

bool TradeTime(Trade start time, Trade end time)

It will be very convenient to use then, if (TradeTime(.,.)) and work!



Well, already... ;)

For one bank I make variant with two simultaneous timings:

- close all orders and positions before the rollover at 22:00

- trade pause from the beginning of the rollover at 22:00 till the end of the day at 23:59

(raw version without additional checks)

//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH>
//HHHHH Стартуем... HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH>
//HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH>
int start() {
//--- Общая проверка --------------------------------------------------------+
if(! IsCondition()) {Print("Низззяяя..."); return;}
//--- Задание неторгового времени (паузы) -----------------------------------+
ObjectDelete("НЕТОРГВРЕМЯ");
if((TimeCurrent()>StrToTime("22:00"))&&(TimeCurrent()<StrToTime("23:59:59"))) 
{ NoTradeTime(); return;}
//--- Принудительное закрытие всех ордеров и позиций в конце дня ------------+
if(Hour()==21 && Minute()>=45) { ЗакрытьДень(); return;}
//*метод имеет недостаток: он будет закрывать до конца указаного часа...
//*например время 21:45, закрывать будет до 21:59:59 а с 22:00 прекратит.
//*впринципе это нам не повредит...
//--- Конец условий ---------------------------------------------------------+
// бла-бла-бла...
return(0);
}
 
kombat >> :

...(raw version without additional checks)

Vinin had separate functions for timing, very detailed and worked out. Look in the EAs on his site or knock on his door.

 
granit77 >> :

Vinin's EA has separate functions for working with time, which are very detailed and thorough. Look through the Expert Advisors on his site or just knock on his door.

Thanks, but no need for that yet...

I just don't have a lot of time for this advisor at the moment,

I know what to write there and I know how to write it too...

*

I will post the main text on the bank's forum in order not to litter this topic.

In his time, of course. ;)

 
granit77 >> :

bool TradeTime(Trade start time, Trade end time)

Then it will be very convenient to use, if (TradeTime(.,.)) and work!

It's necessary to order such a function for Igor Kim.

 
goldtrader писал(а) >>

Igor Kim should order such a function.

I join in the request! It would be a very useful and needed function. In the light of current trading realities....

It is even possible to provide two TIME intervals there.