Dukascopy
 
 
Wiki JStore Search Login

Custom Block
 Post subject: Custom Block Post rating: 0   New post Posted: Sun 14 Aug, 2016, 21:03 
User avatar

User rating: 0
Joined: Sun 18 Mar, 2012, 14:15
Posts: 8
Location: Turkey, Bursa
Hi,

We already know that we can create strategy blocks but i think we can not create indicator and/or component blocks. I want to use my custom indicator in my strategy or i have a common logic that can be like component block that i'll use almost all of my strategies. My opinion it's must be feature. Is there any way to accomplish this things? If not is there any plan about it?

PS: Common block sample is; Session is active block. Input is which session will query (London, Tokyo, New York). Output is true or false according to current time. Block calculation will take into account session local time zone, GMT Offset & DST Offset. You can see my MQL code below, only for clearly understand what i mean.

Regards,
Aytaç Aşan

enum Week { None, First, Second, Third, Fourth, Last };

//+------------------------------------------------------------------+
//| Session Structure |
//+------------------------------------------------------------------+
struct Session
{
int OpenHour;
int OpenMinute;
int CloseHour;
int CloseMinute;
//---
int GmtOffset;
int DstOffset;
Week DstStartWeek;
int DstStartMonth;
Week DstFinishWeek;
int DstFinishMonth;
//---
void Initialize(int openHour, int openMinute,
int closeHour, int closeMinute,
int gmtOffset, int dstOffset,
Week dstStartWeek, int dstStartMonth,
Week dstFinishWeek, int dstFinishMonth)
{
OpenHour = openHour;
OpenMinute = openMinute;
CloseHour = closeHour;
CloseMinute = closeMinute;
GmtOffset = gmtOffset;
DstOffset = dstOffset;
DstStartWeek = dstStartWeek;
DstStartMonth = dstStartMonth;
DstFinishWeek = dstFinishWeek;
DstFinishMonth = dstFinishMonth;
}
//---
datetime GetOpenTime(Session &session, DateTime &dateTime)
{
int gmtOffset = IsDaylightSavingTime(dateTime) ?
GmtOffset + DstOffset :
GmtOffset;
int gmtOffsetSession = session.IsDaylightSavingTime(dateTime) ?
session.GmtOffset + session.DstOffset :
session.GmtOffset;
int differenceInSeconds = (gmtOffsetSession - gmtOffset) * HOURTOSECOND;
return dateTime.GetTime(OpenHour, OpenMinute, 0) + differenceInSeconds;
}
//---
datetime GetCloseTime(Session &session, DateTime &dateTime)
{
int gmtOffset = IsDaylightSavingTime(dateTime) ?
GmtOffset + DstOffset :
GmtOffset;
int gmtOffsetSession = session.IsDaylightSavingTime(dateTime) ?
session.GmtOffset + session.DstOffset :
session.GmtOffset;
int differenceInSeconds = (gmtOffsetSession - gmtOffset) * HOURTOSECOND;
return dateTime.GetTime(CloseHour, CloseMinute, 0) + differenceInSeconds;
}
//---
datetime GetCurrentTime(Session &session, DateTime &dateTime)
{
int gmtOffset = IsDaylightSavingTime(dateTime) ?
GmtOffset + DstOffset :
GmtOffset;
int gmtOffsetSession = session.IsDaylightSavingTime(dateTime) ?
session.GmtOffset + session.DstOffset :
session.GmtOffset;
int differenceInSeconds = (gmtOffset - gmtOffsetSession) * HOURTOSECOND;
return dateTime.Time + differenceInSeconds;
}
//---
bool IsDaylightSavingTime(DateTime &dateTime)
{
int dstStartDay = dateTime.DayOfMonth(Sunday, DstStartWeek, DstStartMonth, dateTime.Year);
int dstFinishDay = dateTime.DayOfMonth(Sunday, DstFinishWeek, DstFinishMonth, dateTime.Year);
//---
datetime date = dateTime.Date;
if(date < StringToTime(StringFormat("%i.%i.%i", dateTime.Year, DstStartMonth, dstStartDay)) ||
date > StringToTime(StringFormat("%i.%i.%i", dateTime.Year, DstFinishMonth, dstFinishDay)))
return false;
//---
return true;
}
};


 

Jump to:  

  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com