Miscellaneous
0
Views
0
Downloads
0
Favorites
statetograph_v2
//+------------------------------------------------------------------+
//| StateToGraph v2.mq4 |
//| Author: Denis Orlov |
//| Changed by GoldnMoney for >= MetaTrader 4 build 670|
//| http://denis-or-love.narod.ru |
//+------------------------------------------------------------------+
/*
Ãðàôè÷åñêîå îòîáðàæåíèå ñòåéòìåíòà èëè "ñòåéòà" ( Statement ),
ò.å. ïåðåíîñ äàííûõ èç òàáëèöû íà ãðàôèê, äëÿ óäîáñòâà àíàëèçà è èçó÷åíèÿ.
Ïîäðîáíî:
http://codebase.mql4.com/ru/6127
Graphic displaing of the statement,
carring of a data from the *.htm table to the graph, for convenience of the analysis.
and studying.
In detail:
http://codebase.mql4.com/6135
Íà îñíîâå èäåè Èãîðÿ Êèìà fromRepOnGraph.mq4 http://www.kimiv.ru */
#property copyright "Denis Orlov"
#property link "http://denis-or-love.narod.ru"
#property show_inputs
#include <WinUser32.mqh>
#include <stdlib.mqh>//for ErrorDescription
#import "user32.dll"
int RegisterWindowMessageA(string param);
#import
int MT4InternalMsg=0;
enum LengthDateStr
{
OldFormat = 16,
NewFormat = 19
};
#define Pr "StateToGraph: "
extern string FileName="Statement.txt";
extern string Suffix="";
extern LengthDateStr DateStringFormat = NewFormat;
extern color BuyArrowColor = Blue;
extern color SellArrowColor= Red;
extern color ProfitLineColor=Lime;
extern color LossLineColor=Magenta;
extern color ClosedByTakeProfitColor=Goldenrod;
extern color ClosedByStopLossColor=Goldenrod;
extern color CancelledColor=Yellow;
extern bool DeletePrev=False;
extern bool ClearChart=False;
datetime OpTime,ClTime;
string ticket,type,sym,lot,suffix;
double OpP,SL,TP,ClP,profit;
datetime FirstOpTime=0;
bool Cancelled=False;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if(ClearChart)
{
Delete_My_Obj(Pr);
return(0);
}
int fname=FileOpen(FileName,FILE_BIN|FILE_READ);
if(fname>0)
{
if(DeletePrev)
Delete_My_Obj(Pr);
string str;
while(!FileIsEnding(fname))
{
str=GetStringFromFile(fname);
str=StringTrimRight(str);
str=StringTrimLeft(str);
str=StringReplaces(str, "buy stop", "buy_stop");
str=StringReplaces(str, "buy limit", "buy_limit");
str=StringReplaces(str, "sell stop", "sell_stop");
str=StringReplaces(str, "sell limit", "sell_limit");
while(StringFind(str,CharToStr(32))>-1 && StringLen(str)>10)
str=StringReplaces(str,CharToStr(32),"/");
if(StringLen(str)<70) continue;
Cancelled=False;
int pos=StringFind(str,"/");
ticket=StringSubstr(str,0,pos);
str=StringSubstr(str,pos+1);/// îòñåêëè ticket
OpTime=StrToTime(StringSubstr(str,0,DateStringFormat));
if(FirstOpTime==0) FirstOpTime=OpTime;
str=StringSubstr(str,DateStringFormat+1);//îòñåêëè OpTime
pos=StringFind(str,"/");
type=StringSubstr(str,0,pos);
if(StringFind(type,"_")>-1)
{
Cancelled=True;
}
type=fStrUpperCase(type);
str=StringSubstr(str,pos+1);/// îòñåêëè type
pos=StringFind(str, "/");
lot=StringSubstr(str, 0, pos);
str=StringSubstr(str,pos+1);/// îòñåêëè lot
pos=StringFind(str, "/");
sym=fStrUpperCase(StringSubstr(str, 0, pos));
str=StringSubstr(str,pos+1);/// îòñåêëè sym
pos=StringFind(str, "/");
OpP=StrToDouble(StringSubstr(str, 0, pos));
str=StringSubstr(str,pos+1);/// îòñåêëè OpP
pos=StringFind(str,"/");
SL=StrToDouble(StringSubstr(str,0,pos));
str=StringSubstr(str,pos+1);/// îòñåêëè SL
pos=StringFind(str,"/");
TP=StrToDouble(StringSubstr(str,0,pos));
str=StringSubstr(str,pos+1);/// îòñåêëè TP
ClTime=StrToTime(StringSubstr(str,0,DateStringFormat));
str=StringSubstr(str,DateStringFormat+1);//îòñåêëè ClTime
pos=StringFind(str, "/");
ClP=StrToDouble(StringSubstr(str, 0, pos));
//Commission
str=StringSubstr(str,pos+1);/// îòñåêëè ClP
pos=StringFind(str, "/");
// Taxes
str=StringSubstr(str,pos+1);/// îòñåêëè Commission
pos=StringFind(str,"/");
//Swap
str=StringSubstr(str,pos+1);/// îòñåêëè Taxes
pos=StringFind(str,"/");
str=StringSubstr(str,pos+1);/// îòñåêëè Swap
profit=StrToDouble(str);
suffix=Suffix;
if(Symbol()==sym+suffix)
{
DrawPos();
}
}
FileClose(fname);
if(FirstOpTime!=0)
{
int handle=WindowHandle(Symbol(),Period());
MT4InternalMsg=RegisterWindowMessageA("MetaTrader4_Internal_Message");
PostMessageA(handle,MT4InternalMsg,55,FirstOpTime-Period()*180);//
}
}
else
{
int err=GetLastError();
Comment("Îøèáêà îòêðûòèÿ ôàéëà \""+FileName+"\"\n"+
"Error of opening file ",err,": ",ErrorDescription(err));
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawPos()
{
string op=" opened ";
string cl=" closed ";
string prof=" / Profit: "+DoubleToStr(profit,2);
double close_pr=ClP;
if(Cancelled)
{
color Clr=CancelledColor;
color ClrOrd=CancelledColor;
op=" posed "; cl=" cancelled "; prof="";
close_pr=OpP;
}
else
if(profit<0)
Clr=LossLineColor;
else
Clr=ProfitLineColor;
if(type=="BUY")
ClrOrd=BuyArrowColor;
if(type=="SELL")
ClrOrd=SellArrowColor;
// Ñòðåëêà îòêðûòèÿ ïîçèöèè
DrawArrows(Pr+"#"+ticket+" "+type+op+TimeToStr(OpTime),OpTime,OpP,1,ClrOrd,0,type+" "+lot+" at "+DoubleToStr(OpP,Digits)+
" S/L:"+DoubleToStr(SL,Digits)+" T/P:"+DoubleToStr(TP,Digits));
if(ClP==TP)
{
cl=" closed by TP ";
ClrOrd=ClosedByTakeProfitColor;
};
if(ClP==SL)
{
cl=" closed by SL ";
ClrOrd=ClosedByStopLossColor;
};
// Ñòðåëêà çàêðûòèÿ ïîçèöèè
DrawArrows(Pr+"#"+ticket+" "+type+cl+TimeToStr(ClTime),ClTime,close_pr,3,ClrOrd,0,type+" "+lot+cl+"at "+DoubleToStr(close_pr,Digits)+prof);
if(SL>0)
DrawArrows(Pr+type+" #"+ticket+" S/L: "+DoubleToStr(SL,Digits),
OpTime,SL,4,Red,0,"");
if(TP>0)
DrawArrows(Pr+type+" #"+ticket+" T/P: "+DoubleToStr(TP,Digits),
OpTime,TP,4,Blue,0,"");
string name=Pr+"#"+ticket+" "+DoubleToStr(OpP,Digits)+" --> "+DoubleToStr(ClP,Digits);
DrawTrends(name,OpTime,OpP,ClTime,close_pr,Clr,1,"",false,0);
ObjectSet(name,OBJPROP_STYLE,STYLE_DASH);
if(!Cancelled)
ObjectSetText(name,type+" "+lot+prof+" ( "+DoubleToStr(ClP-OpP,Digits)+" pts )");
}
//+----------------------------------------------------------------------------+
//| ×èòàåò ñòðîêîâûé áëîê èç ôàéëà äî çíàêà ïåðåíîñà êàðåòêè #13#10 |
//| Ïàðàìåòðû: |
//| fh - îïèñàòåëü îòêðûòîãî ðàíåå ôàéëà |
//| |
//+----------------------------------------------------------------------------+
string GetStringFromFile(int &fh)
{
string str="",s;
while(!FileIsEnding(fh))
{
s=FileReadString(fh,1);
int Ch=StringGetChar(s, 0);
if(Ch!=13 && Ch!=10)
str=str+s;
else
return(str);
}
return(str);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string StringReplaces(string text,string oldstr,string newstr)
{
int pos=StringFind(text,oldstr);
if(pos>-1)
{
string str=StringSubstr(text,0,pos)+newstr+StringSubstr(text,pos+StringLen(oldstr));
return(str);
}
return(text);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string fStrUpperCase(string aString)
{
for(int i=0;i<StringLen(aString);i++)
{
int ichar=StringGetChar(aString,i);
if(ichar>96)
{
if(ichar<123)
{
aString=StringSetChar(aString,i,ichar-32);
continue;
}
}
if(ichar>223)
{
if(ichar<256)
{
aString=StringSetChar(aString,i,ichar-32);
continue;
}
}
if(ichar==184)
{
aString=StringSetChar(aString,i,168);
continue;
}
}
return(aString);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawArrows(string name,datetime T,double P,int code,color Clr=Green,int Win=0,string Text="")
{
ObjectCreate(name,OBJ_ARROW,Win,T,P);
ObjectSet(name,OBJPROP_ARROWCODE,code);
ObjectSet(name,OBJPROP_COLOR,Clr);
ObjectSet(name,OBJPROP_TIME1,T);
ObjectSet(name,OBJPROP_PRICE1,P);
ObjectSetText(name,Text);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawTrends(string name,datetime T1,double P1,datetime T2,double P2,color Clr,int W=1,string Text="",bool ray=false,int Win=0)
{
ObjectCreate(name,OBJ_TREND,Win,T1,P1,T2,P2);
ObjectSet(name,OBJPROP_TIME1,T1);
ObjectSet(name,OBJPROP_PRICE1,P1);
ObjectSet(name,OBJPROP_TIME2,T2);
ObjectSet(name,OBJPROP_PRICE2,P2);
ObjectSet(name,OBJPROP_RAY,ray);
ObjectSet(name,OBJPROP_COLOR,Clr);
ObjectSet(name,OBJPROP_WIDTH,W);
ObjectSetText(name,Text);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Delete_My_Obj(string Prefix)
{
for(int k=ObjectsTotal()-1; k>=0; k--) // Ïî êîëè÷åñòâó âñåõ îáúåêòîâ
{
string Obj_Name=ObjectName(k); // Çàïðàøèâàåì èìÿ îáúåêòà
string Head=StringSubstr(Obj_Name,0,StringLen(Prefix));// Èçâëåêàåì ïåðâûå ñèì
if(Head==Prefix)// Íàéäåí îáúåêò, ..
{
ObjectDelete(Obj_Name);
}
}
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---