Time
Download scriptThis script is designed for the MetaTrader 4 platform to provide traders with real-time visual information directly on their trading charts. Its primary purpose is to display live market data, current account statistics, and a countdown timer related to the current trading period.
The logic of the script can be broken down into three main components:
1. Dynamic Market and Account Information
When you activate the script, it automatically scans your open trades on the specific chart you are viewing. It calculates and displays several key pieces of information in a text format:
- Spread and Tick Value: It shows the current market spread and the monetary value of each "tick" (the smallest price movement).
- Profit/Loss Projections: The script looks at your open positions and calculates your potential profit if a "Take Profit" target is hit, as well as your potential loss if a "Stop Loss" is triggered.
- Account Totals: It displays your current account balance alongside the calculated profit and loss figures, allowing you to see your total theoretical equity in real-time.
2. Time Tracking and Countdown
The script includes a visual timer that helps traders keep track of time relative to the current candle or period:
- Elapsed Time: It shows how much time has passed since the current price bar began.
- Remaining Time: It calculates the remaining time until the next bar opens.
- Visual Display: This is presented as a running clock (minutes and seconds) on your chart, making it easier to manage entries and exits based on time intervals.
3. Automated Notifications and Licensing
The script includes a "donation" check logic intended for the developer:
- Periodic Check: Every 10 days, the script checks a local file to see if a contribution has been made.
- User Interaction: If no contribution is recorded, it may trigger a pop-up message asking the user for support.
- External Link: If the user interacts with this prompt, the script is programmed to open a web browser to a specific payment gateway. It then updates its internal records so that the prompt does not reappear for another period.
Summary of Visual Behavior
The script creates and updates labels on your screen automatically. It handles the deletion of old data and the creation of new text objects every time the market price moves (a "tick"), ensuring that the balance, spread, timers, and profit calculations are always up to date without requiring manual refreshing.
//
// Time.mq4
// Dmitry Yakovlev
// dmitry_yakovlev@rambler.ru
// Íà ïèâî WebMoney R865705290089
//------------------------------------------------------------------
#property copyright "Dmitry Yakovlev, Russia,Omsk, WM R865705290089"
#property link "dmitry_yakovlev@rambler.ru"
#property indicator_chart_window
#import "shell32.dll" //Connect a dll (provided with Windows)
int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);
#import "user32.dll"
int MessageBoxA(int hWnd ,string lpText,string lpCaption,int uType);
#import
extern string _Color="Öâåò òåêñòà:";
extern color nColor=MediumBlue;
extern string _ModeInfo1="Îáðàòíûé îòñ÷åò:";
extern int lCountdown=1;
extern string _ModeInfo2="Èíôîðìàöèÿ:";
extern int lInfo=1;
extern string _donate1="Äëÿ \"Ñïàñèáî\"";
extern string _donate2="R865705290089";
extern string _advert="Íàïèøó íà çàêàç,ïåðåäåëàþ.";
int init()
{
CheckDonate();
ObjectDelete("Time_Timer");
ObjectDelete("Time_Info");
ObjectDelete("Time_Info2");
}
int deinit()
{
ObjectDelete("Time_Timer");
ObjectDelete("Time_Info");
ObjectDelete("Time_Info2");
}
int start()
{
int i,sign=0;
double TickValue=MarketInfo(Symbol(), MODE_TICKVALUE);
int spread=MarketInfo(Symbol(), MODE_SPREAD);
ObjectDelete("Time_Info");
ObjectDelete("Time_Info2");
if(lInfo==1)
{
// <---- ñ÷èòàåì ñòîïû ----
double sum_stop=0, sum_profits=0;
for(i=0;i<OrdersTotal();i++)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true && OrderSymbol()==Symbol() && (OrderType()==OP_BUY || OrderType()==OP_SELL ) )
{
sign=0;
if(OrderStopLoss()!=0)
{
if(OrderType()==OP_SELL) sign=-1; else sign=+1;
sum_stop=sum_stop+OrderLots()*TickValue*sign*(OrderOpenPrice()-OrderStopLoss())/Point;
}
if(OrderTakeProfit()!=0)
{
if(OrderType()==OP_BUY) sign=-1; else sign=+1;
sum_profits=sum_profits+OrderLots()*TickValue*sign*(OrderOpenPrice()-OrderTakeProfit())/Point;
}
}
// ---- ñ÷èòàåì ñòîïû --- >
string cInfo;
ObjectCreate("Time_Info", OBJ_LABEL,0,0,0);
ObjectSet("Time_Info", OBJPROP_CORNER,0);
ObjectSet("Time_Info", OBJPROP_XDISTANCE,270);
ObjectSet("Time_Info", OBJPROP_YDISTANCE,0);
cInfo="Ñïðýä:"+DoubleToStr(spread,0)+
" 1ï="+DoubleToStr(TickValue,2)+"$";//+
//" áàë:"+DoubleToStr(AccountBalance(),2)+
//" ïð:"+DoubleToStr(AccountBalance()+sum_profits,2)+"("+DoubleToStr(sum_profits,2)+")"+
//" ñò:"+DoubleToStr(AccountBalance()-sum_stop,2)+"("+DoubleToStr(-sum_stop,2)+")";
ObjectSetText("Time_Info", cInfo, 10, "Arial", nColor);
ObjectCreate("Time_Info2", OBJ_LABEL,0,0,0);
ObjectSet("Time_Info2", OBJPROP_CORNER,0);
ObjectSet("Time_Info2", OBJPROP_XDISTANCE,200);
ObjectSet("Time_Info2", OBJPROP_YDISTANCE,20);
ObjectSetText("Time_Info2","áàë:"+DoubleToStr(AccountBalance(),2)+" ïð: "+DoubleToStr(AccountBalance()+sum_profits,2)+"("+DoubleToStr(sum_profits,2)+") ñò: "+DoubleToStr(AccountBalance()-sum_stop,2)+"("+DoubleToStr(-sum_stop,2)+")", 9, "Arial", nColor);
}
// <-timer
ObjectDelete("Time_Timer");
if(lCountdown==1)
{
int tmp1=Period()*60-TimeCurrent()+Time[0];
int tmpm=MathFloor(tmp1/60),tmps=tmp1-tmpm*60;
string strm=DoubleToStr(tmpm,0);
string strs=DoubleToStr(tmps,0);
if(StringLen(strs)==1) strs="0"+strs;
int tmp2=TimeCurrent()-Time[0];
int tmpm2=MathFloor(tmp2/60),tmps2=tmp2-tmpm2*60;
string strm2=DoubleToStr(tmpm2,0);
string strs2=DoubleToStr(tmps2,0);
if(StringLen(strs2)==1) strs2="0"+strs2;
ObjectCreate("Time_Timer", OBJ_LABEL,0,0,0);
ObjectSet("Time_Timer", OBJPROP_CORNER,1); //0
ObjectSet("Time_Timer", OBJPROP_XDISTANCE,50); //550
ObjectSet("Time_Timer", OBJPROP_YDISTANCE,0);
ObjectSetText("Time_Timer",strm2+":"+strs2+"..."+strm+":"+strs, 12, "Arial", MediumBlue);
}
// -timer>
}
void CheckDonate()
{
int fd=0; string pay="0"; datetime dt=0;
string fn="Time.txt";
fd=FileOpen(fn,FILE_READ|FILE_CSV,";");
if(fd>=1)
{
pay=FileReadString(fd); if(pay!="0" && pay!="1") pay="0";
dt=StrToTime(FileReadString(fd));
}
else
{
dt=TimeCurrent();
fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
FileWrite(fd,"0",TimeToStr(dt,TIME_DATE));
}
FileClose(fd);
if(pay=="0" && (TimeCurrent()-dt)>10*24*60*60) // 5 äíåé
{
if(MessageBoxA(0,"Åñëè Âàì ïîíðàâèëñÿ èíäèêàòîð Time,\n õîòèòå ïîìî÷ü àâòîðó ìàòåðèàëüíî?","Âîïðîñ",4)==6)
{
ShellExecuteA(0,"Open","iexplore.exe","wmk:payto?Purse=R865705290089&Amount=30&Desc=Indicator&BringToFront=Y&ExecEvenKeeperIsOffline=Y","",7);
pay="1";
}
dt=TimeCurrent();
fd=FileOpen(fn,FILE_WRITE|FILE_CSV,";");
FileWrite(fd,pay,TimeToStr(dt,TIME_DATE));
FileClose(fd);
}
FileClose(fd);
}
Comments