• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 10:15pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 10:15pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

MT4 error code 3 Invalid_trade Parameters on EA - help! 2 replies

MT4 symbol parameters 0 replies

How do I prevent MT4 from shrinking parameters? 4 replies

Mt4 - EA last used parameters 2 replies

Resetting Market Watch to local Time 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe

Resetting MT4 EA Parameters through code

  • Post #1
  • Quote
  • First Post: Jul 13, 2015 5:27pm Jul 13, 2015 5:27pm
  •  Pipologist
  • Joined May 2009 | Status: testing/trading/testing/trading... | 1,799 Posts
Is there any way to reset the EA parameters automatically through code instead of opening the EA properties settings and clicking reset?

I'd like to have the settings reset after each order close cycle when the orderstotal == 0.

Basically, I'd like to force it to do an "uninitialization" for reason 5. I wish I could just do something like "uninit(5)" but there is no such code recognized.

How could I do this?
  • Post #2
  • Quote
  • Jul 14, 2015 3:52am Jul 14, 2015 3:52am
  •  rockit
  • Joined Oct 2013 | Status: Member | 917 Posts
Not sure what you are trying to accomplish (that is, asking for), but you can "reset" any variable at any time by simply assigning to it an initial value. If you have input variables (that is constants) simply create a new (working) set of runtime variables that you populate with the input values at the init process, henceforth you use only the working variables and not the input constants, which you can re-assign at any point in code.
..
 
 
  • Post #3
  • Quote
  • Jul 14, 2015 4:04am Jul 14, 2015 4:04am
  •  honestknave
  • Joined Nov 2014 | Status: Member | 1,300 Posts
Change your input variables to extern variables.

You can modify externs like normal variables from within your code.

It saves running 2 sets of variables.
 
 
  • Post #4
  • Quote
  • Jul 14, 2015 10:47am Jul 14, 2015 10:47am
  •  Pipologist
  • Joined May 2009 | Status: testing/trading/testing/trading... | 1,799 Posts
I have an extern here

extern double AccountEquityProtectDollars = 0;

that I change manually mid trade and would like it reset to zero after the trade is automatically closed.

The initial amount of zero for the variable is currently necessary since other amounts are calculated based on this figure being zero.

Basically I have a manual scalping EA that automatically sets a hidden SL based on equity value and then I change the min equity to protect mid trade, which is the variable figure above. When and after the equity value is hit either by stop or by me manually pulling out or by other variables being hit, I'd like the populated amount for the variable above reset to zero. I was thinking a complete EA reset would do the job, but resetting the variable only, still leaves the manually inputted figure in the extern variable field within the EA parameters. Either way I would like to ensure that the variable is automatically set to zero after each set of trades are closed out, since there have been more than a few times that in the heat of the moment trading and resetting the EA manually, that I forgot to do so and got taken out of the trade instantly after opening since the equity was already lower than the manually inputted amount.

I was thinking something like this but not sure if it would work...

Inserted Code
void CompleteCloseOut() {
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--) {
if(!OrderSelect(i, SELECT_BY_POS))
{
Print(TimeToStr(TimeCurrent(),TIME_SECONDS), " CHECK Function > ", __FUNCTION__," !!!!! ", OrderMagicNumber(), " Error code = ", GetLastError()); }
else
int result;
 
 if ((OrderType() == OP_BUY) && (OrderSymbol() == "GOLD"))
 { result = OrderClose(OrderTicket(),OrderLots(),MarketInfo("GOLD",MODE_BID),MaxSlippage*2,CLR_NONE); }
 if ((OrderType() == OP_SELL) && (OrderSymbol() == "GOLD"))
 {result = OrderClose(OrderTicket(),OrderLots(),MarketInfo("GOLD",MODE_ASK),MaxSlippage*2,CLR_NONE); }
 
 if ((OrderType() == OP_BUY) && (OrderSymbol() == "EURUSD"))
 { result = OrderClose(OrderTicket(),OrderLots(),MarketInfo("EURUSD",MODE_BID),MaxSlippage*2,CLR_NONE); }
 if ((OrderType() == OP_SELL) && (OrderSymbol() == "EURUSD"))
 {result = OrderClose(OrderTicket(),OrderLots(),MarketInfo("EURUSD",MODE_ASK),MaxSlippage*2,CLR_NONE); }
 
 return;
 }
 
Print(TimeToStr(TimeCurrent(),TIME_SECONDS), " CLOSED ALL OPEN ORDERS VIA COMPLETE CLOSE OUT CLOSE OUT FUNCTION ", "  Last: ", DoubleToStr(Close[0], Digits), "   Open Trades: ",  OrdersTotal());
 
  AccountEquityProtectDollars = 0;
 
  return; }

Of that only leaves the variable still at the manually set amount doesn't it?
 
 
  • Post #5
  • Quote
  • Jul 14, 2015 11:34am Jul 14, 2015 11:34am
  •  Pipologist
  • Joined May 2009 | Status: testing/trading/testing/trading... | 1,799 Posts
For now rather than resetting I just filtered out any EQ Stop Losses to amounts less than current EQ. Duh...

Inserted Code
if (AccountEquityProtectDollars > AccountEquity() && (OrdersTotal() == 0))
{Comment(TimeToStr(TimeCurrent(),TIME_SECONDS), "  ERROR !!!  ESP VALUE IS GREATER THAN CURRENT ACCOUNT EQUITY !!!  RESET VALUE NOW !!!  NOT PROTECTED !!! "); return(0);}
 
if (AccountEquityProtectDollars > AccountEquity()) AccountEquityProtectDollars = InitialEquityProtectAmountOut;
 
 
  • Post #6
  • Quote
  • Last Post: Jul 14, 2015 11:44am Jul 14, 2015 11:44am
  •  Pipologist
  • Joined May 2009 | Status: testing/trading/testing/trading... | 1,799 Posts
Whoops that doesn't work. It now does not take me out of the trade, just merely sets the amount to the initial EQ stop out. For now, I'll just live with the manual warning...

if (AccountEquityProtectDollars > AccountEquity() && (OrdersTotal() == 0))
{Comment(TimeToStr(TimeCurrent(),TIME_SECONDS), " ERROR !!! ESP VALUE IS GREATER THAN CURRENT ACCOUNT EQUITY !!! RESET VALUE NOW !!! NOT PROTECTED !!! "); return(0);}
 
 
  • Platform Tech
  • /
  • Resetting MT4 EA Parameters through code
  • Reply to Thread
0 traders viewing now
Top of Page
Forex Factory Blog Updated: Alerting All Members
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022