Disliked@ectrade
Thanks for your reply . but to be frank , due to no prog. background..i m not able to understand the code you posted! esp in absence of explanationIgnored
Attached File(s)
EA/Script to close all orders when profit hit? 11 replies
Script Modification Request - Set SL and TP on all orders 0 replies
Need help to mod "Close All Pending Orders" script 12 replies
script to "close open orders" and "open opposite orders" 3 replies
Disliked@ectrade
Thanks for your reply . but to be frank , due to no prog. background..i m not able to understand the code you posted! esp in absence of explanationIgnored
DislikedSwitch the time frame? And how do you call out a global? Can you show me on the EA provided? Am still learning.Ignored
Dislikedthats a nice piece there, very short, very effective
i do see a problem
if you switch tf, or the broker resets you
Equity_New will be reset to 0
which resets your goal, making your goal higher
id use a global, then it should be invincibleIgnored
//+------------------------------------------------------------------+ //| Close all Orders onTarget.mq4 | //| Copyright © 2009, Dennis Hamiilton | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Dennis Hamiilton" #property link "[email protected]" extern double Set_Profit=0; extern string Reset="n",Close_All="n"; double Equity_New,Equity_Base; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- Check or Set Global Variable for Equity_New if(!GlobalVariableCheck("e_new")||Reset!="n"){ GlobalVariableSet("e_new",0); } if(!GlobalVariableCheck("s_profit")||Reset!="n"){ GlobalVariableSet("s_profit",Set_Profit); } Equity_New=GlobalVariableGet("e_new"); Set_Profit=GlobalVariableGet("s_profit"); //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- if(Set_Profit>0){ if(Equity_New==0){ Equity_New=AccountEquity(); } Equity_Base=AccountEquity(); if(Equity_Base>=Equity_New+Set_Profit){ Equity_New=Equity_Base; Close_All="y"; } if(Close_All=="y") { int total=OrdersTotal(); for(int i=total-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true) { if(OrderType()==OP_BUY||OrderType()==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Red); } if(OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) { OrderDelete(OrderTicket()); } if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP) { OrderDelete(OrderTicket()); } } } Close_All="n"; } } //---- return(0); } //+------------------------------------------------------------------+
QuoteDislikedOkay, so you want it in EA form?
DislikedHey, have just added the globals. Can you check and see if it looks okay? Note that I added the "Reset" option which, if you set it to anything other than "n," it will reset the globals to "0." This should only be necessary if you wish to set a new "Set_Profit" value. I also modified it so everything operates within the "if(Set_Profit>0)" parameters, in case you inadvertently forget to set it which, I suspect will close all trades when you first initialize the EA. And we don't want to have any of that.
[php]//+------------------------------------------------------------------+
//|...Ignored
Dislikedfrom what i see here
in the start function, i dont see you resetting to a new goal after you hit the target
you should set the global to a new goal
you need the stuff in init to be in start() refine the rules so it uses the global always
wrather than set Equity_New=something
the Equity_New=the global
change the global instead of changing Equity_New
you want the global to fully be the new settings
like here
if(Equity_Base>=Equity_New+Set_Profit){ Equity_New=Equity_Base; Close_All="y"; }
instead
if(Equity_Base>=Equity_New+Set_Profit){ globalvariableset....;...Ignored
//+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- Check and Set Global Variables if(!GlobalVariableCheck("e_new")||Reset!="n"){ GlobalVariableSet("e_new",0); } if(!GlobalVariableCheck("s_profit")||Reset!="n"){ GlobalVariableSet("s_profit",Set_Profit); } Set_Profit=GlobalVariableGet("s_profit"); //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- Set Equity_New Equity_New=GlobalVariableGet("e_new"); //---- if(Set_Profit>0){ if(Equity_New==0){ Equity_New=AccountEquity(); } Equity_Base=AccountEquity(); if(Equity_Base>=Equity_New+Set_Profit){ GlobalVariableSet("e_new",Equity_Base); Close_All="y"; }
Dislikedhey saint..... it just occurred to me your question -> have you tested Saint.mq4 code live <-, you are talking about testing live without the trade placing code aren't you......
the trade placing code was just there for visual backtesting as mentioned in that post...... it needs to be removed ....
ran g p morgan on multiple pairs past 24 hours, the saint ea closes the trades like clockwork.......hIgnored