| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack (1) | Thread Tools | Display Modes |
|
|||
|
Closing Multiple Position By Magic Number - Help
hello all.
I'm new in mt4 programming and below are my very first EA. The purpose of this EA is to close all position regardless any currency pair based on the same magic number. Let say under magic # 8675310, i got 2 position EURUSD & USDCFh. It shall be able to close all these pair when it reaches certain profit target. The problem with this EA is, Open Transaction # 1 EURUSD (able to close) Open Transaction # 2 USDCFh (won't be able to close) IT WON'T BE ABLE TO CLOSE TRANSACTION # 2. Any Ideas ? Thanks //+------------------------------------------------------------------+ //| Closing_Trade_By_Magic_No_v1 .mq4 | //| Mine | //| Forex Trading Software: Forex Trading Platform MetaTrader 4 | //+------------------------------------------------------------------+ #property copyright "Mine" #property link "http://www.metaquotes.net" //---- input parameters extern int MagicNumber1=8675310; extern int Profit1=10; extern int MagicNumber2=8675311; extern int Profit2=15; extern int MagicNumber3=8675312; extern int Profit3=15; extern int MagicNumber4=8675313; extern int Profit4=15; extern int MagicNumber5=8675314; extern int Profit5=15; extern int MagicNumber6=0; extern int Profit6=10; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { onScreenComment(98,"Tengak Initialize.."); //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { string myMessage=""; myMessage = myMessage + ProfitLossMonitor(1,MagicNumber1,Pr ofit1,myMessage); myMessage = myMessage + ProfitLossMonitor(2,MagicNumber2,Pr ofit2,myMessage); myMessage = myMessage + ProfitLossMonitor(3,MagicNumber3,Pr ofit3,myMessage); myMessage = myMessage + ProfitLossMonitor(4,MagicNumber4,Pr ofit4,myMessage); myMessage = myMessage + ProfitLossMonitor(5,MagicNumber5,Pr ofit5,myMessage); myMessage = myMessage + ProfitLossMonitor(6,MagicNumber6,Pr ofit6,myMessage); onScreenComment(98,myMessage); //---- //---- return(0); } string ProfitLossMonitor(int myGroupNumber,int myMagicNumber, int myProfit,string myMessage ) { int total = OrdersTotal(); double MyCurrentProfit=0; string MyOrderNo=""; for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_ TRADES); if (OrderMagicNumber() == myMagicNumber) { MyCurrentProfit += OrderProfit(); MyOrderNo= MyOrderNo + "," + OrderTicket(); } } if(MyCurrentProfit>=myProfit) CloseAll(myMagicNumber); myMessage="Group Position #" + myGroupNumber + " " + myMagicNumber + "=" + myProfit + "(" + DoubleToStr(MyCurrentProfit,2) + " " + MyOrderNo + ")" + "\n" ; return (myMessage); } void CloseAll(int myMagicNumber) { int total = OrdersTotal(); for (int cnt = 0 ; cnt < total ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_ TRADES); if (OrderMagicNumber() == myMagicNumber) if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots( ),Bid,5,Violet); if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots( ),Ask,5,Violet); } } void onScreenComment(int myEvent, string myComment) { switch (myEvent) { case 98: Comment(myComment); break; } } //+------------------------------------------------------------------+ Edit/Delete Message ![]() |
|
|||
|
how to not trade till the next bar
I've tried programming for the first time, but have one issue.
- if I close a trade in a bar, I can only open a new trade when the new bar opens. I have tried the following; datetime time0=0; int start() if (time0 == Time[0]) return; { "program code" } time0 = Time[0]; return(0); If I take this bit out I get multiple entries in various bar. With it in, I get far fewer entries (from 70 in a backtest. to 4), but with missing entries. Anyone know what I'm doing wrong. Thanks in advance. |
|
|||
|
You can use the NewBar() function below..
Like if(NewBar(){ ........programming here Code:
bool NewBar() {
static datetime LastTime = 0;
if (Time[0] != LastTime) {
LastTime = Time[0];
return (true);
} else
return (false);
}
Hope that helps. Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV ![]() ForexArea.com Users of Gap Trader from 'Forex-Assistant' MUST Read This |
|
|||
|
Lux
Thanks for your help with this. I think I've figured out what was going on on the program. I was previously checking for a new bar at the start, so the program just checked the first tick of the new bar to see if it agreed with my signals, without checking the other ticks. This is why do few trade signals came through the backtest. I have now placed the code correctly, (ie. where my ordersend instuction is) it seems to be working ok. Am I correct in my thinking? |
|
|||
|
Please help to update the code of expert.
There is a simple expert. Code is clear and simple too, but i have a big problem - expert got only ONE try to Open/Close order.
Can somebody help to fix it? Expert must try 5-10 times to open/close order. Maybe n=number of try, and please without "while". Thanks a lot. |
|
|||
|
My code for 'adjust lots after loss',need help..thanks
My code below for 'adjust lots after loss', but it did an error massage "incorrect start position 0 for ArraySort function" during Testing. Anyone can help me to fix it? need help..
PHP Code:
Last edited by tommy0418; 10-16-2008 at 12:45 AM. |
|
|||
|
how do you use Fractal?
lets say i only want the fractal up? i am confuse.. is fractal up mode upper? and also about the shift? below is the code i place to check the newest fractal up iFractals (Symbol (), PERIOD_H1, MODE_UPPER, 1); is this correct? or should i put 0 in the shift? |
|
|||
|
0 shift is the current bar that is still forming, 1 is the previous bar that has already closed. It depends which one you want.
Good luck Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV ![]() ForexArea.com Users of Gap Trader from 'Forex-Assistant' MUST Read This |
![]() |
| Bookmarks |
| Tags |
| candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
|
||||
| Posted By | For | Type | Date | |
| Need an experienced programmer? - Page 2 | Post #0 | Refback | 09-24-2008 07:24 AM | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to code this? | iscuba11 | Metatrader 4 mql 4 - Development course | 1 | 08-03-2007 05:22 PM |