ROOI:
Now if I Close on the window the order will close even if there is no tick.The problem is you can't close a partial position on that window.Only the whole order,so if I want to close the order partially I need to open the Order Window like below
My problem is I don't like that big window I want a small window or a button or something but I have in the past made an EA that can do the job but needs a tick to run.
There has to be a different function activated for the button that the mt4 interface produces as apposed to what we code in the EAs
Is there a way I can access that function or how does it work as I have limited knowledge about coding but only some idea about the nuts and bolts of mt4.
Is there anyone that know the mt4 platform that well or where can I ask ?
Hi
I was wondering if anyone here might know the following or have a suggestion of how to do the following:
Say I open a postion using the MarketDepth Window by click buy like below
Now if I Close on the window the order will close even if there is no tick.The problem is you can't close a partial position on that window.Only the whole order,so if I want to close the order partially I need to open the Order Window like below
If I click on the close button that window it partially close the size I wanted even if there is no tick that comes in.
My problem is I don't like that big window I want a small window or a button or something but I have in the past made an EA that can do the job but needs a tick to run.
There has to be a different function activated for the button that the mt4 interface produces as apposed to what we code in the EAs
Is there a way I can access that function or how does it work as I have limited knowledge about coding but only some idea about the nuts and bolts of mt4.
Is there anyone that know the mt4 platform that well or where can I ask ?
Thank you for your time
If you put that previous robot OnTIck() code in:
OnTimer()
{
}
Function then it does not need a tick anymore it will run on set intervals.
Marco vd Heijden:
If you put that previous robot OnTIck() code in:
I see, Thank you very much for this info.
Would you mind helping as to how to update the code below please
//+------------------------------------------------------------------+ //| PartialClose_EA_V1.mq4 | //| Copyright 2014, bla | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, bla" #property link "http://www.mql5.com" #property version "1.00" #property description "blabla" #property strict input double Percent=50.0; input int Slippage=3; input int X_Distance=20; input int Y_Distance=50; input int Corner=1; bool Partial=false; double mult=1.0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- if(Digits==1 || Digits==3 || Digits==5) mult=10.0; if(!ObjectCreate(0,"PartialClose_EA",OBJ_BUTTON,0,0,0)) { Print(__FUNCTION__, ": failed to create the button! Error code = ",GetLastError()); return(INIT_FAILED); } //--- set button coordinates ObjectSetInteger(0,"PartialClose_EA",OBJPROP_XDISTANCE,X_Distance); ObjectSetInteger(0,"PartialClose_EA",OBJPROP_YDISTANCE,Y_Distance); //--- set button size ObjectSetInteger(0,"PartialClose_EA",OBJPROP_XSIZE,100); ObjectSetInteger(0,"PartialClose_EA",OBJPROP_YSIZE,30); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"PartialClose_EA",OBJPROP_CORNER,Corner); //--- set the text ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"PARTIAL CLOSE"); //--- set text font ObjectSetString(0,"PartialClose_EA",OBJPROP_FONT,"Arial"); //--- set font size ObjectSetInteger(0,"PartialClose_EA",OBJPROP_FONTSIZE,9); //--- set text color ObjectSetInteger(0,"PartialClose_EA",OBJPROP_COLOR,clrBlack); //--- set background color ObjectSetInteger(0,"PartialClose_EA",OBJPROP_BGCOLOR,C'236,233,216'); //--- set border color ObjectSetInteger(0,"PartialClose_EA",OBJPROP_BORDER_COLOR,clrNONE); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"PartialClose_EA",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"PartialClose_EA",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"PartialClose_EA",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"PartialClose_EA",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object PartialClose_EA in the object list ObjectSetInteger(0,"PartialClose_EA",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"PartialClose_EA",OBJPROP_ZORDER,0); //--- successful execution //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- ObjectDelete(0,"PartialClose_EA"); //--- } //+------------------------------------------------------------------+ //| Expert PartialClose function | //+------------------------------------------------------------------+ void PartialClose() { //--- int result; for (int i = OrdersTotal()-1; i >= 0; i--) { if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if(OrderSymbol() == Symbol() && (OrderType()<2) ) { while(IsTradeContextBusy()) Sleep(50); RefreshRates(); double lot = OrderLots()*Percent/100.0; lot = MathMax(lot,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)); lot = MathMin(lot,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX)); double volumeStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP); int digits = (int)MathCeil(MathLog10(1/volumeStep)); lot = NormalizeDouble(lot,digits); if(OrderType() == OP_BUY) { result = OrderClose(OrderTicket(),lot,Bid,Slippage,clrGold); } else if(OrderType() == OP_SELL) { result = OrderClose(OrderTicket(),lot,Ask,Slippage,clrGold); } } } ObjectSetInteger(0,"PartialClose_EA",OBJPROP_STATE,false); ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"PARTIAL CLOSE"); Partial=false; //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() // Is this only place to change ? { //--- if(Partial) PartialClose(); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_OBJECT_CLICK && sparam=="PartialClose_EA") { Partial=true; ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"Wait..."); } } //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //| PartialClose_EA_V1.mq4 | //| Copyright 2014, bla | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, bla" #property link "http://www.mql5.com" #property version "1.00" #property description "blabla" #property strict input double Percent=50.0; input int Slippage=3; input int X_Distance=20; input int Y_Distance=50; input int Corner=1; bool Partial=false; double mult=1.0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- create timer EventSetMillisecondTimer(250); //--- if(Digits==1 || Digits==3 || Digits==5) mult=10.0; if(!ObjectCreate(0,"PartialClose_EA",OBJ_BUTTON,0,0,0)) { Print(__FUNCTION__, ": failed to create the button! Error code = ",GetLastError()); return(INIT_FAILED); } //--- set button coordinates ObjectSetInteger(0,"PartialClose_EA",OBJPROP_XDISTANCE,X_Distance); ObjectSetInteger(0,"PartialClose_EA",OBJPROP_YDISTANCE,Y_Distance); //--- set button size ObjectSetInteger(0,"PartialClose_EA",OBJPROP_XSIZE,100); ObjectSetInteger(0,"PartialClose_EA",OBJPROP_YSIZE,30); //--- set the chart's corner, relative to which point coordinates are defined ObjectSetInteger(0,"PartialClose_EA",OBJPROP_CORNER,Corner); //--- set the text ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"PARTIAL CLOSE"); //--- set text font ObjectSetString(0,"PartialClose_EA",OBJPROP_FONT,"Arial"); //--- set font size ObjectSetInteger(0,"PartialClose_EA",OBJPROP_FONTSIZE,9); //--- set text color ObjectSetInteger(0,"PartialClose_EA",OBJPROP_COLOR,clrBlack); //--- set background color ObjectSetInteger(0,"PartialClose_EA",OBJPROP_BGCOLOR,C'236,233,216'); //--- set border color ObjectSetInteger(0,"PartialClose_EA",OBJPROP_BORDER_COLOR,clrNONE); //--- display in the foreground (false) or background (true) ObjectSetInteger(0,"PartialClose_EA",OBJPROP_BACK,false); //--- set button state ObjectSetInteger(0,"PartialClose_EA",OBJPROP_STATE,false); //--- enable (true) or disable (false) the mode of moving the button by mouse ObjectSetInteger(0,"PartialClose_EA",OBJPROP_SELECTABLE,false); ObjectSetInteger(0,"PartialClose_EA",OBJPROP_SELECTED,false); //--- hide (true) or display (false) graphical object PartialClose_EA in the object list ObjectSetInteger(0,"PartialClose_EA",OBJPROP_HIDDEN,false); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(0,"PartialClose_EA",OBJPROP_ZORDER,0); //--- successful execution //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- destroy timer EventKillTimer(); //--- ObjectDelete(0,"PartialClose_EA"); //--- } //+------------------------------------------------------------------+ //| Expert PartialClose function | //+------------------------------------------------------------------+ void PartialClose() { //--- int result; for (int i = OrdersTotal()-1; i >= 0; i--) { if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if(OrderSymbol() == Symbol() && (OrderType()<2) ) { while(IsTradeContextBusy()) Sleep(50); RefreshRates(); double lot = OrderLots()*Percent/100.0; lot = MathMax(lot,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)); lot = MathMin(lot,SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX)); double volumeStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP); int digits = (int)MathCeil(MathLog10(1/volumeStep)); lot = NormalizeDouble(lot,digits); if(OrderType() == OP_BUY) { result = OrderClose(OrderTicket(),lot,Bid,Slippage,clrGold); } else if(OrderType() == OP_SELL) { result = OrderClose(OrderTicket(),lot,Ask,Slippage,clrGold); } } } ObjectSetInteger(0,"PartialClose_EA",OBJPROP_STATE,false); ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"PARTIAL CLOSE"); Partial=false; //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() // Is this only place to change ? { //--- //if(Partial) PartialClose(); } //+------------------------------------------------------------------+ //| Expert timer function | //+------------------------------------------------------------------+ void OnTimer() // Is this only place to change ? { //--- if(Partial) PartialClose(); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_OBJECT_CLICK && sparam=="PartialClose_EA") { Partial=true; ObjectSetString(0,"PartialClose_EA",OBJPROP_TEXT,"Wait..."); } } //+------------------------------------------------------------------+
Marco vd Heijden:
I see,
Thank you very much for the help and advice.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi
I was wondering if anyone here might know the following or have a suggestion of how to do the following:
Say I open a postion using the MarketDepth Window by click buy like below
![](https://c.mql5.com/3/104/a_Open__1.png)
The trade will fill even if there is no tick that comes into the platform.The broker just needs to fill the order if possible at that price.Now if I Close on the window the order will close even if there is no tick.The problem is you can't close a partial position on that window.Only the whole order,so if I want to close the order partially I need to open the Order Window like below
My problem is I don't like that big window I want a small window or a button or something but I have in the past made an EA that can do the job but needs a tick to run.
There has to be a different function activated for the button that the mt4 interface produces as apposed to what we code in the EAs
Is there a way I can access that function or how does it work as I have limited knowledge about coding but only some idea about the nuts and bolts of mt4.
Is there anyone that know the mt4 platform that well or where can I ask ?
Thank you for your time