|
|||||||
| 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 |
|
|||
|
Take Profit, cancel all other orders
Hi,
Situation: 1. For GBPUSD 2. Place one buy stop and one sell stop. 3. When buy stop is triggered and hit "TakeProfit" level, opened buy position will be closed and pending sell stop order will be deleted. Vice versa for when sell stop is triggered. 4. When buy stop is triggered and hit "Stoploss" level, opened buy position will be closed but pending sell stop order remain open. Vice versa for when sell stop is triggered. My code: // Trade Order EntryLong = RangeHigh + (Pip_Filter + MarketInfo(Symbol(),MODE_SPREAD))*Point; EntryShort = RangeLow - Pip_Filter*Point; if(TimeCurrent() == Start_Trade) { if(Bought == false && ActiveSession == true && SmallSession == true) { OrderSend(Symbol(),OP_BUYSTOP,Lots,EntryLong,Slipp age,(EntryLong-(Stoploss*Point)),0,Order_id,Magic_Number,0,Blue); } if(Sold == false && ActiveSession == true && SmallSession == true) { OrderSend(Symbol(),OP_SELLSTOP,Lots,EntryShort,Sli ppage,(EntryShort+(Stoploss*Point)),0,Order_id,Mag ic_Number,0,Red); } } // Close open order and cancel opposite pending order if profit target reached int i; for(i=OrdersTotal();i>=0;i--) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if((OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic_Number)) { if((OrderProfit() >= TakeProfit*Point)) { switch(OrderType()) { case OP_BUY: OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_BID),5,Red); break; //Close opened long positions case OP_SELL: OrderClose(OrderTicket(),OrderLots(),MarketInfo(Or derSymbol(),MODE_ASK),5,Red); break; //Close opened short positions case OP_BUYSTOP: case OP_SELLSTOP: OrderDelete(OrderTicket()); //Close pending orders } } } } Problem: 1. The open pending order did not cancel when hit "TakeProfit" level. 2. Open buy/sell positions closed at 1-3 pips profit instead of the 40pips set by "TakeProfit". Questions: 1. Can anyone help to amend or write the code? 2. How can I put the takeprofit into the OrderSend() and still achieve the desired outcome? |
|
|||
|
why some trades are entered, some not?
Hi,
While looking through the results generated by my EA, I found that I face the following issues: 1. All orders (open and pending) are supposed to close by 1800hr UK time. However one or two of the pending orders was closed before 1800hrs while the rest have no problem. 2. Buystop and Sellstop are placed when certain conditions are fulfilled. Though in some of the days these conditions are fully fulfilled, buystop and sellstop are not placed. Majority of the days have no problem running according to the conditions. Does anyone know what are the problems? Could it be due to only 90% modelling quality? or some coding problems? |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/10542-take-profit-cancel-all-other-orders.html
|
|||
| Posted By | For | Type | Date |
| Take Profit, cancel all other orders | Stop Collection Agency Scams | This thread | Pingback | 11-04-2007 10:12 AM |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OCO - one cancel another script | newt | Indicators - Metatrader 4 | 7 | 06-04-2007 11:49 AM |
| modify orders and close pending orders | bkgridley | Questions | 8 | 05-23-2007 09:49 PM |
| Breakout-System - Cancel Order | justize | Expert Advisors - Metatrader 4 | 3 | 03-10-2007 06:35 PM |