forex software

Create and Test Forex Strategies

forex software

Skip to forum content

Forex Forum

Forex Software, Forex Strategies, Expert Advisors Generator

You are not logged in. Please login or register.


(Page 1 of 2)

Forex Forum → Expert Advisor Studio → Close all Script

Pages 1 2 Next

You must login or register to post a reply

RSS topic feed

Posts: 1 to 25 of 43

Topic: Close all Script

Hello Miroslav,

you have long Time back give a Close all Script for the EAStudio Portfolio.

Can you change the script with a Option for a firm TP for the Portfolio? Is it possible for this Script?

I mean, when all Trades in xx profit, then Close all Trades (loss and win Trades)

Thank you, Marcus.

Re: Close all Script

I to would love a script like this as it is very important to reduce market exposure!

3 (edited by GD 2019-04-12 10:39:39)

Re: Close all Script

It can be done separate with an extra HIDDEN EA made by the user for all or some EAs running
This EA can check also statistics of each EA of portfolio or other EA and if no good close specific EA
It can be part of EA portfolio also
Possibly I will try to do it in future myself.

The EA studio EAs can be used with many ways of management.
I think this is the main reason Popov does not want to complicate the things and keeps the code simple.

I just gave some ideas for all of us to talk about.
EA studio can keep i.e. all trades in a file (trading or not) and user use another file to open or close EAs to run even changing a parameters file.

Re: Close all Script

Let's be clear on why I would like to .... I find that the Portfolio EA's (100 pieces) are relatively good in the first few hours. Very often, within 1-2 hours a good plus and then everything is bad ..... so why not always use this effect?
It is very difficult to sit there all day and close it by hand with the Close Script, so please have something like what you're saying, like ea on second window, where you can set a value in USD, when everything should be closed.

5 (edited by hannahis 2019-04-12 18:39:42)

Re: Close all Script

rantampla wrote:

Let's be clear on why I would like to .... I find that the Portfolio EA's (100 pieces) are relatively good in the first few hours. Very often, within 1-2 hours a good plus and then everything is bad ..... so why not always use this effect?
It is very difficult to sit there all day and close it by hand with the Close Script, so please have something like what you're saying, like ea on second window, where you can set a value in USD, when everything should be closed.

You can consider these 2 options:

1) Use a profit trailing stop: I personally find the profit trailing stop EA, as a dynamic way to handle and close orders.  It's a much more reactive and responsive method than closing with exit rules (unless your exit rules are so perfect and accurate).

For trailing EA, I would recommend either Vanessa Trailing (cost $30 right now, mentioned here https://forexsb.com/forum/post/54380/#p54380 or Trailling OS by Tim (free for the time being, mentioned here https://forexsb.com/forum/post/54290/#p54290

2. Use Fxblue Profit/Loss (P/L) Manager app (free)

User guide for you to read more about it https://www.fxblue.com/appstore/u6/pl-m … guide#toc2

You start P/L Manager by attaching the EA to a chart in MetaTrader. The EA's "Allow live trading" setting must be turned on before starting. The "Allow DLL imports" setting must also be turned on if you want to shut down MT4 when the target is hit.

Set the high and low triggers at which P/L Manager should close orders: the CloseAboveUpperPnL and CloseBelowLowerPnL parameters


There is a saying, "Let Your Profits Run"

Let your profits run is an expression that encourages traders to resist the tendency to sell winning positions too early. The flipside of letting profits run is to cut losses early. The way to make money as a trader, according to many, is to follow both of these pieces of advice.

For example:

1.  I don't want to close all orders when target profit is hit.  Because it's a blanket rule and some EA may still be better off to keep it running.

2. Instead of closing all orders when account's profit target is hit, if I use profit trailing, I can still keep the profitable EA running with appropriate profit trailing and break even setting (such as Vanessa Trailing EA, it has 5 different levels of profit targets and 3 levels of break even targets) so that I can keep the profit running when secure my targeted profit.

3.  And at the same time, I'm not cutting my losses too early (for other losing EA) with a blanket rule of closing all trades.

Re: Close all Script

Hello Hannahis
Thank you for your idea with the Trail SL
I have also thought about it a lot.
The problem, however, still ... as soon as I've closed the good trades, whether by trail or normal, and the market still moves in the same direction after a short break, I have due to the portfolio EA an increased loss speed ,
In my current style, I just close everything and let the portfolio EA start all over again, most of the time you have a fairly balanced hedge level and not the problems of extreme losses at market shift.
I know, it's not actually the goal .... actually the goal is to create very robust EA, which work for a long time .... unfortunately I fail for a long time at this goal .... so I tried this variant now .... Finally, it's just about making money and nothing else .....
For 3 days I test this variant on a live account with 0.01 and despite some larger movements in the EurUsd I have made with 0.01 66 dollars plus, with moderate DD.
I will pursue this further .... because at the robust EA with EAStudio I do not believe more ...

7 (edited by Roughey 2019-04-12 20:39:02)

Re: Close all Script

its easy to make it.

-create a button
-create a function to get all Positions in profit and call the ClosePosition function

;-)

but i prefered to use something like takeprofit basket for all open orders if xxx amount reach close all..or if xx% reach close all

Re: Close all Script

Yes, Roughey, that's what I mean.
If all open trades have an xx profit, I want to close all trades. Not just the basket of winners. But the whole basket.
The idea of Hannahis is good, but not meaningful for my variant ... although I think about it as I could possibly make everything more useful with the idea. I do not have a solution yet smile

Re: Close all Script

ok so you will get it ;-)


HERE put outside ontick

this

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Open_Orders_Profit()
{
   double openordersprofit = 0;
   RefreshRates();
   int Total=OrdersTotal();
   if(Total>0)
   {
      for(int i=Total-1; i>=0; i--)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==TRUE)
         {
            const int magicNumber = OrderMagicNumber();
            if(OrderSymbol()==Symbol() && (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100)))
            {
               openordersprofit +=OrderProfit()+OrderSwap()+OrderCommission();
            }
         }
      }
   }
   return(openordersprofit);
}

That will count all profits of open orders.

Now you have to work with that.

add input variable

input double               TakeProfitAll           = 100;

in Ontick add this.

void OnTick()
  {
    if(Open_Orders_Profit()>=TakeProfitALL)
   {     
      Print("CLOSED ALL OPEN POSITIONS DUE TO TAKEPROFIT ALL REACHED: "+DoubleToString(Open_Orders_Profit(),2)+"| TAKE PROFIT SET: "+DoubleToString(TakeProfitALL,2));
      CloseAllPositions();      
   }

Have a nice weekend.

Re: Close all Script

Thank you, you are a good  men smile

Nice weekend to for you smile

Re: Close all Script

Update for all Interested.

After 1 Week with this System and 0.01 Lot i have 97 USD Profit.

Let us see what this week make.

12 (edited by rantampla 2019-04-19 17:09:13)

Re: Close all Script

no idea if anyone is interested.

Duration of this variant: 1.5 weeks
Calm market and extreme market
1050 trades with 0.01 lot each
Profit after costs: 129.89 USD    (live Trading, not Demo!)

Happy Easter to all smile

Re: Close all Script

Ive just intergrated this code into my portfolios with some great results!

However im wondering 2 things:

1: The takeprofitall value is that in pips?
2: Is it possible to help me reverse this so I can close all when in loss, this way we have Close all in Profit and Close all in Loss?

Re: Close all Script

I have added a Close all if in loss to this code. number needs to be a negative number:

input double TakeProfitALL = 100;
input double TakeLossALL = 100;
void OnTick()
  
  {
    if(Open_Orders_Profit()>=TakeProfitALL)
   {     
      Print("CLOSED ALL OPEN POSITIONS DUE TO TAKEPROFIT ALL REACHED: "+DoubleToString(Open_Orders_Profit(),2)+"| TAKE PROFIT SET: "+DoubleToString(TakeProfitALL,2));
      CloseAllPositions();      
   }
   if(IsForceSessionClose())
     {
      CloseAllPositions();
      return;
     }
     
     if(Open_Orders_Loss()<=TakeLossALL)
   {     
      Print("CLOSED ALL OPEN POSITIONS DUE TO TAKELOSS ALL REACHED: "+DoubleToString(Open_Orders_Loss(),2)+"| TAKE LOSS SET: "+DoubleToString(TakeLossALL,2));
      CloseAllPositions();      
   }

   if(Time[0]>barTime)
     {
      barTime=Time[0];
      OnBar();
     }
  }
  
double Open_Orders_Loss()
{
   double openordersloss = 0;
   RefreshRates();
   int Total=OrdersTotal();
   if(Total>0)
   {
      for(int i=Total-1; i>=0; i--)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==TRUE)
         {
            const int magicNumber = OrderMagicNumber();
            if(OrderSymbol()==Symbol() && (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100)))
            {
               openordersloss +=OrderProfit()+OrderSwap()+OrderCommission();
            }
         }
      }
   }
   return(openordersloss);
}
  
  double Open_Orders_Profit()
{
   double openordersprofit = 0;
   RefreshRates();
   int Total=OrdersTotal();
   if(Total>0)
   {
      for(int i=Total-1; i>=0; i--)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==TRUE)
         {
            const int magicNumber = OrderMagicNumber();
            if(OrderSymbol()==Symbol() && (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100)))
            {
               openordersprofit +=OrderProfit()+OrderSwap()+OrderCommission();
            }
         }
      }
   }
   return(openordersprofit);
   }

However one downfall of this is not having the ability to close all loosing trades in a portfolio an let the winners run. Wold anyone have any idea about how I could only close the loosing trades?

Re: Close all Script

Roughey wrote:

ok so you will get it ;-)


HERE put outside ontick

this

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Open_Orders_Profit()
{
   double openordersprofit = 0;
   RefreshRates();
   int Total=OrdersTotal();
   if(Total>0)
   {
      for(int i=Total-1; i>=0; i--)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==TRUE)
         {
            const int magicNumber = OrderMagicNumber();
            if(OrderSymbol()==Symbol() && (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100)))
            {
               openordersprofit +=OrderProfit()+OrderSwap()+OrderCommission();
            }
         }
      }
   }
   return(openordersprofit);
}

That will count all profits of open orders.

Now you have to work with that.

add input variable

input double               TakeProfitAll           = 100;

in Ontick add this.

void OnTick()
  {
    if(Open_Orders_Profit()>=TakeProfitALL)
   {     
      Print("CLOSED ALL OPEN POSITIONS DUE TO TAKEPROFIT ALL REACHED: "+DoubleToString(Open_Orders_Profit(),2)+"| TAKE PROFIT SET: "+DoubleToString(TakeProfitALL,2));
      CloseAllPositions();      
   }

Have a nice weekend.

Roughey,
can you please look in attached Picture? I have a error and no Idea for that. Can you help me?
Thanks, Marcus

Post's attachments

error.png 108.19 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Re: Close all Script

Hi Marcus,

You need to change:
input double               TakeProfitAll           = 100;

To:

input double               TakeProfitALL          = 100;


It is just a case sensitive issue.

Re: Close all Script

Michael1 wrote:

Hi Marcus,

You need to change:
input double               TakeProfitAll           = 100;

To:

input double               TakeProfitALL          = 100;


It is just a case sensitive issue.

Cool, Michael1. Thank you smile

I must say, when i backtest it is not good. But the Backtest makes all Trades in the same moment open.

I have this now run over 2 weeks live and the trades goes not instantly open, only backtest. in live i have very good results.

Re: Close all Script

Michael1.
Use you this? Have you Experience with that?
Greets, Marcus smile

Re: Close all Script

Hi rant,

I have tested this and I don’t have very good results at all lol. I think it’s more got to do with the strategies you use it on more than anything.

20 (edited by rantampla 2019-04-27 01:35:00)

Re: Close all Script

Michael1 wrote:

Hi rant,

I have tested this and I don’t have very good results at all lol. I think it’s more got to do with the strategies you use it on more than anything.

When i make backtest with this, all is very bad...but when i have it live, it is the best what i have last 2 years make with ea studio big_smile

And this Strategies only 5 minits search without monte carlo and others.

why this is so good, i have no idea, but i use it forward in live smile

p.s. the last days eurusd was very crazy chart... but i have make profit with that. On Friday it was 6 percent smile

Photo is the Balance Chart for 3 Weeks with 0.01 lot smile

Post's attachments

Balance.png 119.03 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

21 (edited by rantampla 2019-05-17 00:44:23)

Re: Close all Script

I do not know if anyone cares. if it does, here is an update of the variant after 6 weeks. Still with 0.01 lot.
The collapse at about 1,741 trades was on the broker, stood still for minutes and the Closebefehl has hit too late and at the worst moment.

I would like to read from others also the experiences. does anyone want to discuss in an extra thread?

In Attachment is the Balancechart after 6 Weeks.

P.S.: I have nothing changed, it is the same Portfolio in EurUsd as before 6 weeks.
No Monte Carlo, No Multi Market No Walk Forward. Nothing. Only few Minutes Search in Generator. smile

Post's attachments

Portfolio100-nach 6 Wochen.png 130.04 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Re: Close all Script

rantampla wrote:

I do not know if anyone cares. if it does, here is an update of the variant after 6 weeks. Still with 0.01 lot.
The collapse at about 1,741 trades was on the broker, stood still for minutes and the Closebefehl has hit too late and at the worst moment.

I would like to read from others also the experiences. does anyone want to discuss in an extra thread?

In Attachment is the Balancechart after 6 Weeks.

P.S.: I have nothing changed, it is the same Portfolio in EurUsd as before 6 weeks.
No Monte Carlo, No Multi Market No Walk Forward. Nothing. Only few Minutes Search in Generator. smile

I´m interested :-D
Can u pls explain the process, what u have done and criterias?

Re: Close all Script

I have no Special Settings use.
Only Tickstory Data for EurUsd M5 from 01.01.2018 till now.
Generator without Special Settings. Only SL maybe use from 10 to 100 and TP maybe use from 10 to 100.
Then run the Generator for 15 Minutes and no check the Backtest. Only put the 100 Strategies in Portfolio.

smile

Re: Close all Script

rantampla wrote:

I have no Special Settings use.
Only Tickstory Data for EurUsd M5 from 01.01.2018 till now.
Generator without Special Settings. Only SL maybe use from 10 to 100 and TP maybe use from 10 to 100.
Then run the Generator for 15 Minutes and no check the Backtest. Only put the 100 Strategies in Portfolio.

smile

Slow learner so happy if u enlighten me.. :-)

Ok, so if I have 100 strategies and I put them on trade, what to do next?

-what script to use that close the trade?
-what criterias for closing the trade? how to do it? if I use the EA:s sl and tp what do the script add then..?
- can I re-use all 100 ea:s all over again or are they out the ones that are "used"?

I would be happy if u explained the whole process, I´m interested to try it out and hopefully maybe even to contribute with something

25 (edited by rantampla 2019-05-17 17:53:32)

Re: Close all Script

Roughey has posted the code for the mq4 file earlier in the post.

You can insert this into the portfolio file.
but: it does not work without watching. I recommend that you recognize support and resistance lines and close all trades when you reach them. So you could call it a semi-automatic trade.
good luck

since 6 weeks i have nothing changed on portfolio smile

Posts: 1 to 25 of 43

Pages 1 2 Next

You must login or register to post a reply

Forex Forum → Expert Advisor Studio → Close all Script

Similar topics in this forum