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

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Close pending order on profit taken by magic number 11 replies

Change magic number of open trades? 3 replies

One EA - two independent magic number trades 2 replies

Close all orders with magic number at certain profit 8 replies

how to close a trade with the magic number? 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 5
Attachments: Close all trades, Based on Magic Number Modification
Exit Attachments

Close all trades, Based on Magic Number Modification

  • Post #1
  • Quote
  • First Post: Edited at 3:09pm Oct 4, 2009 2:02pm | Edited at 3:09pm
  •  forexsaint
  • Joined Jun 2009 | Status: <-That's how u gonna b, in the END! | 1,508 Posts
Hello
Attached is a ea which constantly tracks the Floating Accountprofit function to track of a fixed profit entered in settings of the ea,
to close all orders as soon as it is reached.

There is also one around which is based on Symbols.

But i think it will be lot better if we have one which tracks/summarizes the net profit and loss of Orders with same magic number only and closes them all after a fixed profit is reached, instead of closing orders initiated manually or of other EA's.
This way by alotting same magic number to a set of trades, be it different symbol, same symbol, different type, etc etc, We can Use this Close all feature based on profit to various strategies!

Can Someone explain on the code how to select net profit/loss of a number of trades having same magic number or provide a solution !

TIA
Attached File
File Type: mq4 Close All OPEN orders after SET AccountPROFIT EA.mq4   3 KB | 1 download
100 Fold Challenge->Interested? ->https://www.forexfactory.com/thread/32152
  • Post #2
  • Quote
  • Oct 4, 2009 2:24pm Oct 4, 2009 2:24pm
  •  wolfe
  • | Joined Nov 2007 | Status: Member | 43 Posts
Here are a few functions I created to deal with orders by magic number, maybe they can help you in what you are trying to accomplish.

To get the order profit by magic number:

PHP Code:
double OPBM(int intMagic)//OrderProfitByMagic
{
double dblProfit=0;
int intPOS=0;
bool boolTerm=false;
while(
boolTerm==false)
{
if(
OrderSelect(intPOS,SELECT_BY_POS))
{
if(
OrderMagicNumber()==intMagic) dblProfit=dblProfit+OrderProfit();
intPOS++;
}
else
boolTerm=true;
}
return(
dblProfit);
} 
To get the orders total by magic number:

PHP Code:
int OTBM(int intMagic)//OrdersTotalByMagic
{
int intCount=0;
int intPOS=0;
bool boolTerm=false;
while(
boolTerm==false)
{
if(
OrderSelect(intPOS,SELECT_BY_POS))
{
if(
OrderMagicNumber()==intMagic) intCount++;
intPOS++;
}
else
boolTerm=true;
}
return(
intCount);
} 
To close all orders with specific magic number:

PHP Code:
int CBM(int intMagic)//CloseByMagic
{
int intOffset=0;
int Count = OTBM(intMagic);

while(
OTBM(intMagic)>0 && Count > 0)
{
OrderSelect(intOffset,SELECT_BY_POS);
if(
OrderMagicNumber()==intMagic)
{
if(
OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);
else if(
OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);
Count--;
}
else {
intOffset++;
}
}
return(
0);
} 
Hope this may help.
 
1
  • Post #3
  • Quote
  • Oct 4, 2009 5:03pm Oct 4, 2009 5:03pm
  •  forexsaint
  • Joined Jun 2009 | Status: <-That's how u gonna b, in the END! | 1,508 Posts
Thanks Wolfe for your reply. Appreciate that.

I tried using the first code in the ea, modded a bit !
I will try this when markets open.
But Can you kindly go through the code..
is it right? Most of the times i code wrong (No programming background sorry)

Regards
Attached File
File Type: mq4 CloseAllSpecificMagicNoTradesAfterSetProfit EA.mq4   3 KB | 1 download
100 Fold Challenge->Interested? ->https://www.forexfactory.com/thread/32152
 
 
  • Post #4
  • Quote
  • Oct 4, 2009 8:21pm Oct 4, 2009 8:21pm
  •  wolfe
  • | Joined Nov 2007 | Status: Member | 43 Posts
I took a look at your code. I noticed you have no order entry in the EA. You first need to have order(s) opened with the magic number you want to track .

I'll try to provide an example for you, when I get a little more time.
 
 
  • Post #5
  • Quote
  • Edited at 10:02pm Oct 4, 2009 9:40pm | Edited at 10:02pm
  •  forexsaint
  • Joined Jun 2009 | Status: <-That's how u gonna b, in the END! | 1,508 Posts
Quoting wolfe
Disliked
I took a look at your code. I noticed you have no order entry in the EA. You first need to have order(s) opened with the magic number you want to track .

I'll try to provide an example for you, when I get a little more time.
Ignored
Thas fine... ! i want to use this as standalone ea which will closes orders only, based on magic numbers .
For opening orders we have trading EA's to do that or even order opening (with Magic no)scripts
Its just a kind of surveillance ea which is required to be always working on a chart and close them a soon as that profit target is reached!

I see you mean otherwise code is fine... is it?
Regards
100 Fold Challenge->Interested? ->https://www.forexfactory.com/thread/32152
 
 
  • Post #6
  • Quote
  • Oct 4, 2009 11:35pm Oct 4, 2009 11:35pm
  •  forexsaint
  • Joined Jun 2009 | Status: <-That's how u gonna b, in the END! | 1,508 Posts
I just checked.. It seems to be working as required.

I think i wanted to ask...
1) I see that that the comment "CurrentProfit Magic No Based trades" which references the dblProfit variable from code on chart is big not that quick to update... Can we make it bit quick...though not that important.
2) when we have 2 comment functions within the code, and both get executed..does that mean comments willoverlap on chart on top left?
3) Is there a way to show comments on other regions of chart say top right?

Thanks
100 Fold Challenge->Interested? ->https://www.forexfactory.com/thread/32152
 
 
  • Post #7
  • Quote
  • Nov 21, 2016 10:02am Nov 21, 2016 10:02am
  •  djatomic
  • | Joined Jan 2013 | Status: Member | 25 Posts
Quoting forexsaint
Disliked
Thanks Wolfe for your reply. Appreciate that. I tried using the first code in the ea, modded a bit ! I will try this when markets open. But Can you kindly go through the code.. is it right? Most of the times i code wrong (No programming background sorry) Regards {file}
Ignored
Hi, I'm reading now this thread and I find useful this EA.
Can you add the possibility to consider the Swap and the Commission?
 
 
  • Post #8
  • Quote
  • Dec 25, 2016 8:33am Dec 25, 2016 8:33am
  •  atanasxx
  • | Joined Dec 2016 | Status: Member | 23 Posts
i need indicator by use that i can close all trades of one pairs.
 
 
  • Post #9
  • Quote
  • Feb 21, 2017 12:37pm Feb 21, 2017 12:37pm
  •  akash14
  • Joined Aug 2009 | Status: Member | 189 Posts
Quoting forexsaint
Disliked
Thanks Wolfe for your reply. Appreciate that. I tried using the first code in the ea, modded a bit ! I will try this when markets open. But Can you kindly go through the code.. is it right? Most of the times i code wrong (No programming background sorry) Regards {file}
Ignored
I used your EA and it dsnt work with magic number for closing them.

Can somebody please share any EA which close trades based on EA magicnumber and profit?
Believe in your thesis and stick to the plan, don't get scared with moves
 
 
  • Post #10
  • Quote
  • Feb 21, 2018 4:05am Feb 21, 2018 4:05am
  •  candyman752
  • Joined Mar 2013 | Status: Member | 1,724 Posts
ere we are
Attached File
File Type: mq4 Equity Stop Loss Trailer With Magic Number.mq4   28 KB | 280 downloads
 
 
  • Post #11
  • Quote
  • Feb 22, 2018 6:54am Feb 22, 2018 6:54am
  •  candyman752
  • Joined Mar 2013 | Status: Member | 1,724 Posts
better
Attached File
File Type: mq4 Equity Stop Loss Trailer With Magic Number_V2.2.mq4   25 KB | 504 downloads
 
 
  • Post #12
  • Quote
  • Apr 12, 2018 10:10am Apr 12, 2018 10:10am
  •  FranzelPure
  • | Joined May 2016 | Status: Member | 5 Posts
I am busy with this EA. I have gotten the EA working correctly on focusing on one magic number.
what do I need to add so the EA focuses on 2 magic numbers, but focuses on them separately?

Example

EA take profit = $5.0

magic number 1 = $2.5
magic number 2 = $5.0

EA closes magic number 2

EA does not close magic number 1 until Take profit has been reached of $5.0

Here is the coding I have for magic number 1
How do I add magic number 2?

double Profit(){
double Prof=0;
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if( OrderMagicNumber()== magic_number1 ){
Attached File
File Type: mq4 Profit taker_magic_5 levels.mq4   4 KB | 508 downloads
 
 
  • Post #13
  • Quote
  • Apr 13, 2019 10:22am Apr 13, 2019 10:22am
  •  Shakka
  • | Joined Jun 2017 | Status: Superior | 152 Posts
Quoting forexsaint
Disliked
Hello Attached is a ea which constantly tracks the Floating Accountprofit function to track of a fixed profit entered in settings of the ea, to close all orders as soon as it is reached. There is also one around which is based on Symbols. But i think it will be lot better if we have one which tracks/summarizes the net profit and loss of Orders with same magic number only and closes them all after a fixed profit is reached, instead of closing orders initiated manually or of other EA's. This way by alotting same magic number to a set of trades, be...
Ignored
If someone had already try this before, kindly help me answer my question..
Close all orders is based on pips target or money target ?
Thanks
Gambling = 0% skill, 100% luck. Trading = 1% skill, 99% luck.
USA INDEX - two {continuation} All Time Return: 6.7%
 
 
  • Post #14
  • Quote
  • Apr 15, 2019 12:41am Apr 15, 2019 12:41am
  •  Shakka
  • | Joined Jun 2017 | Status: Superior | 152 Posts
Quoting Shakka
Disliked
{quote} If someone had already try this before, kindly help me answer my question.. Close all orders is based on pips target or money target ? Thanks
Ignored
Any response ?
Gambling = 0% skill, 100% luck. Trading = 1% skill, 99% luck.
USA INDEX - two {continuation} All Time Return: 6.7%
 
 
  • Post #15
  • Quote
  • Last Post: Feb 26, 2022 8:49pm Feb 26, 2022 8:49pm
  •  Deidra007
  • | Joined Feb 2022 | Status: Junior Member | 1 Post
Wow I like this. I know that there are Scripts that are able to close all trades by simply dragging and dropping it on the chart. However, I would like an EA that would be able to close all trades except one, two, or any amount of trades that I indicate to the EA by selecting trades that I don’t want to be closed if I should drag a close all script onto the charts. Does anything like this exist? How much would it cost to create one if it doesn’t exist?


Quoting wolfe
Disliked
Here are a few functions I created to deal with orders by magic number, maybe they can help you in what you are trying to accomplish. To get the order profit by magic number: double OPBM(int intMagic)//OrderProfitByMagic { double dblProfit=0; int intPOS=0; bool boolTerm=false; while(boolTerm==false) { if(OrderSelect(intPOS,SELECT_BY_POS)) { if(OrderMagicNumber()==intMagic) dblProfit=dblProfit+OrderProfit(); intPOS++; } else boolTerm=true; } return(dblProfit); }To get the orders total by magic number: int OTBM(int intMagic)//OrdersTotalByMagic {...
Ignored
 
 
  • Platform Tech
  • /
  • Close all trades, Based on Magic Number Modification
  • 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