Partial position closing source code download and deployment instructions | Trading script download - MT4/MT5 resources | Foreign exchange automatic trading robot tool
Introduction to partial liquidation source code: "Expert Advisor (EA)" will monitor all or specified instruments' open positions. "Expert Advisor (EA)" will monitor the open positions of all or specified instruments and perform partial liquidation when the preset profit is reached. You can specify a specific "Magic Number" or set it to "-1" to cover all positions. EA supports setting 4 closing levels, for example: when the profit reaches 50 points, close 50% of the position; when the profit reaches 100 points, close an additional 30% of the position; when the profit reaches 150 points, close the position 10%; when the profit reaches 250 points, close the remaining 10%. After the first partial closing of a position, the EA will adjust the position to a "breakeven" status and attach a "NoLoss" profit protection point. For example, if "NoLoss" is set to 10 points, when the profit reaches 100 points, the EA closes 50% of the position and sets the stop loss (SL) to 10 points above the opening price (applicable to buy orders). cpp //+------------------------------------------------------------------+ //| Trading Panel System.mq4 | //| Copyright © 2023-2025, AI Programming zblog | //| http://www.eawalk.com | //+----------------------------------------------------------------+ #property copyright"Copyright © 2024, AI Programming zblog" #propertylink "www.eawalk.com" #property version "1.0" #property strict #propertydescription "1. The expert advisor tracks open positions for all or specified instruments." #propertydescription "2. When the specified profit is reached, close part of the position." #propertydescription "3. On the first partial close, convert the position to breakeven and attach NoLoss profit points." //+--------------------------------------------------------------------------------+ //| | //+--------------------------------------------------------------------------------+ enum tt { tr2=0, // Current currency pair tr1=1, // All currency pairs}; input tt Trading range = 1; // Trading range selection: 0 is the current currency pair, 1 is all currency pairs extern int magic number = -1; // Magic number: -1 means monitoring all orders extern int closing level 1 = 50; // closing level 1 (unit: points) extern int closing level 2 = 100; // closing level 2 (unit: points) extern int Closing level 3 = 150; // Closing level 3 (unit: points) extern int Closing level 4 = 250; // Closing level 4 (unit: points) extern int Closing percentage 1 = 50; // Closing percentage 1 (based on initial position) extern int Closing percentage 2 = 30; // Closing percentage 2 (based on initial position) extern int Closing percentage 3 = 10; // Closing percentage 3 (based on initial position) extern int Closing percentage 4 = 10; // Closing percentage 4 (based on initial position) extern int No-loss profit points = 0; // No-loss profit points: additional profit points when switching to breakeven after the first closing extern int Slippage tolerance = 3; // Slippage tolerance (unit: points) sinput double interface scaling ratio = 1.2; // interface scaling ratio input bool Screenshot save = true; // Whether to save the screenshot input color Color 1 = clrWhite; // Color 1 input color Color 2 = clrAqua; // Color 2 input color Color 3 = clrMagenta; // Color 3 input color Color 4 = clrDarkOrange; // Color 4 //+--------------------------------------------------------------------------------+ //| | //+--------------------------------------------------------------------------------+ string AC,GVp; int Lossless profit,Magic,LevelClose[4]; intPercentClose[4]; boolShowOrder=true,SymbolAll=false,LANGUAGE; color ColorN[4]; //+--------------------------------------------------------------------------------+ //| | //+--------------------------------------------------------------------------------+ int OnInit() { Comment(""); AC=AccountCurrency(); GVp="cm partial closing position "; if(IsTesting())GVp=GVp+" Testing"; if(IsDemo()) GVp=GVp+" Demo"; if(IsTesting()) GlobalVariablesDeleteAll(GVp); ColorN[0]=Color1; ColorN[1]=Color2; ColorN[2]=Color3; ColorN[3]=Color4; LevelClose[0]=Close Level 1; LevelClose[1]=Close level 2; LevelClose[2]=Close level 3; LevelClose[3]=Close level 4; PercentClose[0]=Close percentage 1; PercentClose[1]=Close percentage 2; PercentClose[2]=Close percentage 3; PercentClose[3]=Close percentage 4; LANGUAGE=TerminalInfoString(TERMINAL_LANGUAGE)=="Russian"; intY=20; SymbolAll=Trading range==1; Magic=Magic number; No-loss profit=No-loss profit point; ButtonCreate(0,"cm PCP Symbol" ,0,205,Y,200,20,CORNER_RIGHT_UPPER,SymbolAll?"Symbol(),"Arial",12,clrBlack,clrLightGray,clrNONE,SymbolAll,false,false,true,0,LANGUAGE?"The choice to work for all currencies or only for theone on which the Expert Advisor is installed");Y+=19; EditCreate(0,"cm PCP Magic_" ,0,205,Y,101,20,"Magic Number" ,"Arial",12,ALIGN_CENTER,true,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Magic (When setting the value -1, the Expert Advisor sees all the magics)");Y+=19; EditCreate(0,"cm PCP CloseLevel_" ,0,205,Y,101,20,"Closing Level" ,"Arial",12,ALIGN_CENTER,true,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing Level":"Closing Levels");Y+=19; EditCreate(0,"cm PCP Percents_" ,0,205,Y,101,20,"Closing percentage" ,"Arial",12,ALIGN_CENTER,true,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing percentage":"Closing percentage");Y+=19; EditCreate(0,"cm PCP NoLoss_" ,0,205,Y,101,20,"No-loss profit point" ,"Arial",12,ALIGN_CENTER,true,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Minimum profit when transferring to breakeven":"minimum profit when transferring to breakeven");Y=39; EditCreate(0,"cm PCP Magic" ,0,105,Y,100,20,IntegerToString(Magic),"Arial",12,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Magic Number (Monitor all orders when set to -1)":"Magic (When setting the value -1, the Expert Advisors all the magics)");Y+=19; EditCreate(0,"cm PCPCloseLevel1",0,105,Y,26,20,IntegerToString(Close Level 1),"Arial",11,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing Levels (Separate multiple levels) with /)"); EditCreate(0,"cm PCP CloseLevel2",0,80,Y,26,20,IntegerToString(Close Level 2),"Arial",11,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing Levels (Separatemultiple levels with /)":"Closing Levels (Separatemultiple levels with /)"); EditCreate(0,"cm PCP CloseLevel3",0,55,Y,26,20,IntegerToString(Closing Level 3),"Arial",11,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing Levels (Separate multiple levels with /)":"Closing Levels (Separatemultiple levels with /)"); EditCreate(0,"cm PCP CloseLevel4",0,30,Y,25,20,IntegerToString(Closing Level 4),"Arial",11,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing Levels (Separate multiple levels with /)":"Closing Levels (Separatemultiple levels with /)");Y+=19; EditCreate(0,"cm PCP Percents1" ,0,105,Y,26,20,IntegerToString(Closing percentage 1),"Arial",11,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing percentage(Separate multiple levels with /)":"Closing percentage(Separate multiple levels with /)"); EditCreate(0,"cm PCP Percents2" ,0,80,Y,26,20,IntegerToString(Closing Percent 2),"Arial",11,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing Percentage (multiple levels separated by /)":"Closing percentage(Separate multiple levels with /)"); EditCreate(0,"cm PCP Percents3" ,0,55,Y,26,20,IntegerToString(Closing percentage 3),"Arial",11,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing percentage(Separate multiple levels with /)":"Closing percentage(Separate multiple levels with /)"); EditCreate(0,"cmPCP Percents4" ,0, 30,Y,25,20,IntegerToString(Closing Percent 4),"Arial",11,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"Closing Percentage (multiple levels separated by /)":"Closing percentage(Separate multiple levels with /)");Y+=19; EditCreate(0,"cm PCP NoLoss" ,0,105,Y,100,20,IntegerToString(No loss profit) ,"Arial",12,ALIGN_CENTER,false,CORNER_RIGHT_UPPER,clrBlack,clrWhite,clrGray,false,false,true,0,LANGUAGE?"minimum profit when transferring to breakeven");Y+=19; ButtonCreate(0,"cm PCPShowOrder",0,205,Y,200,20,CORNER_RIGHT_UPPER,"Show order","Arial",12,clrBlack,clrLightGray,clrNONE,SymbolAll,false,false,true,0,LANGUAGE?"Show/hide the order table":"Show/hide the ordertable"); OnTick(); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(constint r) { if(IsTesting()) GlobalVariablesDeleteAll(GVp); ObjectsDeleteAll(0,"cm PCP"); return; } //+------------------------------------------------------------------+ //| txt=NULL; int N=0; void OnTick() { if (lossless profit!=(int)StringToInteger(ObjectGetString(0,"cmPCP NoLoss",OBJPROP_TEXT))) {lossless profit=(int)StringToInteger(ObjectGetString(0,"cmPCP NoLoss",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"modified":"Changed"," lossless profit = ",lossless profit,"n"); } if(Magic!=(int)StringToInteger(ObjectGetString(0,"cm PCPMagic",OBJPROP_TEXT))) { Magic=(int)StringToInteger(ObjectGetString(0,"cm PCPMagic",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"modified":"Changed"," magic number = ",Magic,"n"); } if(LevelClose[0]!=(int)StringToInteger(ObjectGetString(0,"cm PCPCloseLevel1",OBJPROP_TEXT))) { LevelClose[0]=(int)StringToInteger(ObjectGetString(0,"cm PCPCloseLevel1",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"Modified":"Changed"," Closing level 1 = ",LevelClose[0],"Point n"); } if(LevelClose[1]!=(int)StringToInteger(ObjectGetString(0,"cm PCPCloseLevel2",OBJPROP_TEXT))) { LevelClose[1]=(int)StringToInteger(ObjectGetString(0,"cm PCPCloseLevel2",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"Modified":"Changed"," Closing level 2 = ",LevelClose[1],"Point n"); } if(LevelClose[2]!=(int)StringToInteger(ObjectGetString(0,"cm PCPCloseLevel3",OBJPROP_TEXT))) { LevelClose[2]=(int)StringToInteger(ObjectGetString(0,"cm PCPCloseLevel3",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"Modified":"Changed"," Closing level 3 = ",LevelClose[2],"Point n"); } if(LevelClose[3]!=(int)StringToInteger(ObjectGetString(0,"cm PCPCloseLevel4",OBJPROP_TEXT))) { LevelClose[3]=(int)StringToInteger(ObjectGetString(0,"cm PCPCloseLevel4",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"Modified":"Changed"," Closing level 4 = ",LevelClose[3],"Point n"); } //--- if(PercentClose[0]!=(int)StringToInteger(ObjectGetString(0,"cm PCPPercents1",OBJPROP_TEXT))) { PercentClose[0]=(int)StringToInteger(ObjectGetString(0,"cm PCPPercents1",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"Modified":"Changed"," Closing percentage 1 = ",PercentClose[0],"%n"); } if(PercentClose[1]!=(int)StringToInteger(ObjectGetString(0,"cm PCPPercents2",OBJPROP_TEXT))) { PercentClose[1]=(int)StringToInteger(ObjectGetString(0,"cm PCPPercents2",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"Modified":"Changed"," Closing percentage 2 = ",PercentClose[1],"%n"); } if(PercentClose[2]!=(int)StringToInteger(ObjectGetString(0,"cm PCPPercents3",OBJPROP_TEXT))) { PercentClose[2]=(int)StringToInteger(ObjectGetString(0,"cm PCPPercents3",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"Modified":"Changed"," Closing percentage 3 = ",PercentClose[2],"%n"); } if(PercentClose[3]!=(int)StringToInteger(ObjectGetString(0,"cm PCPPercents4",OBJPROP_TEXT))) { PercentClose[3]=(int)StringToInteger(ObjectGetString(0,"cm PCPPercents4",OBJPROP_TEXT)); txt=StringConcatenate(txt,LANGUAGE?"Modified":"Changed"," Closing percentage 4 = ",PercentClose[3],"%n"); } //--- if(ShowOrder != ObjectGetInteger(0,"cm PCP ShowOrder",OBJPROP_STATE)) { ShowOrder = ObjectGetInteger(0,"cm PCPShowOrder",OBJPROP_STATE); if(!ShowOrder) ObjectsDeleteAll(0,"cm PCP srt"); } if(SymbolAll != ObjectGetInteger(0,"cm PCP Symbol",OBJPROP_STATE)) { SymbolAll = ObjectGetInteger(0,"cm PCP Symbol",OBJPROP_STATE); ObjectSetString(0,"cm PCPSymbol",OBJPROP_TEXT,SymbolAll?"All currency pairs":Symbol()); } doublePOINT,BID,ASK,Profit,OOP,OSL,SL,LotsClose; inti,DIGITS,ParentTicket=0; intNO=0; doubleOL; boolSS=false; intn=0; for(i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()==Magic || Magic==-1) { string OrdSym=OrderSymbol(); if(OrdSym==Symbol() || SymbolAll) { double TekLot=OrderLots(); OL=TekLot; double STOPLEVEL=MarketInfo(OrdSym,MODE_STOPLEVEL); DIGITS=(int)MarketInfo(OrdSym,MODE_DIGITS); POINT=MarketInfo(OrdSym,MODE_POINT); BID=NormalizeDouble(MarketInfo(OrdSym,MODE_BID),DIGITS); ASK=NormalizeDouble(MarketInfo(OrdSym,MODE_ASK),DIGITS); OOP =NormalizeDouble(OrderOpenPrice(),DIGITS); OSL =NormalizeDouble(OrderStopLoss(),DIGITS); Profit =OrderProfit()+OrderCommission()+OrderSwap(); int Ticket=OrderTicket(); ParentTicket=LastPositionTicket(OrderComment()); NO=0; if(ParentTicket!=0) { if(GlobalVariableCheck(StringConcatenate(GVp,ParentTicket,OrdSym,"Num"))) { NO=((int)GlobalVariableGet(StringConcatenate(GVp,ParentTicket,OrdSym,"Num")))+1; } if(GlobalVariableCheck(StringConcatenate(GVp,ParentTicket,OrdSym,"Lots"))) { OL=GlobalVariableGet(StringConcatenate(GVp,ParentTicket,OrdSym,"Lots")); } } GlobalVariableSet(StringConcatenate(GVp,Ticket,OrdSym,"Num"),NO); GlobalVariableSet(StringConcatenate(GVp,Ticket,OrdSym,"Lots"),OL); if(NO=ArraySize(LevelClose))NO=ArraySize(LevelClose)-1; RefreshRates(); if(OrderType()=OOP)Orders[n][2]=Orders[n][2]+" lossless"; Orders[n][4]=StringConcatenate(NO," - ",DoubleToString(PercentClose[NO],0),"%"); Orders[n][5]=StringConcatenate(DoubleToString((BID-OOP)/POINT,0)," point(",IntegerToString(LevelClose[NO]),")"); n++; if(NormalizeDouble(BID-OOP,DIGITS)>=NormalizeDouble(POINT*LevelClose[0],DIGITS)) { SL=NormalizeDouble(OOP+lossless profit*POINT,DIGITS); if (OSL!=SL&& BID>SL+STOPLEVEL*POINT) { if(!OrderModify(Ticket,OOP,SL,OrderTakeProfit(),0,clrNONE)) Print("Order modification error",(GetLastError())); elsetxt=StringConcatenate(txt,"Lossless Protection",Ticket," ",OrdSym,"Buy",DoubleToString(OSL,DIGITS)," ->",DoubleToString(SL,DIGITS),"n"); } } if(NormalizeDouble(BID-OOP,DIGITS)>=NormalizeDouble(POINT*LevelClose[NO],DIGITS)) { LotsClose=CheckVolumeValue(PercentClose[NO]/100.0*OL,OrdSym); if(LotsClose>0) { LotsClose=MathMin(LotsClose,TekLot); if(!OrderClose(Ticket,LotsClose,NormalizeDouble(BID,DIGITS),Slippage Tolerance,CLR_NONE)) { Print("Close Error",GetLastError()); } else { SS=true; txt=StringConcatenate(txt,"Close",Ticket,"",OrdSym," Buy",DoubleToString(LotsClose,2)," (",DoubleToString(OL,2),")",NO," level=",IntegerToString(LevelClose[NO]),"n"); } } } } if(OrderType()==OP_SELL) { Orders[n][2]="Sell"; if (OSL!=0 &&OSL<=OOP) Orders[n][2]=Orders[n][2]+" lossless"; Orders[n][4]=StringConcatenate(NO," -",DoubleToString(PercentClose[NO],0),"%"); Orders[n][5]=StringConcatenate(DoubleToString((OOP-ASK)/POINT,0)," point(",IntegerToString(LevelClose[NO]),")"); n++; if(NormalizeDouble(OOP-ASK,DIGITS)>=NormalizeDouble(POINT*LevelClose[0],DIGITS)) { SL=NormalizeDouble(OOP-lossless profit*POINT,DIGITS); if (OSL!=SL&& ASK=NormalizeDouble(POINT*LevelClose[NO],DIGITS)) { LotsClose=CheckVolumeValue(PercentClose[NO]/100.0*OL,OrdSym); if(LotsClose>0) { LotsClose=MathMin(LotsClose,TekLot); if(!OrderClose(Ticket,LotsClose,NormalizeDouble(ASK,DIGITS),Slippage Tolerance,CLR_NONE)) { Print("Close Error",GetLastError()); } else { SS=true; txt=StringConcatenate(txt,"Close",Ticket,"",OrdSym," Sell ",DoubleToString(LotsClose,2)," (",DoubleToString(OL,2),")",NO," level=",IntegerToString(LevelClose[NO]),"n"); } } } } } }} } if(IsTesting() && n==0) { if(OrderSend(Symbol(),OP_BUY,CheckVolumeValue(1.0),NormalizeDouble(Ask,Digits),0,0,0,NULL,0,0)==-1)Print("Error",GetLastError()); if (OrderSend(Symbol(),OP_SELL,CheckVolumeValue(1.0),NormalizeDouble(Bid,Digits),0,0,0,NULL,0,0)==-1)Print("Error",GetLastError()); } if(ShowOrder) { int X=0,Y=20; for(i=0; i=n) { ObjectDelete(0,StringConcatenate("cm PCP srt",i,"",j)); } else { int y=100; color colort=clrWhite; switch(j) { case 0: y=100;break; case 1: y=80;break; case 2: y=50; if(StringFind(Orders[i][2],"lossless")!=-1) colort=clrLime; break; case 3: y=100; if(Orders[i][8]!="") colort=ColorN[StrToInteger(Orders[i][8])];break; case 4: y=50;break; case 5: y=100; if(StringFind(Orders[i][5],"-")==-1)colort=clrLime; break; case 6: y=100; if(StringFind(Orders[i][6],"-")==-1)colort=clrLime; break; case 7: y=120;break; case 8: y=25;break; case 9: y=25;break; } EditCreate(0,StringConcatenate("cm PCP srt",i,"",j),0,X,Y,y,15,Orders[i][j],"Arial",10,ALIGN_CENTER,true,CORNER_LEFT_UPPER, clrBlack,colort,clrGray,false,false,true,0); X+=y-1; } } Y+=14; } N=n; Comment(txt); } //+------------------------------------------------------------------+ //| TimeCurrent(tm); int TekHour = tm.hour; int Minute = tm.min; int Seconds = tm.sec; #endif string ScreenShotName=StringConcatenate("cmPCP","//",TimeToString(TimeCurrent(),TIME_DATE)," "); ScreenShotName=StringConcatenate(ScreenShotName,TekHour<10?"0":"",IntegerToString(TekHour),"-",Minute<10?"0":"",IntegerToString(Minute),"-",Seconds=0) { int tPos2=StringFind(aComment,"#"); if(tPos2>tPos1) { return(StrToInteger(StringSubstr(aComment,tPos2+1,StringLen(aComment)-tPos2-1))); } } return(0); } //+--------------------------------------------------------------------------------+ //| | //+--------------------------------------------------------------------------------+ doubleCheckVolumeValue(double volume, string Sim=NULL) { doublemin_volume=SymbolInfoDouble(Sim,SYMBOL_VOLUME_MIN); if(volumemax_volume) return(max_volume); doublevolume_step=SymbolInfoDouble(Sim,SYMBOL_VOLUME_STEP); intratio=(int)MathRound(volume/volume_step); if(MathAbs(ratio*volume_step-volume)>0.0000001)return(ratio*volume_step); return(volume); } //+------------------------------------------------------------------+ //| Sub-window number const int x=0, // Alignment const bool read_only=false, // Whether it is editable const ENUM_BASE_CORNERcorner=CORNER_LEFT_UPPER, // Chart corner binding const color clr=clrBlack, // Text color const color back_clr=clrWhite, // Background color const color border_clr=clrNONE, // Border color const bool back=false, // Whether in the background const bool selection=false, // Whether it can be selected and moved const bool hidden=true, // Whether it is hidden in the object list const long z_order=0, // Mouse click priority const string podskazka="") { if(ObjectFind(chart_ID,name)==0) { ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); } else { if(!ObjectCreate(chart_ID,name,OBJ_EDIT,sub_window,0,0))return(false); ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,(int)(x*interface scaling ratio)); ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,(int)(y*interface scaling ratio)); ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,(int)(width*interface scaling ratio)); ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,(int)(height*interface scaling)); ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); ObjectSetString(chart_ID,name,OBJPROP_FONT,font); ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); ObjectSetInteger(chart_ID,name,OBJPROP_ALIGN,align); ObjectSetInteger(chart_ID,name,OBJPROP_READONLY,read_only); ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr); ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,podskazka); } return(true); } //+-----------------------------------------------------------------+ boolButtonCreate(const long chart_ID=0, // chart ID const string name="Button", // Button name const int sub_window=0, // Sub-window number const int x=0, // X-axis coordinate const int y=0, // Y-axis coordinate const int width=50, // Button width const int height=18, // Button height const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // Chart corner binding const string text="Button", // Text const string font="Arial", // Font const int font_size=10, // Font size const color clr=clrBlack, // Text color const color back_clr=C'236,233,216', // Background color const color border_clr=clrNONE, // Border color const bool state=false, // Whether to press const bool back=false, // Whether in the background const bool selection=false, // Whether it can be selected and moved const bool hidden=true, // Whether it is hidden in the object list const long z_order=0, // Mouse click priority const string podskazka="") { if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))return(false); ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,(int)(x*interface scaling ratio)); ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,(int)(y*interface scaling ratio)); ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,(int)(width*interface scaling ratio)); ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,(int)(height*interface scaling)); ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); ObjectSetString(chart_ID,name,OBJPROP_FONT,font); ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr); ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,podskazka); return(true); } //+------------------------------------------------------------------+ SHAPE MERGEFORMAT SHAPE MERGEFORMAT 222.png
Partial closing source code source code download and deployment instructions key points before use
This page has been reorganized according to the reading path of search users, focusing on the applicable scenarios of EA source code, MQL4/MQL5 platform compatibility, parameter testing methods and real-time risk warnings, so as to quickly judge whether it is worth continuing to test before downloading or deploying.
Suitable for who to use
- Traders who need to quickly screen EA source code and are willing to do simulation verification first.
- People who are already familiar with the MT4/MT5 installation process and want to compare different EAs, indicators or source code projects.
- People who want to record the backtest, parameters and risk control before deciding whether to enter the real market.
Testing and risk control suggestions
- First use the default parameters for basic backtesting, and then adjust them one by one according to the variety, cycle and spread.
- Grid, Martin, and scalping strategies should focus on observing maximum drawdown, continuous losses, and trading frequency.
- It is recommended to observe the simulated trading performance for at least 2-4 weeks before the actual trading, and limit the account risk proportion of a single strategy.
FAQ
Can this file be sold directly?
It is not recommended to make a direct offer. Any EA or indicator requires first checking the source, parameters, platform version and historical performance.
Can MT4 and MT5 be used interchangeably?
Usually it cannot be used directly. MQ4/EX4 corresponds to MT4, MQ5/EX5 corresponds to MT5, and the source code project also needs to be compiled in the corresponding MetaEditor.
What else can I continue to watch?
Forex EA download , foreign exchange indicator download , EA evaluation , GitHub open source EA , MQL5 CodeBase .
English Search Notes
This page is also optimized for English search intent around partial closing source code download and deployment instructions . Related search terms include: MQL4 source code, MQL5 source code. Test any Forex EA, Expert Advisor, MT4/MT5 indicator or MQL source code with historical data and a demo account before live trading.
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •