Adam/Adam.mq5

773 lines
54 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 14:38:54 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Adam_1.0.mq5 |
//| Magistr Sanich |
//| |
//+------------------------------------------------------------------+
#property copyright "Magistr Sanich"
#property link ""
#property version "1.00"
#define BUY "Buy"
#define SELL "Sell"
#define PLAY "Play"
#define STOP "Stop"
#include <Adam\MQL4.mqh>
#include <Arrays\ArrayObj.mqh>
#include <Arrays\ArrayInt.mqh>
#include <Adam\Functions.mqh>
#include <Adam\CMyTrade.mqh>
#include <Arrays\ArrayDouble.mqh>
#include <Arrays\ArrayInt.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\AccountInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\HistoryOrderInfo.mqh>
#include <Controls\Button.mqh>
#include <ChartObjects\ChartObjectsLines.mqh>
#include <Trade\Trade.mqh>
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
input int set_imp=80;//<?C;LA [Pips]
input int set_count_bar_imp=1;//>;8G5AB2> 10@>2 2 8<?C;LA5
input ENUM_TIMEFRAMES period=PERIOD_M5;//"09<D@59<
input bool set_un_damage=true;//1I89 157C1KB>: [2:;/2K:;]
input int set_dist_price=30;// 0AAB>O=85 1-3> >@45@0 >B "& [Pips]
input int set_step=50;//(03 >@45@>2 [Pips]
input int set_add_undamage=3;//+[pips] : 157CNKB:C
input double coofLot=1;//>MDD8F85=B ;>B0
input int spred=15; // !?@54 [Pips]
input int slip=15;//@>A:0;L7K20=85 [Pips]
input long Magic=1;//038:
input bool alert=true;//;5@B [2:;/2K:;]
input bool alert_sound=false;//2C: 0;5@B0 [2:;/2K:;]
input int wt_begin_hh=8;//0G0;> [hours]
input int wt_begin_mm=0;//0G0;> [min]
input int wt_end_hh=20;//>=5F [hours]
input int wt_end_mm=0;//>=5F [min]
input string s1=" " +   ";//   1
input double or1_risk=2;// 8A: [%]
input int or1_take_pr=80;//"59: [Pips]
input int or1_stop=30;//!B>? ;>AA [Pips]
input string s3="-----------------------";//   2
input double or2_risk=40;//>;O >B 1 >@45@0 [%]
input int or2_take_pr=80;//"59: [Pips]
input string s4="-----------------------";//   3
input double or3_risk=20;//>;O >B 1 >@45@0 [%]
input int or3_take_pr=80;//"59: [Pips]
input string s5="-----------------------";//   4
input double or4_risk=0;//>;O >B 1 >@45@0 [%]
input int or4_take_pr=0;//"59: [Pips]
input string s6="-----------------------";//    5
input double or5_risk=0;//>;O >B 1 >@45@0 [%]
input int or5_take_pr=0;//"59: [Pips]
input double min_lot=0.1;//8=8<0;L=K9 >1J5< ;>B0
input string com343="!"  # / #+"";//-----------------------
input bool lev_use=true;//A?>;L7>20BL ;8=8N [2:;/2K:;]
input int lev_size=1;//">;I8=0 C@>2=O
input color lev_color=clrLightGray;//&25B C@>2=O
input ENUM_LINE_STYLE lev_style=STYLE_SOLID;//"8? C@>2=O
input string com1="!"  ";//-----------------------
input bool But_use=true;//B>1@060BL :=>?:8 [2:;/2K:;]
input int But_x=60;//!<5I5=85 ?> %
input int But_y=185;//!<5I5=85 ?> #
input int But_dist=15;// 0AAB>O=85 <564C :=>?:0<8
input int But_width=160;// (8@8=0
input int But_height=25;// KA>B0
input int But_font_size=10; // @07<5@ H@8DB0
input color But_clr=clrDarkGray; //&255B B5:AB0
input color But_back_clr=clrBlack; // &25B D>=0
input color But_border_clr=clrDarkGray; // F25B 3@0=8FK
input string com666="!"  $. ";//-------------------------------
input bool Lab_use=true;//B>1@060BL B5:AB [2:;/2K:;]
input color Lab_colorText=clrDarkGray; // &25B B5:AB0
input int Lab_size=8; // 07<5@ H@8DB0
input int Lab_offset_x=15; // !<5I5=85 ?> %
input int Lab_offset_y=20; // !<5I5=85 ?> Y
input int Lab_distText=15; // 0AAB>O=85 <564C AB@>:0<8
//---Global Var----
CArrayObj *netOrders;
CArrayDouble *riskOrders;
CArrayInt *takeOrders;
MqlTick last_tick;
CSymbolInfo *symbol_info;
ulong netTickets[5];
CButton *btnWork;
CChartObjectHLine *lineZero;
CChartObjectLabel *labStopLevel;
CChartObjectLabel *labBalance;
CChartObjectLabel *labGain;
CChartObjectLabel *labDrowdown;
CChartObjectLabel *labAllProfit;
CChartObjectLabel *labAllLost;
CChartObjectLabel *labNett;
CChartObjectLabel *labTotalVolume;
CChartObjectLabel *labTimeWork;
int netSize;
int index_last;
int count_orders;
int count_positions;
string netType;
double valueFirstOrder;
double undamage_price;
datetime last_checking;
datetime last_open;
bool workingNet;
double textLoss;
double textProfit;
double textBalance;
double textGain;
double textDrowdown;
double textNett;
double textVolume;
double textTimeWorl;
double maxBalance;
double startBalance;
bool notFirst;
long workTime;
long lastTime;
ulong lastTick;
int max_spread;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void SetParams()
{
riskOrders.Clear();
riskOrders.Add(or1_risk);
riskOrders.Add(or2_risk);
riskOrders.Add(or3_risk);
riskOrders.Add(or4_risk);
riskOrders.Add(or5_risk);
takeOrders.Clear();
takeOrders.Add(or1_take_pr);
takeOrders.Add(or2_take_pr);
takeOrders.Add(or3_take_pr);
takeOrders.Add(or4_take_pr);
takeOrders.Add(or5_take_pr);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void reculcOrders()
{
int count=0;
index_last=0;
for(int i=0;i<netSize;i++)
{
if(netTickets[i]!=0)
{
count++;
}
}
for(int i=netSize-1;i>=0;i--)
{
if(netTickets[i]!=0)
{
index_last=i+1;
break;
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double culcLot(int numb)
{
if(numb==0)
{
CAccountInfo account_info=new CAccountInfo();
symbol_info.Refresh();
valueFirstOrder=(riskOrders.At(0)/100*account_info.Balance())/(or1_stop+symbol_info.Spread())*coofLot;
if(valueFirstOrder<min_lot)
valueFirstOrder=min_lot;
if(valueFirstOrder>symbol_info.LotsMax())
valueFirstOrder=symbol_info.LotsMax();
return valueFirstOrder;
}
else
{
symbol_info.Refresh();
double l_lot=valueFirstOrder*riskOrders.At(numb)/100;
if(l_lot<min_lot) l_lot=min_lot;
if(l_lot>symbol_info.LotsMax()) l_lot=symbol_info.LotsMax();
return l_lot;
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void closeAll()
{
CPositionInfo pos_inf=new CPositionInfo();
COrderInfo ord_inf=new COrderInfo();
CTrade my_trade=new CMyTrade();
for(int i=0;i<netSize;i++)
{
if(ord_inf.Select(netTickets[i]))
{
my_trade.OrderDelete(ord_inf.Ticket());
netTickets[i]=0;
}
}
pos_inf.Select(_Symbol);
my_trade.PositionClose(pos_inf.Ticket(),slip);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void fixPriceFirstOrd()
{
COrderInfo ord_inf=new COrderInfo();
if(index_last==1)
{
if(!ord_inf.Select(netTickets[0])) return;
SymbolInfoTick(_Symbol,last_tick);
if(netType==BUY)
{
int dist=(int)((ord_inf.PriceOpen()-last_tick.ask)/_Point);
if(dist>set_dist_price)
{
double price=last_tick.ask+set_dist_price*_Point;
double sl=price-or1_stop*_Point;
double tp=price+or1_take_pr*_Point;
CMyTrade my_trade=new CMyTrade();
my_trade.Modify(netTickets[0],price,sl,tp);
}
}
else
if(netType==SELL)
{
int dist=(int)((last_tick.bid-ord_inf.PriceOpen())/_Point);
if(dist>set_dist_price)
{
double price=last_tick.bid-set_dist_price*_Point;
double sl=price+or1_stop*_Point;
double tp=price-or1_take_pr*_Point;
CMyTrade my_trade=new CMyTrade();
my_trade.Modify(netTickets[0],price,sl,tp);
}
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void doUndamage()
{
CPositionInfo pos_inf=new CPositionInfo();
pos_inf.Select(_Symbol);
if(index_last<=2 || pos_inf.Ticket()<=0) return;
CTrade my_trade=new CTrade();
COrderInfo ord_inf=new COrderInfo();
for(int i=netSize-1;i>=0;i--)
{
if(!PositionSelectByTicket(netTickets[i])) continue;
double cur_sl=PositionGetDouble(POSITION_SL);
double cur_tp=PositionGetDouble(POSITION_TP);
if(Equal(cur_sl,0)==0 && Equal(cur_tp,0)==0) continue;
ctrLine();
if(Equal(cur_sl,undamage_price)==0 || undamage_price==0) return;
//Print("Pos Tick: ",netTickets[i]," PosStop: ",cur_sl,"; PosTake: ",cur_tp);
SymbolInfoTick(_Symbol,last_tick);
if((netType==BUY && undamage_price>=last_tick.bid) || (netType==SELL && undamage_price<=last_tick.ask))
{
closeAll();
return;
}
//Print(Traders());
bool suc=my_trade.PositionModify(netTickets[i],undamage_price,PositionGetDouble(POSITION_TP));
if(!suc)
Print("UndamageModify Error! #",my_trade.ResultRetcode()," ask: ",last_tick.ask," bid:",last_tick.bid);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void ctrLine()
{
if(index_last<=2)
{
lineZero.Delete();
return;
}
CPositionInfo pos_inf = new CPositionInfo();
CSymbolInfo sym_inf = new CSymbolInfo();
CDealInfo deal_inf= new CDealInfo();
symbol_info.Name(_Symbol);
SymbolInfoTick(_Symbol,last_tick);
if(pos_inf.Ticket()<=0) return;
double AllProfit=0;
double volumeLots=0;
for(int i=0;i<netSize;i++)
{
if(!pos_inf.SelectByTicket(netTickets[i])) continue;
double temp=pos_inf.Profit()+pos_inf.Commission()+pos_inf.Swap();
AllProfit+=temp;
}
textBalance=AllProfit;
double TickValue=symbol_info.TickValue();
if(netType==BUY)
{
double dev=volumeLots*TickValue;
if(dev==0)
return;
double bid=NormalizeDouble(last_tick.bid,Digits());
int pips=(int)MathFloor(AllProfit/dev);
while(true)
{
if(AllProfit-pips*volumeLots<0) pips--;
else break;
}
pips-=set_add_undamage;
undamage_price=NormalizeDouble(bid-pips*_Point,Digits());
Print("Pips: ",pips," UDP: ",undamage_price);
if(lev_use)
lineZero.Create(0,"ZeroLine",0,undamage_price);
}
else if(netType==SELL)
{
double dev=volumeLots*TickValue;
if(dev==0)
return;
double ask=NormalizeDouble(last_tick.ask,Digits());
int pips=(int)MathFloor(AllProfit/dev);
while(true)
{
if(AllProfit-pips*volumeLots<0) pips--;
else break;
}
pips-=set_add_undamage;
undamage_price=NormalizeDouble(ask+pips*_Point,Digits());
Print("Pips: ",pips," UDP: ",undamage_price);
if(lev_use)
lineZero.Create(0,"ZeroLine",0,undamage_price);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void conNet()
{
if(!HistorySelect(last_checking,TimeCurrent())) return;
COrderInfo ord_inf=new COrderInfo();
if(index_last>=netSize || index_last<1) return;
if(ord_inf.Select(netTickets[index_last-1])) return;
CPositionInfo pos_inf=new CPositionInfo();
pos_inf.Select(_Symbol);
SymbolInfoTick(_Symbol,last_tick);
if(netType==BUY)
{
CMyTrade ord= netOrders.At(index_last);
double price=last_tick.ask+_Point*set_step;
double l_lot=culcLot(index_last);
string comment=IntegerToString(index_last);
int sl=(int)MathAbs((pos_inf.StopLoss()-last_tick.ask)/_Point);
netTickets[index_last]=ord.buyStop(price,l_lot,sl,or1_take_pr,Magic,slip,comment);
index_last++;
}
else if(netType==SELL)
{
CMyTrade ord=netOrders.At(index_last);
double price=last_tick.bid-_Point*set_step;
double l_lot=culcLot(index_last);
string comment=IntegerToString(index_last);
int sl=(int)MathAbs((pos_inf.StopLoss()-last_tick.bid)/_Point);
netTickets[index_last]=ord.sellStop(price,l_lot,sl,or1_take_pr,Magic,slip,comment);
index_last++;
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void culcParam()
{
CDealInfo deal_inf=new CDealInfo();
if(!HistorySelect(last_checking,TimeCurrent())) return;
int his_tot=HistoryDealsTotal();
for(int i=0;i<his_tot;i++)
{
deal_inf.SelectByIndex(i);
ulong t=deal_inf.Ticket();
if(t==lastTick) break;
if(deal_inf.Magic()!=Magic || deal_inf.Symbol()!=_Symbol) continue;
double pr=deal_inf.Profit()+deal_inf.Commission()+deal_inf.Commission();
if(pr>0) textProfit+=pr;
else textLoss+=pr;
textVolume+=deal_inf.Volume();
}
for(int i=0;i<his_tot;i++)
{
deal_inf.SelectByIndex(i);
ulong t=deal_inf.Ticket();
if(t==lastTick) break;
if(deal_inf.Magic()!=Magic || deal_inf.Symbol()!=_Symbol) continue;
lastTick=deal_inf.Ticket();
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string Traders()
{
CPositionInfo pos_inf=new CPositionInfo();
COrderInfo ord_inf=new COrderInfo();
CDealInfo deal_inf=new CDealInfo();
if(!HistorySelect(last_checking,TimeCurrent())) return "";
int ord_tot=OrdersTotal();
string s_ticket="Orders("+IntegerToString(ord_tot)+"): ";
string s_add=" Stops: ";
count_orders=0;
count_positions=0;
for(int i=0;i<ord_tot;i++)
{
ord_inf.SelectByIndex(i);
if(ord_inf.Magic()!=Magic || ord_inf.Symbol()!=_Symbol) continue;
count_orders++;
s_ticket+=IntegerToString(ord_inf.Ticket())+" ";
int index=(int)StringToInteger(ord_inf.Comment());
if(index==0)
{
}
}
int pos_tot=PositionsTotal();
s_ticket+="; Positions("+IntegerToString(pos_tot)+"): ";
for(int i=0;i<pos_tot;i++)
{
pos_inf.SelectByIndex(i);
if(pos_inf.Magic()!=Magic || pos_inf.Symbol()!=_Symbol) continue;
s_ticket+=IntegerToString(pos_inf.Ticket())+" ";
s_add+=DoubleToString(pos_inf.StopLoss(),Digits())+" ";
count_positions++;
}
s_ticket+="; netTickets("+IntegerToString(netSize)+"): ";
for(int i=0;i<netSize;i++)
{
s_ticket+=IntegerToString(netTickets[i])+" ";
}
return (s_ticket+s_add);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CheckTimeWork()
{
datetime time=TimeCurrent();
int hh = (int)(time/60/60%24);
int mm = (int)(time/60%60);
int sec_beg = wt_begin_hh*60*60+wt_begin_mm*60;
int sec_end = wt_end_hh*60*60+wt_end_mm*60;
int sec_now = hh*60*60 + mm*60;
if(sec_now>=sec_beg && sec_now<sec_end)
{
return true;
}
return false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CreateLabel(CChartObjectLabel *obj,string name,color textColor,int FontSize,int x,int y)
{
bool answ=obj.Create(0,name,0,x,y);
obj.Color(textColor);
obj.FontSize(FontSize);
ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
return answ;
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
workTime=1;
lastTime=TimeCurrent();
index_last=0;
netSize=5;
netOrders=new CArrayObj();
riskOrders=new CArrayDouble();
CAccountInfo account_info=new CAccountInfo();
symbol_info=new CSymbolInfo();
takeOrders=new CArrayInt();
symbol_info.Name(_Symbol);
symbol_info.Refresh();
ArrayInitialize(netTickets,0);
last_checking=TimeCurrent();
if(!notFirst)
{
startBalance=account_info.Balance();
workingNet=true;
textLoss=0;
textProfit=0;
if(coofLot==0)
{
Alert("5?@028;L=> 22545=K ?0@0<5B@K! >MDD8F85=B =5 <>65B 1KBL @025= 0!");
return INIT_FAILED;
}
}
for(int i=0;i<netSize;i++)
{
netOrders.Add(new CMyTrade());
}
SetParams();
for(int i=0;i<netSize;i++)
{
if(riskOrders.At(i)<=0)
{
netSize=i;
break;
}
}
if(netSize<2)
{
Alert("5?@028;L=> 22545=K ?0@0<5B@K!");
return INIT_FAILED;
}
btnWork=new CButton();
if(But_use)
{
string nameSell="Destroy";
btnWork.Create(0,nameSell,0,But_x-But_width/2,But_y-But_height/2,But_x+But_width/2,But_y+But_height/2);
btnWork.Text("Destroy!");
btnWork.Color(But_clr);
btnWork.ColorBackground(But_back_clr);
btnWork.ColorBorder(But_border_clr);
ObjectSetInteger(0,nameSell,OBJPROP_CORNER,CORNER_LEFT_UPPER);
}
lineZero=new CChartObjectHLine();
if(lev_use)
{
string nameLine="ZeroLine";
lineZero.Color(lev_color);
lineZero.Width(lev_size);
lineZero.Style(lev_style);
}
if(Lab_use)
{
labAllLost=new CChartObjectLabel();
labAllProfit=new CChartObjectLabel();
labBalance=new CChartObjectLabel();
labDrowdown=new CChartObjectLabel();
labGain=new CChartObjectLabel();
labNett=new CChartObjectLabel();
labStopLevel=new CChartObjectLabel();
labTimeWork=new CChartObjectLabel();
labTotalVolume=new CChartObjectLabel();
int x=Lab_offset_x,y=Lab_offset_y,dist=Lab_distText;
bool res;
res=CreateLabel(labStopLevel,"StopLev",Lab_colorText,Lab_size,x,y);
y+=dist;
res=CreateLabel(labBalance,"Balance",Lab_colorText,Lab_size,x,y);
y+=dist;
res=CreateLabel(labGain,"Gain",Lab_colorText,Lab_size,x,y);
y+=dist;
res=CreateLabel(labDrowdown,"DrowDown",Lab_colorText,Lab_size,x,y);
y+=dist;
res=CreateLabel(labAllProfit,"AllProfit",Lab_colorText,Lab_size,x,y);
y+=dist;
res=CreateLabel(labAllLost,"AllLost",Lab_colorText,Lab_size,x,y);
y+=dist;
res=CreateLabel(labNett,"Nett",Lab_colorText,Lab_size,x,y);
y+=dist;
res=CreateLabel(labTotalVolume,"TotalV",Lab_colorText,Lab_size,x,y);
y+=dist;
res=CreateLabel(labTimeWork,"TimeWork",Lab_colorText,Lab_size,x,y);
y+=dist;
CSymbolInfo s_inf=new CSymbolInfo();
s_inf.Name(_Symbol);
labStopLevel.SetString(OBJPROP_TEXT,"Stop Level: "+IntegerToString(s_inf.StopsLevel()));
}
notFirst=true;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
/*CSymbolInfo si=new CSymbolInfo();
si.Name(_Symbol);
Comment("Spread: ",si.Spread());
if(si.Spread()>max_spread) max_spread=si.Spread();*/
if(index_last==0)
{
//culcParam();
}
if(!CheckTimeWork())
{
if(btnWork.IsEnabled())
{
workingNet=false;
btnWork.Text(PLAY);
btnWork.Disable();
}
}
else
{
if(!btnWork.IsEnabled())
{
workingNet=true;
btnWork.Text(STOP);
workTime=0;
btnWork.Enable();
}
}
if(workingNet)
{
if(lastTime!=TimeCurrent())
{
workTime+=TimeCurrent()-lastTime;
lastTime=TimeCurrent();
}
if(index_last==0)
{
symbol_info.Refresh();
if(symbol_info.Spread()<spred)
{
int imp=checkImp(period,set_count_bar_imp,set_imp);
if(imp==2) //BuyStop
{
SymbolInfoTick(_Symbol,last_tick);
CMyTrade ord= netOrders.At(0);
double price=last_tick.ask+_Point*set_dist_price;
double l_lot=culcLot(0);
string comment="0";
netTickets[0]=ord.buyStop(price,l_lot,or1_stop,or1_take_pr,Magic,slip,comment);
index_last=1;
last_checking=TimeCurrent();
netType=BUY;
last_open=TimeCurrent();
}
else if(imp==1) //SellStop
{
SymbolInfoTick(_Symbol,last_tick);
CMyTrade ord= netOrders.At(0);
double price=last_tick.bid-_Point*set_dist_price;
double l_lot=culcLot(0);
string comment="0";
netTickets[0]=ord.sellStop(price,l_lot,or1_stop,or1_take_pr,Magic,slip,comment);
index_last=1;
last_checking=TimeCurrent();
netType=SELL;
last_open=TimeCurrent();
}
}
}
else
{
fixPriceFirstOrd();
conNet();
doUndamage();
}
}
if(But_use)
{
if(btnWork.Pressed())
{
btnWork.Pressed(false);
if(btnWork.Text()==STOP)
{
workingNet=false;
btnWork.Text(PLAY);
}
else
{
workingNet=true;
btnWork.Text(STOP);
workTime=0;
}
}
}
if(Lab_use)
{
CAccountInfo acc_inf=new CAccountInfo();
if(acc_inf.Balance()>maxBalance) maxBalance=acc_inf.Balance();
else
{
double dd=(maxBalance-acc_inf.Balance()+textBalance)/maxBalance*100;
if(dd>textDrowdown)
textDrowdown=dd;
}
textNett=textProfit+textLoss;
labAllLost.SetString(OBJPROP_TEXT,"All loss: "+DoubleToString(textLoss,2));
labAllProfit.SetString(OBJPROP_TEXT,"All Profit: "+DoubleToString(textProfit,2));
labBalance.SetString(OBJPROP_TEXT,"Balance: "+DoubleToString(textBalance,2));
labDrowdown.SetString(OBJPROP_TEXT,"Drowdown: "+DoubleToString(textDrowdown,2));
labGain.SetString(OBJPROP_TEXT,"Gain: "+DoubleToString((acc_inf.Balance()-startBalance)/startBalance*100,2));
labNett.SetString(OBJPROP_TEXT,"Nett: "+DoubleToString(textNett,2));
labTimeWork.SetString(OBJPROP_TEXT,"Working hours: "+DoubleToString(workTime/60/60,0)+":"+DoubleToString(workTime/60%60,0)+" [hh:mm]");
labTotalVolume.SetString(OBJPROP_TEXT,"Total volume: "+DoubleToString(textVolume,2));
}
}
//+------------------------------------------------------------------+
void OnTrade()
{
CPositionInfo pos_inf=new CPositionInfo();
COrderInfo ord_inf=new COrderInfo();
CHistoryOrderInfo his_inf=new CHistoryOrderInfo();
CDealInfo deal_inf=new CDealInfo();
if(!HistorySelect(last_checking,TimeCurrent())) return;
pos_inf.Select(_Symbol);
if(pos_inf.Ticket()<=0) // #40;5=85 >48=>:8E >@45@>2
{
for(int i=1;i<netSize;i++)
{
if(!ord_inf.Select(netTickets[i]))continue;
CTrade my_trade=new CTrade();
my_trade.OrderDelete(ord_inf.Ticket());
netTickets[i]=0;
}
}
for(int i=0;i<netSize;i++) //@>25@:0 B8:8B>2
{
if(netTickets[i]==0) continue;
ulong t_pos=pos_inf.Ticket();
if(!ord_inf.Select(netTickets[i]) && t_pos<=0)
{
netTickets[i]=0;
}
}
reculcOrders();
ctrLine();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
labAllLost.Delete();
labAllProfit.Delete();
labBalance.Delete();
labDrowdown.Delete();
labGain.Delete();
labNett.Delete();
labStopLevel.Delete();
labTimeWork.Delete();
labTotalVolume.Delete();
btnWork.Destroy();
lineZero.Delete();
Print("Max spread: ",max_spread);
}
//+------------------------------------------------------------------+