How to lock equity periodicaly

 

How to lock equity periodicaly, example first equity 300, when reach 330 stop and continue next week. Start again with 330, when reach 363 stop ad continue next week again.

i tried with :

double Eq=AccountEquity();

if (AccountProfit()>= Eq+(0.1*Eq)){
for (int l=OrdersTotal();l>=0;l--){
OrderSelect(l,SELECT_BY_POS);
deleteOrder();
deletePending();
if (TotalOrders()>0)
deleteOrder();
deletePending();
Eq=AccountEquity();
Sleep(DayOfWeek()==0);
return(0);

}} else

but nothing happened.

Please help, Thanks

 
kieruwin wrote >>

How to lock equity periodicaly, example first equity 300, when reach 330 stop and continue next week. Start again with 330, when reach 363 stop ad continue next week again.

i tried with :

double Eq=AccountEquity();

if (AccountProfit()>= Eq+(0.1*Eq)){
for (int l=OrdersTotal();l>=0;l--){
OrderSelect(l,SELECT_BY_POS);
deleteOrder();
deletePending();
if (TotalOrders()>0)
deleteOrder();
deletePending();
Eq=AccountEquity();
Sleep(DayOfWeek()==0);
return(0);

}} else

but nothing happened.

Please help, Thanks

Make sure you declare (and assign value) to Eq in a way that will not be updated everytime the Start() function runs.

Try like this:

In the global variables declaration area i.e. not inside Start()

double Eq = -1;

Then IN Start()

if (Eq == -1) Eq = AccountEquity(); //This way it will only be updated the first time Start() runs

It is not a good idea to use sleep for the "dormant" time of your ea as you do not know how long it is until the beginning of the new week and Sleep() will stop all trading for the specific number of seconds you set in the ()

Rather try this:

In the global variables area:

bool Dormant = true;

Then in the Start() function:

if (Dormant == true)

{

enter your trades until Equity reaches this value you want

then when your Equity reaches the value

Dormant = false;

}

else

{

//delete all trades:

for (int i=OrdersTotal(), i>=0; i--)

{
OrderSelect(l,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY)

{

if (OrderClose(OrderTicket(), OrderLots(), Ask, 30,Blue) == false) Print ("OrderClose for ticket "+OrderTicket()+" failed with error "+GetLastError());

}

if (OrderType()==OP_SELL)

{

if(OrderClose(OrderTicket(), OrderLots(), Bid, 30, Red) == false) Print ("OrderClose for ticket "+OrderTicket()+" failed with error "+GetLastError());

}

if ((OrderType() == OP_SELLLIMIT) || (OrderType() == OP_SELLSTOP) || (OrderType() == OP_BUYLIMIT) || (OrderType() == OP_BUYSTOP))

{

if (OrderDelete (OrderTicket()) == false) Print ("Pending Order Delete failed with error "+GetLastError());

}

}

}

I didn't test the code (just wrote it off the cuff). I just tried to show some ideas of how to do it.

Good Luck

whocares

 
whocares wrote >>

Make sure you declare (and assign value) to Eq in a way that will not be updated everytime the Start() function runs.

Try like this:

....Good Luck

whocares

Thank you, i will try it now. (^o^)

 
whocares wrote >>

Make sure you declare (and assign value) to Eq in a way that will not be updated everytime the Start() function runs.

Try like this:

...

Good Luck

whocares

I tried with "double Eq = -1;" on global variables and code inside "start":

if (Eq == -1) Eq = AccountEquity();
if (AccountEquity()>= Eq+(0.1*Eq)){ // 10% of the equity
for (int l=OrdersTotal();l>=0;l--){
OrderSelect(l,SELECT_BY_POS);
deleteOrder();
deletePending();
if (TotalOrders()>0)
deleteOrder();
deletePending();
Sleep(86400000); // example i want to sleep for 1 day
return(0);

}} else

but the result is the EA stop when reach 330 and not trade again, is there something wrong? Why it cannot continue trade with the new equity(330) and stop in363,etc ?

please help, thanks

 
kieruwin wrote >>

I tried with "double Eq = -1;" on global variables and code inside "start":

if (Eq == -1) Eq = AccountEquity();
if (AccountEquity()>= Eq+(0.1*Eq)){ // 10% of the equity
for (int l=OrdersTotal();l>=0;l--){
OrderSelect(l,SELECT_BY_POS);
deleteOrder();
deletePending();
if (TotalOrders()>0)
deleteOrder();
deletePending();
Sleep(86400000); // example i want to sleep for 1 day
return(0);

}} else

but the result is the EA stop when reach 330 and not trade again, is there something wrong? Why it cannot continue trade with the new equity(330) and stop in363,etc ?

please help, thanks

You have to reset the value of Eq after the timeout period so the cycle can start again.

In this example, after your Sllep function add:

Eq = AccountEquity();

Hope that helps

whocares

 
whocares wrote >>

You have to reset the value of Eq after the timeout period so the cycle can start again.

In this example, after your Sllep function add:

Eq = AccountEquity();

Hope that helps

whocares

It works now, thank you man, you are the best.

Reason: