//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #property description "Portfolio Manager" #property description "Expert for Portfolio Modeller indicator" #property description "Transcendreamer" #property strict //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #define MAX_SYMBOLS 32 #define FONT_TEXT "Verdana" #define FONT_BUTTON "Wingdings" #define SIZE_TEXT 9 #define SIZE_BUTTON 14 #define SPACING 15 #define XMARGIN 5 #define YMARGIN 25 #define BUTTON_SPACE 23 #define BUTTON_YLINE 3 #define EQUAL '=' #define COLON ':' #define COMMA ',' #define TILDE '~' #define VBAR '|' #define HASH '#' #define SLASH "/" #define BKSLASH "\\" #define CHV_LEFT "<" #define CHV_RIGHT ">" #define BRK_LEFT "[" #define BRK_RIGHT "]" #define BRC_LEFT "{" #define BRC_RIGHT "}" #define PAR_LEFT "(" #define PAR_RIGHT ")" #define CHAR_BUY 221 #define CHAR_SELL 222 #define CHAR_CLOSE 253 #define CHAR_TRANS 91 #define CHAR_SAVE 61 #define KEY_SELL 219 #define KEY_BUY 221 #define KEY_CLOSE 220 #define KEY_TRANS 191 #define KEY_SAVE 192 #define LINES_COLOR clrGreen //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ input string ______GENERAL_______="______GENERAL_______"; input string Portfolio_Name=""; input int Magic_Number=0; input bool Terminal_Mode=false; input string Comment_Filter=""; input string ______TRADING______="______TRADING______"; input double Take_Profit=0; input double Stop_Loss=0; input double Breakeven_Level=0; input double Reversals_Factor=1; input int Reversals_Count=0; enum ENUM_SCALING {no_scaling,by_increment,last_volume,full_volume,next_volume}; input ENUM_SCALING Scaling_Profit=no_scaling; input ENUM_SCALING Scaling_Loss=no_scaling; input ENUM_SCALING Scaling_Breakeven=no_scaling; input ENUM_SCALING Scaling_Reversal=no_scaling; input double Max_Volume=0; input int Lots_Digits=2; input int Retry_Delay=500; input int Retry_Times=50; input string ______AUTOMATE______="______AUTOMATE______"; input datetime Starting_From=D'2012.01.01 00:00'; input datetime Finishing_From=D'2035.01.01 00:00'; input bool Use_Lines=false; input bool Use_Adding=false; input bool Use_Correction=false; input int Iteration_Minutes=60; input double Adding_Threshold=0; input double Correction_Profit=0; input double Correction_Loss=0; input double Gap_Protect=100; input bool Check_Symbols=true; input string ______ROLLOVER______="______ROLLOVER______"; input int Stop_Hour=23; input int Stop_Minute=45; input int Resume_Hour=00; input int Resume_Minute=25; input string ______FILTERS______="______FILTERS______"; enum ENUM_FILTER {zero,model,main,fast,slow,upper,lower}; input double Filter_Quality=0; input ENUM_FILTER Filter_Line_Buy=zero; input ENUM_FILTER Filter_Line_Sell=zero; enum ENUM_OPERATOR {never,above,below,always}; input ENUM_OPERATOR Filter_Op_Buy=never; input ENUM_OPERATOR Filter_Op_Sell=never; enum ENUM_REVERSAL {reverse,close,ignore}; input ENUM_REVERSAL Reversal_Signal=ignore; enum ENUM_PROGRESS {equal,fibo,martin,linear}; input ENUM_PROGRESS Volume_Progression=equal; input string ______TRAILING______="______TRAILING______"; input bool Use_Trailing=false; input ENUM_FILTER Trailing_Long=zero; input ENUM_FILTER Trailing_Short=zero; input ENUM_FILTER Condition_Long=zero; input ENUM_FILTER Condition_Short=zero; input string ______OTHER______="______OTHER______"; input color Text_Color=clrMagenta; input ENUM_BASE_CORNER Text_Corner=CORNER_LEFT_LOWER; input bool Show_Levels=true; input bool Show_Trades=false; input bool Auto_Alerts=false; input bool Push_Notifications=false; input bool Manual_Confirm=true; input bool Template_Autosave=true; input int Screenshot_Seconds=0; input int Screenshot_Width=640; input int Screenshot_Height=480; input int Start_Delay=1000; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool error; int window; long chart; string currency; int dimension,increment; int reversals; bool breakeven; string SYMBOLS[MAX_SYMBOLS]; double LOTS[MAX_SYMBOLS]; double profit,volume; double limit_profit,limit_loss,limit_breakeven; double previous=EMPTY_VALUE,current=EMPTY_VALUE; double level_buy,level_sell; double threshold,quality; datetime iteration=0,screen_timer=0; datetime now_time; MqlDateTime str_time; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnInit() { SetupInitial(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { CleanAll(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void SetupInitial() { CleanAll(); Sleep(Start_Delay); error=false; chart=ChartID(); window=ObjectFind(chart,"Data-label-"+Portfolio_Name+"-1"); currency=AccountInfoString(ACCOUNT_CURRENCY); if(Portfolio_Name=="") { error=true; MessageBox("Empty portfolio name!","ERROR",MB_ICONERROR); return; } if(window<0) { error=true; MessageBox("Portfolio "+Portfolio_Name+" not found!","ERROR",MB_ICONERROR); return; } int x=XMARGIN; int y=BUTTON_YLINE; PlaceLabel("Button_Close",x,y,Text_Corner,CharToString(CHAR_CLOSE),Text_Color,FONT_BUTTON,SIZE_BUTTON); x+=BUTTON_SPACE; PlaceLabel("Button_Buy",x,y,Text_Corner,CharToString(CHAR_BUY),Text_Color,FONT_BUTTON,SIZE_BUTTON); x+=BUTTON_SPACE; PlaceLabel("Button_Sell",x,y,Text_Corner,CharToString(CHAR_SELL),Text_Color,FONT_BUTTON,SIZE_BUTTON); x+=BUTTON_SPACE; PlaceLabel("Button_Trans",x,y,Text_Corner,CharToString(CHAR_TRANS),Text_Color,FONT_BUTTON,SIZE_BUTTON); x+=BUTTON_SPACE; PlaceLabel("Button_Save",x,y,Text_Corner,CharToString(CHAR_SAVE),Text_Color,FONT_BUTTON,SIZE_BUTTON); RestoreGlobals(); ReadScreenFormula(); OnTick(); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CleanAll() { for(int n=ObjectsTotal(chart,window,-1); n>=1; n--) { string name=ObjectName(chart,n-1,window,-1); if(StringFind(name,"Status-line-"+Portfolio_Name)!=-1) ObjectDelete(chart,name); if(StringFind(name,"Stop-"+Portfolio_Name)!=-1) ObjectDelete(chart,name); if(StringFind(name,"Take-"+Portfolio_Name)!=-1) ObjectDelete(chart,name); if(StringFind(name,"Zero-"+Portfolio_Name)!=-1) ObjectDelete(chart,name); if(StringFind(name,"Safe-"+Portfolio_Name)!=-1) ObjectDelete(chart,name); } ObjectDelete(chart,"Button_Sell"); ObjectDelete(chart,"Button_Buy"); ObjectDelete(chart,"Button_Close"); ObjectDelete(chart,"Button_Trans"); ObjectDelete(chart,"Button_Save"); GlobalVariableDel("Volume-"+Portfolio_Name); GlobalVariableDel("Iteration-"+Portfolio_Name); GlobalVariableDel("Threshold-"+Portfolio_Name); GlobalVariableDel("Increment-"+Portfolio_Name); GlobalVariableDel("Breakeven-"+Portfolio_Name); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) { if(error) return; bool buy=false,sell=false,close=false,trans=false,save=false; if(id==CHARTEVENT_OBJECT_CLICK) { if(sparam=="Button_Buy") buy=true; if(sparam=="Button_Sell") sell=true; if(sparam=="Button_Close") close=true; if(sparam=="Button_Trans") trans=true; if(sparam=="Button_Save") save=true; } if(id==CHARTEVENT_KEYDOWN) { if(int(lparam)==KEY_BUY) buy=true; if(int(lparam)==KEY_SELL) sell=true; if(int(lparam)==KEY_CLOSE) close=true; if(int(lparam)==KEY_TRANS) trans=true; if(int(lparam)==KEY_SAVE) save=true; } if(buy) { Print(Portfolio_Name+": Manual BUY"); if(DoOpen(GetVolume(increment+1),false,increment+1)) { UpdateStatus(); DoSave(false); } } if(sell) { Print(Portfolio_Name+": Manual SELL"); if(DoOpen(-GetVolume(increment+1),false,increment+1)) { UpdateStatus(); DoSave(false); } } if(close) { Print(Portfolio_Name+": Manual CLOSE"); if(DoClose(false,0)) { UpdateStatus(); DoSave(false); } } if(trans) { Print(Portfolio_Name+": Manual TRANS"); if(DoTrans(volume,false,0)) { UpdateStatus(); DoSave(false); } } if(save) { DoSave(false); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { if(error) return; UpdateStatus(); CheckLimits(); CheckTrailing(); CheckIterations(); CheckLines(); MakeScreenshot(0); previous=current; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void UpdateStatus() { now_time=TimeCurrent(); TimeToStruct(now_time,str_time); current=GlobalVariableGet("Portfolio-"+Portfolio_Name); quality=GlobalVariableGet("Quality-"+Portfolio_Name); threshold=GlobalVariableGet("Threshold-"+Portfolio_Name); increment=(int)GlobalVariableGet("Increment-"+Portfolio_Name); iteration=(int)GlobalVariableGet("Iteration-"+Portfolio_Name); breakeven=(bool)GlobalVariableGet("Breakeven-"+Portfolio_Name); reversals=(int)GlobalVariableGet("Reversals-"+Portfolio_Name); volume=GlobalVariableGet("Volume-"+Portfolio_Name); profit=GetProfit(0); if(Terminal_Mode) if(profit!=0 && volume==0) volume=1; //--- switch(Filter_Line_Buy) { case main: level_buy=GlobalVariableGet("Main-"+Portfolio_Name); break; case fast: level_buy=GlobalVariableGet("Fast-"+Portfolio_Name); break; case slow: level_buy=GlobalVariableGet("Slow-"+Portfolio_Name); break; case upper: level_buy=GlobalVariableGet("Upper-"+Portfolio_Name); break; case lower: level_buy=GlobalVariableGet("Lower-"+Portfolio_Name); break; case model: level_buy=GlobalVariableGet("Model-"+Portfolio_Name); break; default: level_buy=0; break; } //--- switch(Filter_Line_Sell) { case main: level_sell=GlobalVariableGet("Main-"+Portfolio_Name); break; case fast: level_sell=GlobalVariableGet("Fast-"+Portfolio_Name); break; case slow: level_sell=GlobalVariableGet("Slow-"+Portfolio_Name); break; case upper: level_sell=GlobalVariableGet("Upper-"+Portfolio_Name); break; case lower: level_sell=GlobalVariableGet("Lower-"+Portfolio_Name); break; case model: level_sell=GlobalVariableGet("Model-"+Portfolio_Name); break; default: level_sell=0; break; } //--- switch(Scaling_Loss) { case no_scaling: limit_loss=Stop_Loss; break; case by_increment: limit_loss=Stop_Loss*increment; break; case last_volume: limit_loss=Stop_Loss*GetVolume(increment); break; case next_volume: limit_loss=Stop_Loss*GetVolume(increment+1); break; case full_volume: limit_loss=Stop_Loss*MathAbs(volume); break; default: limit_loss=Stop_Loss; break; } //--- switch(Scaling_Profit) { case no_scaling: limit_profit=Take_Profit; break; case by_increment: limit_profit=Take_Profit*increment; break; case last_volume: limit_profit=Take_Profit*GetVolume(increment); break; case next_volume: limit_profit=Take_Profit*GetVolume(increment+1); break; case full_volume: limit_profit=Take_Profit*MathAbs(volume); break; default: limit_profit=Take_Profit; break; } //--- switch(Scaling_Breakeven) { case no_scaling: limit_breakeven=Breakeven_Level; break; case by_increment: limit_breakeven=Breakeven_Level*increment; break; case last_volume: limit_breakeven=Breakeven_Level*GetVolume(increment); break; case next_volume: limit_breakeven=Breakeven_Level*GetVolume(increment+1); break; case full_volume: limit_breakeven=Breakeven_Level*MathAbs(volume); break; default: limit_breakeven=Breakeven_Level; break; } //--- int offset=YMARGIN; string text=("Name: "+Portfolio_Name); string name=("Status-line-"+Portfolio_Name+"-A"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); offset+=SPACING; text=("Volume: "+DoubleToString(volume,2)); name=("Status-line-"+Portfolio_Name+"-B"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); offset+=SPACING; text=("Profit: "+DoubleToString(profit,2)+" "+currency); name=("Status-line-"+Portfolio_Name+"-C"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); offset+=SPACING; text=("Stop-loss: "+DoubleToString(limit_loss,2)+" "+currency); name=("Status-line-"+Portfolio_Name+"-D"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); offset+=SPACING; text=("Take-profit: "+DoubleToString(limit_profit,2)+" "+currency); name=("Status-line-"+Portfolio_Name+"-E"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); //--- if(Breakeven_Level!=0) { offset+=SPACING; text=("Break-even: "+(breakeven?("ACTIVE"):(DoubleToString(limit_breakeven,2)+" "+currency))); name=("Status-line-"+Portfolio_Name+"-F"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); } //--- if(Use_Trailing) { offset+=SPACING; text=("Trailing: ACTIVE"); name=("Status-line-"+Portfolio_Name+"-G"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); } //--- if(Use_Adding || Use_Correction) { offset+=SPACING; text=("Increment: "+IntegerToString(increment)); name=("Status-line-"+Portfolio_Name+"-H"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); offset+=SPACING; if(iteration==0) text=("Iteration: N/A"); else text=("Iteration: "+TimeToString(iteration,TIME_MINUTES|TIME_SECONDS)); name=("Status-line-"+Portfolio_Name+"-I"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); offset+=SPACING; text=("Threshold: "+DoubleToString(threshold,2)+" "+currency); name=("Status-line-"+Portfolio_Name+"-J"); PlaceLabel(name,XMARGIN,offset,Text_Corner,text,Text_Color,FONT_TEXT,SIZE_TEXT); } //--- if(Show_Levels) if(volume!=0 && profit!=0) if(current!=EMPTY_VALUE) { if(true) { double zero=NormalizeDouble((current-profit/volume),2); PlaceHorizontal("Zero-"+Portfolio_Name,zero,LINES_COLOR,STYLE_DASHDOTDOT,true,false,false); } if(Stop_Loss!=0) { double stop=NormalizeDouble(current-(limit_loss+profit)/volume,2); PlaceHorizontal("Stop-"+Portfolio_Name,stop,LINES_COLOR,STYLE_DASHDOTDOT,true,false,false); } if(Take_Profit!=0) { double take=NormalizeDouble(current+(limit_profit-profit)/volume,2); PlaceHorizontal("Take-"+Portfolio_Name,take,LINES_COLOR,STYLE_DASHDOTDOT,true,false,false); } if(Breakeven_Level!=0) { double be=NormalizeDouble(current+(limit_breakeven-profit)/volume,2); PlaceHorizontal("Safe-"+Portfolio_Name,be,LINES_COLOR,STYLE_DASHDOTDOT,true,false,false); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void RestoreGlobals() { double v=StringToDouble(ObjectGetString(chart,"Volume-"+Portfolio_Name,OBJPROP_TEXT)); double i=StringToDouble(ObjectGetString(chart,"Iteration-"+Portfolio_Name,OBJPROP_TEXT)); double n=StringToDouble(ObjectGetString(chart,"Increment-"+Portfolio_Name,OBJPROP_TEXT)); double t=StringToDouble(ObjectGetString(chart,"Threshold-"+Portfolio_Name,OBJPROP_TEXT)); double b=StringToDouble(ObjectGetString(chart,"Breakeven-"+Portfolio_Name,OBJPROP_TEXT)); double r=StringToDouble(ObjectGetString(chart,"Reversals-"+Portfolio_Name,OBJPROP_TEXT)); GlobalVariableSet("Volume-"+Portfolio_Name,v); GlobalVariableSet("Iteration-"+Portfolio_Name,i); GlobalVariableSet("Increment-"+Portfolio_Name,n); GlobalVariableSet("Threshold-"+Portfolio_Name,t); GlobalVariableSet("Breakeven-"+Portfolio_Name,b); GlobalVariableSet("Reversals-"+Portfolio_Name,r); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void BackupGlobals() { string v=DoubleToString(GlobalVariableGet("Volume-"+Portfolio_Name),2); string i=DoubleToString(GlobalVariableGet("Iteration-"+Portfolio_Name),0); string n=DoubleToString(GlobalVariableGet("Increment-"+Portfolio_Name),0); string t=DoubleToString(GlobalVariableGet("Threshold-"+Portfolio_Name),2); string b=DoubleToString(GlobalVariableGet("Breakeven-"+Portfolio_Name),2); string r=DoubleToString(GlobalVariableGet("Reversals-"+Portfolio_Name),2); PlaceLabel("Volume-"+Portfolio_Name,-100,-100,Text_Corner,v,Text_Color,FONT_TEXT,SIZE_TEXT); PlaceLabel("Iteration-"+Portfolio_Name,-100,-120,Text_Corner,i,Text_Color,FONT_TEXT,SIZE_TEXT); PlaceLabel("Increment-"+Portfolio_Name,-100,-120,Text_Corner,n,Text_Color,FONT_TEXT,SIZE_TEXT); PlaceLabel("Threshold-"+Portfolio_Name,-100,-120,Text_Corner,t,Text_Color,FONT_TEXT,SIZE_TEXT); PlaceLabel("Breakeven-"+Portfolio_Name,-100,-100,Text_Corner,b,Text_Color,FONT_TEXT,SIZE_TEXT); PlaceLabel("Reversals-"+Portfolio_Name,-100,-100,Text_Corner,r,Text_Color,FONT_TEXT,SIZE_TEXT); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetProfit(int number) { double result=0; string filter=""; if(number!=0) filter=Portfolio_Name+"."+IntegerToString(number); else if(Terminal_Mode) filter=Comment_Filter; else filter=Portfolio_Name; #ifdef __MQL4__ for(int n=OrdersTotal(); n>=1; n--) { if(!OrderSelect(n-1,SELECT_BY_POS,MODE_TRADES)) continue; if(filter!="") if(StringFind(OrderComment(),filter,0)==-1) continue; result+=OrderProfit()+OrderCommission()+OrderSwap(); } #else for(int n=PositionsTotal(); n>=1; n--) { if(!PositionSelectByTicket(PositionGetTicket(n-1))) continue; if(filter!="") if(StringFind(PositionGetString(POSITION_COMMENT),filter,0)==-1) continue; result+=PositionGetDouble(POSITION_PROFIT)+ PositionGetDouble(POSITION_SWAP)+ PositionGetDouble(POSITION_COMMISSION); } #endif return(result); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double GetVolume(int n) { if(Volume_Progression==equal) { return(1); } else if(Volume_Progression==fibo) { if(n<3) return(1); int f=1,s=1; while(n>2) { f=f+s*2; s=f-s; f=f-s; n--; } return(s); } else if(Volume_Progression==martin) { return(MathPow(2,n-1)); } else if(Volume_Progression==linear) { return(n); } return(1); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Report(string text) { if(Auto_Alerts) { Alert(text); if(Push_Notifications) SendNotification(text); } else Print(text); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Alarm(string text) { Alert(text); if(Push_Notifications) SendNotification(text); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckLimits() { if(Stop_Loss!=0) if(volume!=0) if(profit<=-limit_loss) { if(Reversals_Count==0 || (Reversals_Count>0 && reversals=limit_profit) { Report(Portfolio_Name+": Take-profit triggered at "+DoubleToString(profit,2)); DoClose(true,0); UpdateStatus(); DoSave(true); MakeScreenshot(1); } if(Breakeven_Level!=0) if(breakeven) if(volume!=0) if(profit<=0) { Report(Portfolio_Name+": Break-even triggered at "+DoubleToString(profit,2)); DoClose(true,0); UpdateStatus(); DoSave(true); MakeScreenshot(1); } if(Breakeven_Level!=0) if(!breakeven) if(volume!=0) if(profit>=limit_breakeven) { Report(Portfolio_Name+": Break-even activated at "+DoubleToString(profit,2)); GlobalVariableSet("Breakeven-"+Portfolio_Name,1); BackupGlobals(); UpdateStatus(); DoSave(true); MakeScreenshot(1); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckTrailing() { if(!Use_Trailing) return; if(volume==0) return; if(current==EMPTY_VALUE) return; double trail_long=0; double trail_short=0; double cond_long=0; double cond_short=0; //--- switch(Trailing_Long) { case main: trail_long=GlobalVariableGet("Main-"+Portfolio_Name); break; case fast: trail_long=GlobalVariableGet("Fast-"+Portfolio_Name); break; case slow: trail_long=GlobalVariableGet("Slow-"+Portfolio_Name); break; case upper: trail_long=GlobalVariableGet("Upper-"+Portfolio_Name); break; case lower: trail_long=GlobalVariableGet("Lower-"+Portfolio_Name); break; case model: trail_long=GlobalVariableGet("Model-"+Portfolio_Name); break; case zero: trail_long=0; break; } //--- switch(Trailing_Short) { case main: trail_short=GlobalVariableGet("Main-"+Portfolio_Name); break; case fast: trail_short=GlobalVariableGet("Fast-"+Portfolio_Name); break; case slow: trail_short=GlobalVariableGet("Slow-"+Portfolio_Name); break; case upper: trail_short=GlobalVariableGet("Upper-"+Portfolio_Name); break; case lower: trail_short=GlobalVariableGet("Lower-"+Portfolio_Name); break; case model: trail_short=GlobalVariableGet("Model-"+Portfolio_Name); break; case zero: trail_short=0; break; } //--- switch(Condition_Long) { case main: cond_long=GlobalVariableGet("Main-"+Portfolio_Name); break; case fast: cond_long=GlobalVariableGet("Fast-"+Portfolio_Name); break; case slow: cond_long=GlobalVariableGet("Slow-"+Portfolio_Name); break; case upper: cond_long=GlobalVariableGet("Upper-"+Portfolio_Name); break; case lower: cond_long=GlobalVariableGet("Lower-"+Portfolio_Name); break; case model: cond_long=GlobalVariableGet("Model-"+Portfolio_Name); break; case zero: cond_long=0; break; } //--- switch(Condition_Short) { case main: cond_short=GlobalVariableGet("Main-"+Portfolio_Name); break; case fast: cond_short=GlobalVariableGet("Fast-"+Portfolio_Name); break; case slow: cond_short=GlobalVariableGet("Slow-"+Portfolio_Name); break; case upper: cond_short=GlobalVariableGet("Upper-"+Portfolio_Name); break; case lower: cond_short=GlobalVariableGet("Lower-"+Portfolio_Name); break; case model: cond_short=GlobalVariableGet("Model-"+Portfolio_Name); break; case zero: cond_short=0; break; } //--- if(volume>0) if(trail_long!=EMPTY_VALUE) if(cond_long!=EMPTY_VALUE) if(current<=trail_long) if(current>=cond_long) { Report(Portfolio_Name+": Trailing triggered at "+DoubleToString(profit,2)); DoClose(true,0); UpdateStatus(); DoSave(true); MakeScreenshot(1); } //--- if(volume<0) if(trail_short!=EMPTY_VALUE) if(cond_short!=EMPTY_VALUE) if(current>=trail_short) if(current<=cond_short) { Report(Portfolio_Name+": Trailing triggered at "+DoubleToString(profit,2)); DoClose(true,0); UpdateStatus(); DoSave(true); MakeScreenshot(1); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckIterations() { if(!Use_Adding && !Use_Correction) return; if(current==EMPTY_VALUE) return; if(previous==EMPTY_VALUE) return; now_time=TimeCurrent(); TimeToStruct(now_time,str_time); if(iteration==0) { iteration=Starting_From; while(now_time>=iteration) iteration+=Iteration_Minutes*60; GlobalVariableSet("Iteration-"+Portfolio_Name,iteration); BackupGlobals(); } if(profit==0) { if(now_timeFinishing_From) return; } int minute_now =str_time.hour*60+str_time.min; int minute_stop =Stop_Hour*60+Stop_Minute; int minute_resume =Resume_Hour*60+Resume_Minute; if(minute_now>=minute_stop || minute_now=iteration) iteration+=Iteration_Minutes*60; GlobalVariableSet("Iteration-"+Portfolio_Name,iteration); BackupGlobals(); //--- bool permit_buy=false; if(Filter_Op_Buy==above) if(current>level_buy) if(level_buy!=EMPTY_VALUE) permit_buy=true; if(Filter_Op_Buy==below) if(currentlevel_sell) if(level_sell!=EMPTY_VALUE) permit_sell=true; if(Filter_Op_Sell==below) if(current0) permit_reverse=true; //--- if(Filter_Quality!=0) if(quality!=0) if(quality>Filter_Quality) { permit_buy=false; permit_sell=false; } //--- if(permit_reverse) { if(Reversal_Signal==close) { Report(Portfolio_Name+": Closing at reversal signal..."); DoClose(true,0); UpdateStatus(); DoSave(true); MakeScreenshot(2); } if(Reversal_Signal==reverse) { Report(Portfolio_Name+": Performing positions reversal..."); DoTrans(-volume,true,0); UpdateStatus(); DoSave(true); MakeScreenshot(2); } } //--- if(Use_Adding) { bool check1=(profit<=threshold && Adding_Threshold<0); bool check2=(profit>=threshold && Adding_Threshold>0); bool check3=(Adding_Threshold==0); if((check1 || check2 || check3) && (permit_buy || permit_sell)) { double size=GetVolume(increment+1); Report(Portfolio_Name+": Adding iteration #"+string(increment+1)); if(permit_buy) if(!permit_sell) DoOpen(+size,true,increment+1); if(permit_sell) if(!permit_buy) DoOpen(-size,true,increment+1); UpdateStatus(); DoSave(true); MakeScreenshot(2); } } //--- if(Use_Correction) for(int m=1; m<=increment; m++) { double subprofit=GetProfit(m); double subvolume=GetVolume(m); if(Correction_Loss!=0) if(subprofit<=-Correction_Loss*MathAbs(subvolume)) { Report(Portfolio_Name+": Correcting iteration #"+string(m)); DoTrans(subvolume,true,m); UpdateStatus(); DoSave(true); MakeScreenshot(2); } if(Correction_Profit!=0) if(subprofit>=Correction_Profit*MathAbs(subvolume)) { Report(Portfolio_Name+": Fixing iteration #"+string(m)); DoClose(true,m); UpdateStatus(); DoSave(true); MakeScreenshot(2); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CheckLines() { if(!Use_Lines) return; if(current==EMPTY_VALUE) return; if(previous==EMPTY_VALUE) return; now_time=TimeCurrent(); TimeToStruct(now_time,str_time); if(profit==0) if(now_timeFinishing_From) return; int minute_now =str_time.hour*60+str_time.min; int minute_stop =Stop_Hour*60+Stop_Minute; int minute_resume =Resume_Hour*60+Resume_Minute; if(minute_now>=minute_stop || minute_now=1; n--) { string name=ObjectName(chart,n-1,window,-1); if(ObjectFind(chart,name)!=window) continue; long type=ObjectGetInteger(chart,name,OBJPROP_TYPE); if(type!=OBJ_TREND && type!=OBJ_HLINE) continue; string text=ObjectGetString(chart,name,OBJPROP_TEXT); total_lines++; ArrayResize(line_name,total_lines); ArrayResize(line_type,total_lines); ArrayResize(line_text,total_lines); line_name[total_lines-1]=name; line_type[total_lines-1]=type; line_text[total_lines-1]=text; } //--- for(int x=0; x= level); bool cross_dn = (fixed_previous > level && fixed_current <= level); bool crossing = cross_dn || cross_up; if(!crossing) continue; long counter=INT_MAX; int left=StringFind(command,BRC_LEFT); int right=StringFind(command,BRC_RIGHT); if(left!=-1 && right!=-1) counter=StringToInteger(StringSubstr(command,left+1,right-1)); double modifier=1; left=StringFind(command,PAR_LEFT); right=StringFind(command,PAR_RIGHT); if(left!=-1 && right!=-1) modifier=StringToDouble(StringSubstr(command,left+1,right-1)); //--- if(keyword_setup) { Report(Portfolio_Name+": SETUP line triggered: "+name); string substr[]; int num=StringSplit(command,COLON,substr); if(num!=3) { Report(Portfolio_Name+": syntax problem - command cancelled!"); continue; } string setup=substr[2]; double price=StringToDouble(substr[1]); StringReplace(setup,CharToString(VBAR),CharToString(TILDE)); StringReplace(setup,CharToString(HASH),CharToString(VBAR)); StringReplace(setup,CharToString(COMMA),CharToString(COLON)); StringReplace(setup,(CHV_LEFT),(BRK_LEFT)); StringReplace(setup,(CHV_RIGHT),(BRK_RIGHT)); StringReplace(setup,(SLASH),(CHV_LEFT)); StringReplace(setup,(BKSLASH),(CHV_RIGHT)); long colour=ObjectGetInteger(chart,name,OBJPROP_COLOR); long style=ObjectGetInteger(chart,name,OBJPROP_STYLE); long width=ObjectGetInteger(chart,name,OBJPROP_WIDTH); string newname="AUTO-"+string(i)+"-"+name; ObjectCreate(chart,newname,OBJ_HLINE,window,TimeCurrent(),price); ObjectSetInteger(chart,newname,OBJPROP_COLOR,colour); ObjectSetInteger(chart,newname,OBJPROP_STYLE,style); ObjectSetInteger(chart,newname,OBJPROP_WIDTH,width); ObjectSetString(chart,newname,OBJPROP_TEXT,setup); StringToLower(text); ObjectSetString(chart,name,OBJPROP_TEXT,text); Report(Portfolio_Name+": new line created: "+newname); Report(Portfolio_Name+": new line command: "+setup); UpdateStatus(); DoSave(true); MakeScreenshot(3); continue; } //--- if(keyword_buy) { Report(Portfolio_Name+": BUY line triggered: "+name); Report(Portfolio_Name+": portfolio price: "+DoubleToString(fixed_current,2)); if(fixed_current>level+Gap_Protect) { Report(Portfolio_Name+": gap protection - trade cancelled!"); continue; } DoOpen(+modifier,true,0); StringToLower(text); ObjectSetString(chart,name,OBJPROP_TEXT,text); UpdateStatus(); DoSave(true); MakeScreenshot(3); continue; } //--- if(keyword_sell) { Report(Portfolio_Name+": SELL line triggered: "+name); Report(Portfolio_Name+": portfolio price: "+DoubleToString(fixed_current,2)); if(fixed_current0) if(volume==0) if(fixed_current>level+Gap_Protect) { Report(Portfolio_Name+": gap protection - trade cancelled!"); } else { Report(Portfolio_Name+": UPWARD opening..."); DoOpen(+1,true,0); countdown=true; } if(counter>0) if(volume<0) { Report(Portfolio_Name+": UPWARD reversal..."); DoTrans(-volume*modifier,true,0); countdown=true; } if(countdown) if(counter!=INT_MAX) { string str1=BRC_LEFT+string(counter)+BRC_RIGHT; string str2=BRC_LEFT+string(counter-1)+BRC_RIGHT; StringReplace(text,str1,str2); ObjectSetString(chart,name,OBJPROP_TEXT,text); } if(counter<1) if(volume<=0) { Report(Portfolio_Name+": UPWARD full stop..."); DoClose(true,0); StringToLower(text); ObjectSetString(chart,name,OBJPROP_TEXT,text); } UpdateStatus(); DoSave(true); MakeScreenshot(3); continue; } //--- if(keyword_downward) if(volume>=0) { Report(Portfolio_Name+": DOWNWARD line triggered: "+name); Report(Portfolio_Name+": portfolio price: "+DoubleToString(fixed_current,2)); bool countdown=false; if(counter>0) if(volume==0) if(fixed_current0) if(volume>0) { Report(Portfolio_Name+": DOWNWARD reversal..."); DoTrans(-volume*modifier,true,0); countdown=true; } if(countdown) if(counter!=INT_MAX) { string str1=BRC_LEFT+string(counter)+BRC_RIGHT; string str2=BRC_LEFT+string(counter-1)+BRC_RIGHT; StringReplace(text,str1,str2); ObjectSetString(chart,name,OBJPROP_TEXT,text); } if(counter<1) if(volume>=0) { Report(Portfolio_Name+": DOWNWARD full stop..."); DoClose(true,0); StringToLower(text); ObjectSetString(chart,name,OBJPROP_TEXT,text); } UpdateStatus(); DoSave(true); MakeScreenshot(3); continue; } //--- if(keyword_alert) { Alarm(Portfolio_Name+": ALERT line triggered: "+name); Alarm(Portfolio_Name+": level crossed: "+DoubleToString(level,2)); Alarm(Portfolio_Name+": portfolio price: "+DoubleToString(fixed_current,2)); StringToLower(text); ObjectSetString(chart,name,OBJPROP_TEXT,text); UpdateStatus(); DoSave(true); MakeScreenshot(3); continue; } //--- if(keyword_disable) { Report(Portfolio_Name+": DISABLE line triggered: "+name); string substr[]; int num=StringSplit(command,COLON,substr); if(num==1) for(int j=ObjectsTotal(chart,window,-1); j>=1; j--) { string objname=ObjectName(chart,j-1,window,-1); if(ObjectFind(chart,objname)!=window) continue; long objtype=ObjectGetInteger(chart,objname,OBJPROP_TYPE); if(objtype!=OBJ_TREND && objtype!=OBJ_HLINE) continue; string objtext=ObjectGetString(chart,objname,OBJPROP_TEXT); bool filter_buy=(StringFind(objtext,"BUY")!=-1); bool filter_sell=(StringFind(objtext,"SELL")!=-1); bool filter_trans=(StringFind(objtext,"TRANS")!=-1); bool filter_close=(StringFind(objtext,"CLOSE")!=-1); bool filter_upward=(StringFind(objtext,"UPWARD")!=-1); bool filter_downward=(StringFind(objtext,"DOWNWARD")!=-1); bool filter_fix=(StringFind(objtext,"FIX")!=-1); bool filter_alert=(StringFind(objtext,"ALERT")!=-1); bool filter_disable=(StringFind(objtext,"DISABLE")!=-1); bool filter_setup=(StringFind(objtext,"SETUP")!=-1); bool filter_any=filter_buy||filter_sell||filter_close||filter_trans|| filter_fix||filter_upward||filter_downward|| filter_alert||filter_disable||filter_setup; if(!filter_any) continue; StringToLower(objtext); ObjectSetString(chart,objname,OBJPROP_TEXT,objtext); Report(Portfolio_Name+": line was disabled: "+objname); } else for(int j=1; j0) if(MathAbs(factor)>Max_Volume) { Alarm(Portfolio_Name+": Maximum volume exceeded!"); return(false); } if(Check_Symbols) for(int i=0; i0) comment+="."+IntegerToString(number); string filter=""; if(number!=0) filter=Portfolio_Name+"."+IntegerToString(number); else if(Terminal_Mode) filter=Comment_Filter; else filter=Portfolio_Name; //--- #ifdef __MQL4__ for(int i=0; i=1; n--) { if(!OrderSelect(n-1,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=SYMBOLS[i]) continue; if(filter!="") if(StringFind(OrderComment(),filter,0)==-1) continue; if(OrderType()==OP_BUY) sum_lots+=OrderLots(); if(OrderType()==OP_SELL) sum_lots-=OrderLots(); } double new_lot=NormalizeDouble(factor*LOTS[i],Lots_Digits); double delta=NormalizeDouble(new_lot-sum_lots,Lots_Digits); if(delta==0) continue; for(int n=OrdersTotal(); n>=1; n--) { if(!OrderSelect(n-1,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=SYMBOLS[i]) continue; if(filter!="") if(StringFind(OrderComment(),filter,0)==-1) continue; if(new_lot!=0) if(OrderType()==OP_BUY && delta>0) continue; if(new_lot!=0) if(OrderType()==OP_SELL && delta<0) continue; if(new_lot!=0) if(OrderLots()>MathAbs(delta)) continue; for(int k=Retry_Times; k>0; k--) { bool check=false; Print(Portfolio_Name,": Sending CLOSE ",SYMBOLS[i]," ",DoubleToString(OrderLots(),Lots_Digits)); if(OrderType()==OP_BUY) check=OrderClose(OrderTicket(),OrderLots(),MarketInfo(SYMBOLS[i],MODE_BID),0); if(OrderType()==OP_SELL) check=OrderClose(OrderTicket(),OrderLots(),MarketInfo(SYMBOLS[i],MODE_ASK),0); if(check) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]; Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to close! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]); return(false); } if(delta>0) delta=NormalizeDouble(delta-OrderLots(),Lots_Digits); if(delta<0) delta=NormalizeDouble(delta+OrderLots(),Lots_Digits); } if(delta!=0) for(int k=Retry_Times; k>0; k--) { int ticket=-1; if(delta>0) Print(Portfolio_Name,": Sending BUY ",SYMBOLS[i]," ",DoubleToString(MathAbs(delta),Lots_Digits)); if(delta<0) Print(Portfolio_Name,": Sending SELL ",SYMBOLS[i]," ",DoubleToString(MathAbs(delta),Lots_Digits)); if(delta>0) ticket=OrderSend(SYMBOLS[i],OP_BUY,MathAbs(delta),MarketInfo(SYMBOLS[i],MODE_ASK),0,0,0,comment,magic); if(delta<0) ticket=OrderSend(SYMBOLS[i],OP_SELL,MathAbs(delta),MarketInfo(SYMBOLS[i],MODE_BID),0,0,0,comment,magic); if(ticket!=-1) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]; Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to open! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]); return(false); } } //--- for(int n=OrdersTotal(); n>=1; n--) { if(!OrderSelect(n-1,SELECT_BY_POS,MODE_TRADES)) continue; if(filter!="") if(StringFind(OrderComment(),filter,0)==-1) continue; bool presence=false; for(int i=0; i0; k--) { bool check=false; Print(Portfolio_Name,": Sending CLOSE ",OrderSymbol()," ",DoubleToString(OrderLots(),Lots_Digits)); if(OrderType()==OP_BUY) check=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),0); if(OrderType()==OP_SELL) check=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),0); if(check) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+" for "+OrderSymbol(); Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to close! - "+ErrorDescription(GetLastError())+" for "+OrderSymbol()); return(false); } } #else //--- for(int i=0; i=1; n--) { if(!PositionSelectByTicket(PositionGetTicket(n-1))) continue; if(PositionGetString(POSITION_SYMBOL)!=SYMBOLS[i]) continue; if(filter!="") if(StringFind(PositionGetString(POSITION_COMMENT),filter,0)==-1) continue; if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) sum_lots+=PositionGetDouble(POSITION_VOLUME); if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) sum_lots-=PositionGetDouble(POSITION_VOLUME); } double new_lot=NormalizeDouble(factor*LOTS[i],Lots_Digits); double delta=NormalizeDouble(new_lot-sum_lots,Lots_Digits); if(delta==0) continue; //--- for(int n=PositionsTotal(); n>=1; n--) { if(!PositionSelectByTicket(PositionGetTicket(n-1))) continue; if(PositionGetString(POSITION_SYMBOL)!=SYMBOLS[i]) continue; if(filter!="") if(StringFind(PositionGetString(POSITION_COMMENT),filter,0)==-1) continue; if(new_lot!=0) if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && delta>0) continue; if(new_lot!=0) if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL && delta<0) continue; if(new_lot!=0) if(PositionGetDouble(POSITION_VOLUME)>MathAbs(delta)) continue; for(int k=Retry_Times; k>0; k--) { bool check=false; Print(Portfolio_Name,": Sending CLOSE ",SYMBOLS[i]," ", DoubleToString(PositionGetDouble(POSITION_VOLUME),Lots_Digits)); if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.position=PositionGetInteger(POSITION_TICKET); request.symbol=PositionGetString(POSITION_SYMBOL); request.volume=PositionGetDouble(POSITION_VOLUME); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_SELL; request.price=SymbolInfoDouble(request.symbol,SYMBOL_BID); check=OrderSend(request,result); } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.position=PositionGetInteger(POSITION_TICKET); request.symbol=PositionGetString(POSITION_SYMBOL); request.volume=PositionGetDouble(POSITION_VOLUME); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_BUY; request.price=SymbolInfoDouble(request.symbol,SYMBOL_ASK); check=OrderSend(request,result); } if(check) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]; Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to close! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]); return(false); } if(delta>0) delta=NormalizeDouble(delta-PositionGetDouble(POSITION_VOLUME),Lots_Digits); if(delta<0) delta=NormalizeDouble(delta+PositionGetDouble(POSITION_VOLUME),Lots_Digits); } //--- if(delta!=0) for(int k=Retry_Times; k>0; k--) { bool check=false; if(delta>0) Print(Portfolio_Name,": Sending BUY ",SYMBOLS[i]," ",DoubleToString(MathAbs(delta),Lots_Digits)); if(delta<0) Print(Portfolio_Name,": Sending SELL ",SYMBOLS[i]," ",DoubleToString(MathAbs(delta),Lots_Digits)); if(delta>0) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.comment=comment; request.symbol=SYMBOLS[i]; request.volume=MathAbs(delta); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_BUY; request.price=SymbolInfoDouble(request.symbol,SYMBOL_ASK); check=OrderSend(request,result); } if(delta<0) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.comment=comment; request.symbol=SYMBOLS[i]; request.volume=MathAbs(delta); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_SELL; request.price=SymbolInfoDouble(request.symbol,SYMBOL_BID); check=OrderSend(request,result); } if(check) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]; Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to open! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]); return(false); } } //--- for(int n=PositionsTotal(); n>=1; n--) { if(!PositionSelectByTicket(PositionGetTicket(n-1))) continue; if(filter!="") if(StringFind(PositionGetString(POSITION_COMMENT),filter,0)==-1) continue; bool presence=false; for(int i=0; i0; k--) { bool check=false; Print(Portfolio_Name,": Sending CLOSE ",PositionGetString(POSITION_SYMBOL)," ", DoubleToString(PositionGetDouble(POSITION_VOLUME),Lots_Digits)); if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.position=PositionGetInteger(POSITION_TICKET); request.symbol=PositionGetString(POSITION_SYMBOL); request.volume=PositionGetDouble(POSITION_VOLUME); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_SELL; request.price=SymbolInfoDouble(request.symbol,SYMBOL_BID); check=OrderSend(request,result); } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.position=PositionGetInteger(POSITION_TICKET); request.symbol=PositionGetString(POSITION_SYMBOL); request.volume=PositionGetDouble(POSITION_VOLUME); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_BUY; request.price=SymbolInfoDouble(request.symbol,SYMBOL_ASK); check=OrderSend(request,result); } if(check) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+ " for "+PositionGetString(POSITION_SYMBOL); Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to close! - "+ErrorDescription(GetLastError())+" for "+ PositionGetString(POSITION_SYMBOL)); return(false); } } #endif //--- volume=factor; GlobalVariableSet("Volume-"+Portfolio_Name,volume); BackupGlobals(); if(Show_Trades) { PlaceVertical("Trade-transformation-"+string(now_time),now_time,LINES_COLOR,STYLE_DASHDOTDOT,true,false,false); } current=GlobalVariableGet("Portfolio-"+Portfolio_Name); string text="Portfolio "+Portfolio_Name+" transformed at "+DoubleToString(current,2)+" volume: "+DoubleToString(volume,2); if(!automatic && Manual_Confirm) MessageBox(text,"STATUS"); else Report(text); return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool DoOpen(double position,bool automatic,int number) { ReadScreenFormula(); if(position==0) { Alarm(Portfolio_Name+": Zero volume requested!"); return(false); } volume=GlobalVariableGet("Volume-"+Portfolio_Name); if(Max_Volume>0) if(MathAbs(position+volume)>Max_Volume) { Alarm(Portfolio_Name+": Maximum portfolio volume exceeded!"); return(false); } if(Check_Symbols) for(int i=0; i0) text="Opening LONG portfolio: "+Portfolio_Name; if(position<0) text="Opening SHORT portfolio: "+Portfolio_Name; if(MessageBox(text,"CONFIRM",MB_OKCANCEL|MB_ICONINFORMATION)==IDCANCEL) { Print("Cancelled!"); return(false); } else Print("Confirmed!"); } //--- int magic=Magic_Number; string comment=Portfolio_Name; if(number>0) comment+="."+IntegerToString(number); //--- #ifdef __MQL4__ for(int i=0; i0; k--) { int ticket=-1; double lot=NormalizeDouble(LOTS[i]*position,Lots_Digits); if(lot==0) break; if(lot>0) Print(Portfolio_Name,": Sending BUY ",SYMBOLS[i]," ",DoubleToString(MathAbs(lot),Lots_Digits)); if(lot<0) Print(Portfolio_Name,": Sending SELL ",SYMBOLS[i]," ",DoubleToString(MathAbs(lot),Lots_Digits)); if(lot>0) ticket=OrderSend(SYMBOLS[i],OP_BUY,MathAbs(lot),MarketInfo(SYMBOLS[i],MODE_ASK),0,0,0,comment,magic); if(lot<0) ticket=OrderSend(SYMBOLS[i],OP_SELL,MathAbs(lot),MarketInfo(SYMBOLS[i],MODE_BID),0,0,0,comment,magic); if(ticket!=-1) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]; Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to open! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]); return(false); } #else //--- for(int i=0; i0; k--) { bool check=false; double lot=NormalizeDouble(LOTS[i]*position,Lots_Digits); if(lot==0) break; if(lot>0) Print(Portfolio_Name,": Sending BUY ",SYMBOLS[i]," ",DoubleToString(MathAbs(lot),Lots_Digits)); if(lot<0) Print(Portfolio_Name,": Sending SELL ",SYMBOLS[i]," ",DoubleToString(MathAbs(lot),Lots_Digits)); if(lot>0) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.comment=comment; request.symbol=SYMBOLS[i]; request.volume=MathAbs(lot); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_BUY; request.price=SymbolInfoDouble(request.symbol,SYMBOL_ASK); check=OrderSend(request,result); } if(lot<0) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.comment=comment; request.symbol=SYMBOLS[i]; request.volume=MathAbs(lot); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_SELL; request.price=SymbolInfoDouble(request.symbol,SYMBOL_BID); check=OrderSend(request,result); } if(check) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]; Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to open! - "+ErrorDescription(GetLastError())+" for "+SYMBOLS[i]); return(false); } #endif //--- if(number==0) volume+=position; else volume=(MathAbs(volume)+MathAbs(position))*((position>0)?1:-1); increment++; threshold+=Adding_Threshold*MathAbs(volume); GlobalVariableSet("Volume-"+Portfolio_Name,volume); GlobalVariableSet("Increment-"+Portfolio_Name,increment); GlobalVariableSet("Threshold-"+Portfolio_Name,threshold); BackupGlobals(); if(Show_Trades) { PlaceVertical("Trade-opening-"+string(now_time),now_time,LINES_COLOR,STYLE_DASHDOTDOT,true,false,false); } string text; current=GlobalVariableGet("Portfolio-"+Portfolio_Name); if(position>0) text="LONG portfolio " +Portfolio_Name+" opened at "+DoubleToString(current,2)+" volume: "+DoubleToString(volume,2); if(position<0) text="SHORT portfolio "+Portfolio_Name+" opened at "+DoubleToString(current,2)+" volume: "+DoubleToString(volume,2); if(!automatic && Manual_Confirm) MessageBox(text,"STATUS"); else Report(text); return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool DoClose(bool automatic,int number) { ReadScreenFormula(); if(Check_Symbols) for(int i=0; i0) comment+="."+IntegerToString(number); int count=0; string filter=""; if(number!=0) filter=Portfolio_Name+"."+IntegerToString(number); else if(Terminal_Mode) filter=Comment_Filter; else filter=Portfolio_Name; //--- #ifdef __MQL4__ for(int n=OrdersTotal(); n>=1; n--) { if(!OrderSelect(n-1,SELECT_BY_POS,MODE_TRADES)) continue; if(filter!="") if(StringFind(OrderComment(),filter,0)==-1) continue; count++; for(int k=Retry_Times; k>0; k--) { bool check=false; Print(Portfolio_Name,": Sending CLOSE ",OrderSymbol()," ",DoubleToString(OrderLots(),Lots_Digits)); if(OrderType()==OP_BUY) check=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),0); if(OrderType()==OP_SELL) check=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),0); if(check) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+" for "+OrderSymbol(); Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to close! - "+ErrorDescription(GetLastError())+" for "+OrderSymbol()); return(false); } } #else //--- for(int n=PositionsTotal(); n>=1; n--) { if(!PositionSelectByTicket(PositionGetTicket(n-1))) continue; if(filter!="") if(StringFind(PositionGetString(POSITION_COMMENT),filter,0)==-1) continue; count++; for(int k=Retry_Times; k>0; k--) { bool check=false; Print(Portfolio_Name,": Sending CLOSE ",PositionGetString(POSITION_SYMBOL)," ", DoubleToString(PositionGetDouble(POSITION_VOLUME),Lots_Digits)); if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.position=PositionGetInteger(POSITION_TICKET); request.symbol=PositionGetString(POSITION_SYMBOL); request.volume=PositionGetDouble(POSITION_VOLUME); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_SELL; request.price=SymbolInfoDouble(request.symbol,SYMBOL_BID); check=OrderSend(request,result); } if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL) { MqlTradeRequest request= {}; MqlTradeResult result= {}; request.magic=magic; request.position=PositionGetInteger(POSITION_TICKET); request.symbol=PositionGetString(POSITION_SYMBOL); request.volume=PositionGetDouble(POSITION_VOLUME); request.type_filling=GetFilling(request.symbol); request.action=TRADE_ACTION_DEAL; request.type=ORDER_TYPE_BUY; request.price=SymbolInfoDouble(request.symbol,SYMBOL_ASK); check=OrderSend(request,result); } if(check) break; string message=Portfolio_Name+": Trading error! - "+ErrorDescription(GetLastError())+ " for "+PositionGetString(POSITION_SYMBOL); Print(message); if(automatic) Sleep(Retry_Delay); else if(MessageBox(message,"ERROR",MB_RETRYCANCEL|MB_ICONERROR)==IDCANCEL) return(false); if(IsStopped()) break; if(k>1) continue; Alarm(Portfolio_Name+": Failed to close! - "+ErrorDescription(GetLastError())+ " for "+PositionGetString(POSITION_SYMBOL)); return(false); } } #endif //--- if(number==0) { volume=0; increment=0; threshold=0; iteration=0; breakeven=false; reversals=0; ObjectDelete(0,"Zero-"+Portfolio_Name); ObjectDelete(0,"Stop-"+Portfolio_Name); ObjectDelete(0,"Take-"+Portfolio_Name); ObjectDelete(0,"Safe-"+Portfolio_Name); GlobalVariableDel("Volume-"+Portfolio_Name); GlobalVariableDel("Increment-"+Portfolio_Name); GlobalVariableDel("Threshold-"+Portfolio_Name); GlobalVariableDel("Iteration-"+Portfolio_Name); GlobalVariableDel("Breakeven-"+Portfolio_Name); GlobalVariableDel("Reversals-"+Portfolio_Name); ObjectDelete(0,"Volume-"+Portfolio_Name); ObjectDelete(0,"Increment-"+Portfolio_Name); ObjectDelete(0,"Threshold-"+Portfolio_Name); ObjectDelete(0,"Iteration-"+Portfolio_Name); ObjectDelete(0,"Breakeven-"+Portfolio_Name); ObjectDelete(0,"Reversals-"+Portfolio_Name); } else { threshold-=Adding_Threshold*MathAbs(volume); if(volume>0) volume-=GetVolume(number); if(volume<0) volume+=GetVolume(number); increment--; GlobalVariableSet("Volume-"+Portfolio_Name,volume); GlobalVariableSet("Increment-"+Portfolio_Name,increment); GlobalVariableSet("Threshold-"+Portfolio_Name,threshold); BackupGlobals(); } if(Show_Trades) { if(number==0) PlaceVertical("Trade-closing-"+string(now_time),now_time,LINES_COLOR,STYLE_DASHDOTDOT,true,false,false); else PlaceVertical("Trade-part-closing-"+string(now_time),now_time,LINES_COLOR,STYLE_DASHDOTDOT,true,false,false); } string text; current=GlobalVariableGet("Portfolio-"+Portfolio_Name); if(count>0) text="Portfolio "+Portfolio_Name+" closed out at "+DoubleToString(current,2); else text="No positions for portfolio: "+Portfolio_Name; if(!automatic && Manual_Confirm) MessageBox(text,"STATUS"); else Report(text); return(true); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #ifdef __MQL5__ ENUM_ORDER_TYPE_FILLING GetFilling(string symbol) { long mode=SymbolInfoInteger(symbol,SYMBOL_FILLING_MODE); if((mode&SYMBOL_FILLING_FOK)==SYMBOL_FILLING_FOK) return(ORDER_FILLING_FOK); if((mode&SYMBOL_FILLING_IOC)==SYMBOL_FILLING_IOC) return(ORDER_FILLING_IOC); return(ORDER_FILLING_RETURN); } #endif //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CheckSession(string symbol) { bool check=true; int index=0; datetime begin=0; datetime end=0; datetime time=now_time%(24*60*60); while(check) { check=SymbolInfoSessionTrade(symbol,(ENUM_DAY_OF_WEEK)str_time.day_of_week,index,begin,end); if(check) if(time>=begin && time<=end) return(true); index++; } return(false); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ReadScreenFormula() { dimension=0; string parts[]; string sub="Formula-label-"+Portfolio_Name+"-"; int objects=ObjectsTotal(chart,window,-1); for(int i=0; iscreen_timer || event>0) { if(screen_timer==0) screen_timer=Starting_From; if(event==0) while(screen_timer<=now_time) screen_timer+=Screenshot_Seconds; string time_text=TimeToString(now_time,TIME_DATE|TIME_SECONDS); StringReplace(time_text,".","-"); StringReplace(time_text,":","-"); string name=Portfolio_Name+"\\"+Portfolio_Name+"-"+time_text+SCREEN_EVENT[event]+".gif"; ChartScreenShot(chart,name,Screenshot_Width,Screenshot_Height); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void PlaceLabel(string name,int x,int y,int corner,string text,int colour,string font,int size) { ENUM_ANCHOR_POINT anchor=0; if(corner==CORNER_LEFT_LOWER) anchor=ANCHOR_LEFT_LOWER; else if(corner==CORNER_LEFT_UPPER) anchor=ANCHOR_LEFT_UPPER; else if(corner==CORNER_RIGHT_LOWER) anchor=ANCHOR_RIGHT_LOWER; else if(corner==CORNER_RIGHT_UPPER) anchor=ANCHOR_RIGHT_UPPER; ObjectCreate(chart,name,OBJ_LABEL,window,0,0); ObjectSetInteger(chart,name,OBJPROP_CORNER,corner); ObjectSetInteger(chart,name,OBJPROP_ANCHOR,anchor); ObjectSetInteger(chart,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(chart,name,OBJPROP_YDISTANCE,y); ObjectSetString(chart,name,OBJPROP_TEXT,text); ObjectSetString(chart,name,OBJPROP_FONT,font); ObjectSetInteger(chart,name,OBJPROP_FONTSIZE,size); ObjectSetInteger(chart,name,OBJPROP_COLOR,colour); ObjectSetInteger(chart,name,OBJPROP_SELECTABLE,false); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void PlaceVertical(string name,datetime time,int colour,int style,bool back,bool selectable,bool selected) { ObjectCreate(chart,name,OBJ_VLINE,window,time,0); ObjectSetInteger(chart,name,OBJPROP_TIME,time); ObjectSetInteger(chart,name,OBJPROP_COLOR,colour); ObjectSetInteger(chart,name,OBJPROP_STYLE,style); ObjectSetInteger(chart,name,OBJPROP_BACK,back); ObjectSetInteger(chart,name,OBJPROP_SELECTABLE,selectable); ObjectSetInteger(chart,name,OBJPROP_SELECTED,selected); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void PlaceHorizontal(string name,double price,int colour,int style,bool back,bool selectable,bool selected) { ObjectCreate(chart,name,OBJ_HLINE,window,0,price); ObjectSetDouble(chart,name,OBJPROP_PRICE,price); ObjectSetInteger(chart,name,OBJPROP_COLOR,colour); ObjectSetInteger(chart,name,OBJPROP_STYLE,style); ObjectSetInteger(chart,name,OBJPROP_BACK,back); ObjectSetInteger(chart,name,OBJPROP_SELECTABLE,selectable); ObjectSetInteger(chart,name,OBJPROP_SELECTED,selected); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ string ErrorDescription(int code) { #ifdef __MQL4__ if(code==ERR_NO_ERROR) return("NO_ERROR"); if(code==ERR_NO_RESULT) return("NO_RESULT"); if(code==ERR_COMMON_ERROR) return("COMMON_ERROR"); if(code==ERR_INVALID_TRADE_PARAMETERS) return("INVALID_TRADE_PARAMETERS"); if(code==ERR_SERVER_BUSY) return("SERVER_BUSY"); if(code==ERR_OLD_VERSION) return("OLD_VERSION"); if(code==ERR_NO_CONNECTION) return("NO_CONNECTION"); if(code==ERR_NOT_ENOUGH_RIGHTS) return("NOT_ENOUGH_RIGHTS"); if(code==ERR_TOO_FREQUENT_REQUESTS) return("TOO_FREQUENT_REQUESTS"); if(code==ERR_MALFUNCTIONAL_TRADE) return("MALFUNCTIONAL_TRADE"); if(code==ERR_ACCOUNT_DISABLED) return("ACCOUNT_DISABLED"); if(code==ERR_INVALID_ACCOUNT) return("INVALID_ACCOUNT"); if(code==ERR_TRADE_TIMEOUT) return("TRADE_TIMEOUT"); if(code==ERR_INVALID_PRICE) return("INVALID_PRICE"); if(code==ERR_INVALID_STOPS) return("INVALID_STOPS"); if(code==ERR_INVALID_TRADE_VOLUME) return("INVALID_TRADE_VOLUME"); if(code==ERR_MARKET_CLOSED) return("MARKET_CLOSED"); if(code==ERR_TRADE_DISABLED) return("TRADE_DISABLED"); if(code==ERR_NOT_ENOUGH_MONEY) return("NOT_ENOUGH_MONEY"); if(code==ERR_PRICE_CHANGED) return("PRICE_CHANGED"); if(code==ERR_OFF_QUOTES) return("OFF_QUOTES"); if(code==ERR_BROKER_BUSY) return("BROKER_BUSY"); if(code==ERR_REQUOTE) return("REQUOTE"); if(code==ERR_ORDER_LOCKED) return("ORDER_LOCKED"); if(code==ERR_LONG_POSITIONS_ONLY_ALLOWED) return("LONG_POSITIONS_ONLY_ALLOWED"); if(code==ERR_TOO_MANY_REQUESTS) return("TOO_MANY_REQUESTS"); if(code==ERR_TRADE_MODIFY_DENIED) return("TRADE_MODIFY_DENIED"); if(code==ERR_TRADE_CONTEXT_BUSY) return("TRADE_CONTEXT_BUSY"); if(code==ERR_TRADE_EXPIRATION_DENIED) return("TRADE_EXPIRATION_DENIED"); if(code==ERR_TRADE_TOO_MANY_ORDERS) return("TRADE_TOO_MANY_ORDERS"); if(code==ERR_TRADE_HEDGE_PROHIBITED) return("TRADE_HEDGE_PROHIBITED"); if(code==ERR_TRADE_PROHIBITED_BY_FIFO) return("TRADE_PROHIBITED_BY_FIFO"); if(code==ERR_NO_MQLERROR) return("NO_MQLERROR"); if(code==ERR_WRONG_FUNCTION_POINTER) return("WRONG_FUNCTION_POINTER"); if(code==ERR_ARRAY_INDEX_OUT_OF_RANGE) return("ARRAY_INDEX_OUT_OF_RANGE"); if(code==ERR_NO_MEMORY_FOR_CALL_STACK) return("NO_MEMORY_FOR_CALL_STACK"); if(code==ERR_RECURSIVE_STACK_OVERFLOW) return("RECURSIVE_STACK_OVERFLOW"); if(code==ERR_NOT_ENOUGH_STACK_FOR_PARAM) return("NOT_ENOUGH_STACK_FOR_PARAM"); if(code==ERR_NO_MEMORY_FOR_PARAM_STRING) return("NO_MEMORY_FOR_PARAM_STRING"); if(code==ERR_NO_MEMORY_FOR_TEMP_STRING) return("NO_MEMORY_FOR_TEMP_STRING"); if(code==ERR_NOT_INITIALIZED_STRING) return("NOT_INITIALIZED_STRING"); if(code==ERR_NOT_INITIALIZED_ARRAYSTRING) return("NOT_INITIALIZED_ARRAYSTRING"); if(code==ERR_NO_MEMORY_FOR_ARRAYSTRING) return("NO_MEMORY_FOR_ARRAYSTRING"); if(code==ERR_TOO_LONG_STRING) return("TOO_LONG_STRING"); if(code==ERR_REMAINDER_FROM_ZERO_DIVIDE) return("REMAINDER_FROM_ZERO_DIVIDE"); if(code==ERR_ZERO_DIVIDE) return("ZERO_DIVIDE"); if(code==ERR_UNKNOWN_COMMAND) return("UNKNOWN_COMMAND"); if(code==ERR_WRONG_JUMP) return("WRONG_JUMP"); if(code==ERR_NOT_INITIALIZED_ARRAY) return("NOT_INITIALIZED_ARRAY"); if(code==ERR_DLL_CALLS_NOT_ALLOWED) return("DLL_CALLS_NOT_ALLOWED"); if(code==ERR_CANNOT_LOAD_LIBRARY) return("CANNOT_LOAD_LIBRARY"); if(code==ERR_CANNOT_CALL_FUNCTION) return("CANNOT_CALL_FUNCTION"); if(code==ERR_EXTERNAL_CALLS_NOT_ALLOWED) return("EXTERNAL_CALLS_NOT_ALLOWED"); if(code==ERR_NO_MEMORY_FOR_RETURNED_STR) return("NO_MEMORY_FOR_RETURNED_STR"); if(code==ERR_SYSTEM_BUSY) return("SYSTEM_BUSY"); if(code==ERR_DLLFUNC_CRITICALERROR) return("DLLFUNC_CRITICALERROR"); if(code==ERR_INTERNAL_ERROR) return("INTERNAL_ERROR"); if(code==ERR_OUT_OF_MEMORY) return("OUT_OF_MEMORY"); if(code==ERR_INVALID_POINTER) return("INVALID_POINTER"); if(code==ERR_FORMAT_TOO_MANY_FORMATTERS) return("FORMAT_TOO_MANY_FORMATTERS"); if(code==ERR_FORMAT_TOO_MANY_PARAMETERS) return("FORMAT_TOO_MANY_PARAMETERS"); if(code==ERR_ARRAY_INVALID) return("ARRAY_INVALID"); if(code==ERR_CHART_NOREPLY) return("CHART_NOREPLY"); if(code==ERR_INVALID_FUNCTION_PARAMSCNT) return("INVALID_FUNCTION_PARAMSCNT"); if(code==ERR_INVALID_FUNCTION_PARAMVALUE) return("INVALID_FUNCTION_PARAMVALUE"); if(code==ERR_STRING_FUNCTION_INTERNAL) return("STRING_FUNCTION_INTERNAL"); if(code==ERR_SOME_ARRAY_ERROR) return("SOME_ARRAY_ERROR"); if(code==ERR_INCORRECT_SERIESARRAY_USING) return("INCORRECT_SERIESARRAY_USING"); if(code==ERR_CUSTOM_INDICATOR_ERROR) return("CUSTOM_INDICATOR_ERROR"); if(code==ERR_INCOMPATIBLE_ARRAYS) return("INCOMPATIBLE_ARRAYS"); if(code==ERR_GLOBAL_VARIABLES_PROCESSING) return("GLOBAL_VARIABLES_PROCESSING"); if(code==ERR_GLOBAL_VARIABLE_NOT_FOUND) return("GLOBAL_VARIABLE_NOT_FOUND"); if(code==ERR_FUNC_NOT_ALLOWED_IN_TESTING) return("FUNC_NOT_ALLOWED_IN_TESTING"); if(code==ERR_FUNCTION_NOT_CONFIRMED) return("FUNCTION_NOT_CONFIRMED"); if(code==ERR_SEND_MAIL_ERROR) return("SEND_MAIL_ERROR"); if(code==ERR_STRING_PARAMETER_EXPECTED) return("STRING_PARAMETER_EXPECTED"); if(code==ERR_INTEGER_PARAMETER_EXPECTED) return("INTEGER_PARAMETER_EXPECTED"); if(code==ERR_DOUBLE_PARAMETER_EXPECTED) return("DOUBLE_PARAMETER_EXPECTED"); if(code==ERR_ARRAY_AS_PARAMETER_EXPECTED) return("ARRAY_AS_PARAMETER_EXPECTED"); if(code==ERR_HISTORY_WILL_UPDATED) return("HISTORY_WILL_UPDATED"); if(code==ERR_TRADE_ERROR) return("TRADE_ERROR"); if(code==ERR_RESOURCE_NOT_FOUND) return("RESOURCE_NOT_FOUND"); if(code==ERR_RESOURCE_NOT_SUPPORTED) return("RESOURCE_NOT_SUPPORTED"); if(code==ERR_RESOURCE_DUPLICATED) return("RESOURCE_DUPLICATED"); if(code==ERR_INDICATOR_CANNOT_INIT) return("INDICATOR_CANNOT_INIT"); if(code==ERR_END_OF_FILE) return("END_OF_FILE"); if(code==ERR_SOME_FILE_ERROR) return("SOME_FILE_ERROR"); if(code==ERR_WRONG_FILE_NAME) return("WRONG_FILE_NAME"); if(code==ERR_TOO_MANY_OPENED_FILES) return("TOO_MANY_OPENED_FILES"); if(code==ERR_CANNOT_OPEN_FILE) return("CANNOT_OPEN_FILE"); if(code==ERR_INCOMPATIBLE_FILEACCESS) return("INCOMPATIBLE_FILEACCESS"); if(code==ERR_NO_ORDER_SELECTED) return("NO_ORDER_SELECTED"); if(code==ERR_UNKNOWN_SYMBOL) return("UNKNOWN_SYMBOL"); if(code==ERR_INVALID_PRICE_PARAM) return("INVALID_PRICE_PARAM"); if(code==ERR_INVALID_TICKET) return("INVALID_TICKET"); if(code==ERR_TRADE_NOT_ALLOWED) return("TRADE_NOT_ALLOWED"); if(code==ERR_LONGS_NOT_ALLOWED) return("LONGS_NOT_ALLOWED"); if(code==ERR_SHORTS_NOT_ALLOWED) return("SHORTS_NOT_ALLOWED"); if(code==ERR_TRADE_EXPERT_DISABLED_BY_SERVER) return("TRADE_EXPERT_DISABLED_BY_SERVER"); if(code==ERR_OBJECT_ALREADY_EXISTS) return("OBJECT_ALREADY_EXISTS"); if(code==ERR_UNKNOWN_OBJECT_PROPERTY) return("UNKNOWN_OBJECT_PROPERTY"); if(code==ERR_OBJECT_DOES_NOT_EXIST) return("OBJECT_DOES_NOT_EXIST"); if(code==ERR_UNKNOWN_OBJECT_TYPE) return("UNKNOWN_OBJECT_TYPE"); if(code==ERR_NO_OBJECT_NAME) return("NO_OBJECT_NAME"); if(code==ERR_OBJECT_COORDINATES_ERROR) return("OBJECT_COORDINATES_ERROR"); if(code==ERR_NO_SPECIFIED_SUBWINDOW) return("NO_SPECIFIED_SUBWINDOW"); if(code==ERR_SOME_OBJECT_ERROR) return("SOME_OBJECT_ERROR"); if(code==ERR_CHART_PROP_INVALID) return("CHART_PROP_INVALID"); if(code==ERR_CHART_NOT_FOUND) return("CHART_NOT_FOUND"); if(code==ERR_CHARTWINDOW_NOT_FOUND) return("CHARTWINDOW_NOT_FOUND"); if(code==ERR_CHARTINDICATOR_NOT_FOUND) return("CHARTINDICATOR_NOT_FOUND"); if(code==ERR_SYMBOL_SELECT) return("SYMBOL_SELECT"); if(code==ERR_NOTIFICATION_ERROR) return("NOTIFICATION_ERROR"); if(code==ERR_NOTIFICATION_PARAMETER) return("NOTIFICATION_PARAMETER"); if(code==ERR_NOTIFICATION_SETTINGS) return("NOTIFICATION_SETTINGS"); if(code==ERR_NOTIFICATION_TOO_FREQUENT) return("NOTIFICATION_TOO_FREQUENT"); if(code==ERR_FILE_TOO_MANY_OPENED) return("FILE_TOO_MANY_OPENED"); if(code==ERR_FILE_WRONG_FILENAME) return("FILE_WRONG_FILENAME"); if(code==ERR_FILE_TOO_LONG_FILENAME) return("FILE_TOO_LONG_FILENAME"); if(code==ERR_FILE_CANNOT_OPEN) return("FILE_CANNOT_OPEN"); if(code==ERR_FILE_BUFFER_ALLOCATION_ERROR) return("FILE_BUFFER_ALLOCATION_ERROR"); if(code==ERR_FILE_CANNOT_DELETE) return("FILE_CANNOT_DELETE"); if(code==ERR_FILE_INVALID_HANDLE) return("FILE_INVALID_HANDLE"); if(code==ERR_FILE_WRONG_HANDLE) return("FILE_WRONG_HANDLE"); if(code==ERR_FILE_NOT_TOWRITE) return("FILE_NOT_TOWRITE"); if(code==ERR_FILE_NOT_TOREAD) return("FILE_NOT_TOREAD"); if(code==ERR_FILE_NOT_BIN) return("FILE_NOT_BIN"); if(code==ERR_FILE_NOT_TXT) return("FILE_NOT_TXT"); if(code==ERR_FILE_NOT_TXTORCSV) return("FILE_NOT_TXTORCSV"); if(code==ERR_FILE_NOT_CSV) return("FILE_NOT_CSV"); if(code==ERR_FILE_READ_ERROR) return("FILE_READ_ERROR"); if(code==ERR_FILE_WRITE_ERROR) return("FILE_WRITE_ERROR"); if(code==ERR_FILE_BIN_STRINGSIZE) return("FILE_BIN_STRINGSIZE"); if(code==ERR_FILE_INCOMPATIBLE) return("FILE_INCOMPATIBLE"); if(code==ERR_FILE_IS_DIRECTORY) return("FILE_IS_DIRECTORY"); if(code==ERR_FILE_NOT_EXIST) return("FILE_NOT_EXIST"); if(code==ERR_FILE_CANNOT_REWRITE) return("FILE_CANNOT_REWRITE"); if(code==ERR_FILE_WRONG_DIRECTORYNAME) return("FILE_WRONG_DIRECTORYNAME"); if(code==ERR_FILE_DIRECTORY_NOT_EXIST) return("FILE_DIRECTORY_NOT_EXIST"); if(code==ERR_FILE_NOT_DIRECTORY) return("FILE_NOT_DIRECTORY"); if(code==ERR_FILE_CANNOT_DELETE_DIRECTORY) return("FILE_CANNOT_DELETE_DIRECTORY"); if(code==ERR_FILE_CANNOT_CLEAN_DIRECTORY) return("FILE_CANNOT_CLEAN_DIRECTORY"); if(code==ERR_FILE_ARRAYRESIZE_ERROR) return("FILE_ARRAYRESIZE_ERROR"); if(code==ERR_FILE_STRINGRESIZE_ERROR) return("FILE_STRINGRESIZE_ERROR"); if(code==ERR_FILE_STRUCT_WITH_OBJECTS) return("FILE_STRUCT_WITH_OBJECTS"); if(code==ERR_WEBREQUEST_INVALID_ADDRESS) return("WEBREQUEST_INVALID_ADDRESS"); if(code==ERR_WEBREQUEST_CONNECT_FAILED) return("WEBREQUEST_CONNECT_FAILED"); if(code==ERR_WEBREQUEST_TIMEOUT) return("WEBREQUEST_TIMEOUT"); if(code==ERR_WEBREQUEST_REQUEST_FAILED) return("WEBREQUEST_REQUEST_FAILED"); #else if(code==TRADE_RETCODE_REQUOTE) return("TRADE_RETCODE_REQUOTE"); if(code==TRADE_RETCODE_REJECT) return("TRADE_RETCODE_REJECT"); if(code==TRADE_RETCODE_CANCEL) return("TRADE_RETCODE_CANCEL"); if(code==TRADE_RETCODE_PLACED) return("TRADE_RETCODE_PLACED"); if(code==TRADE_RETCODE_DONE) return("TRADE_RETCODE_DONE"); if(code==TRADE_RETCODE_DONE_PARTIAL) return("TRADE_RETCODE_DONE_PARTIAL"); if(code==TRADE_RETCODE_ERROR) return("TRADE_RETCODE_ERROR"); if(code==TRADE_RETCODE_TIMEOUT) return("TRADE_RETCODE_TIMEOUT"); if(code==TRADE_RETCODE_INVALID) return("TRADE_RETCODE_INVALID"); if(code==TRADE_RETCODE_INVALID_VOLUME) return("TRADE_RETCODE_INVALID_VOLUME"); if(code==TRADE_RETCODE_INVALID_PRICE) return("TRADE_RETCODE_INVALID_PRICE"); if(code==TRADE_RETCODE_INVALID_STOPS) return("TRADE_RETCODE_INVALID_STOPS"); if(code==TRADE_RETCODE_TRADE_DISABLED) return("TRADE_RETCODE_TRADE_DISABLED"); if(code==TRADE_RETCODE_MARKET_CLOSED) return("TRADE_RETCODE_MARKET_CLOSED"); if(code==TRADE_RETCODE_NO_MONEY) return("TRADE_RETCODE_NO_MONEY"); if(code==TRADE_RETCODE_PRICE_CHANGED) return("TRADE_RETCODE_PRICE_CHANGED"); if(code==TRADE_RETCODE_PRICE_OFF) return("TRADE_RETCODE_PRICE_OFF"); if(code==TRADE_RETCODE_INVALID_EXPIRATION) return("TRADE_RETCODE_INVALID_EXPIRATION"); if(code==TRADE_RETCODE_ORDER_CHANGED) return("TRADE_RETCODE_ORDER_CHANGED"); if(code==TRADE_RETCODE_TOO_MANY_REQUESTS) return("TRADE_RETCODE_TOO_MANY_REQUESTS"); if(code==TRADE_RETCODE_NO_CHANGES) return("TRADE_RETCODE_NO_CHANGES"); if(code==TRADE_RETCODE_SERVER_DISABLES_AT) return("TRADE_RETCODE_SERVER_DISABLES_AT"); if(code==TRADE_RETCODE_CLIENT_DISABLES_AT) return("TRADE_RETCODE_CLIENT_DISABLES_AT"); if(code==TRADE_RETCODE_LOCKED) return("TRADE_RETCODE_LOCKED"); if(code==TRADE_RETCODE_FROZEN) return("TRADE_RETCODE_FROZEN"); if(code==TRADE_RETCODE_INVALID_FILL) return("TRADE_RETCODE_INVALID_FILL"); if(code==TRADE_RETCODE_CONNECTION) return("TRADE_RETCODE_CONNECTION"); if(code==TRADE_RETCODE_ONLY_REAL) return("TRADE_RETCODE_ONLY_REAL"); if(code==TRADE_RETCODE_LIMIT_ORDERS) return("TRADE_RETCODE_LIMIT_ORDERS"); if(code==TRADE_RETCODE_LIMIT_VOLUME) return("TRADE_RETCODE_LIMIT_VOLUME"); if(code==TRADE_RETCODE_INVALID_ORDER) return("TRADE_RETCODE_INVALID_ORDER"); if(code==TRADE_RETCODE_POSITION_CLOSED) return("TRADE_RETCODE_POSITION_CLOSED"); if(code==TRADE_RETCODE_INVALID_CLOSE_VOLUME) return("TRADE_RETCODE_INVALID_CLOSE_VOLUME"); if(code==TRADE_RETCODE_CLOSE_ORDER_EXIST) return("TRADE_RETCODE_CLOSE_ORDER_EXIST"); if(code==TRADE_RETCODE_LIMIT_POSITIONS) return("TRADE_RETCODE_LIMIT_POSITIONS"); if(code==TRADE_RETCODE_REJECT_CANCEL) return("TRADE_RETCODE_REJECT_CANCEL"); if(code==TRADE_RETCODE_LONG_ONLY) return("TRADE_RETCODE_LONG_ONLY"); if(code==TRADE_RETCODE_SHORT_ONLY) return("TRADE_RETCODE_SHORT_ONLY"); if(code==TRADE_RETCODE_CLOSE_ONLY) return("TRADE_RETCODE_CLOSE_ONLY"); if(code==TRADE_RETCODE_FIFO_CLOSE) return("TRADE_RETCODE_FIFO_CLOSE"); if(code==TRADE_RETCODE_HEDGE_PROHIBITED) return("TRADE_RETCODE_HEDGE_PROHIBITED"); if(code==ERR_ACCOUNT_WRONG_PROPERTY) return("ERR_ACCOUNT_WRONG_PROPERTY"); if(code==ERR_TRADE_WRONG_PROPERTY) return("ERR_TRADE_WRONG_PROPERTY"); if(code==ERR_TRADE_DISABLED) return("ERR_TRADE_DISABLED"); if(code==ERR_TRADE_POSITION_NOT_FOUND) return("ERR_TRADE_POSITION_NOT_FOUND"); if(code==ERR_TRADE_ORDER_NOT_FOUND) return("ERR_TRADE_ORDER_NOT_FOUND"); if(code==ERR_TRADE_DEAL_NOT_FOUND) return("ERR_TRADE_DEAL_NOT_FOUND"); if(code==ERR_TRADE_SEND_FAILED) return("ERR_TRADE_SEND_FAILED"); if(code==ERR_TRADE_CALC_FAILED) return("ERR_TRADE_CALC_FAILED"); #endif return("NOT_DEFINED"); } //+------------------------------------------------------------------+