| 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 |
|
|||
|
Buy and sell on the 100's
Zamanib,
I understand what you wrote, but I don't see how you close at a profit. This looks to me like a Hedge type EA. There are several of those in forex-tsd, and you don't have to Martingale. Big Be |
|
|||
|
Quote:
please direct me to the hedge ea . I see lot of it . but not what excatly what i want. |
|
||||
|
code or platform problem?
Quote:
Thanks for replying. For some reason my code doesnt work: if (OrderSelect(orderNo, SELECT_BY_TICKET)==true) { if (OrderType() == OP_BUY && Close[0] >= OrderTakeProfit()) CloseOrder(orderNo); if (OrderType() == OP_SELL && Close[0] <= OrderTakeProfit()) CloseOrder(orderNo); } I would be grateful for advice. euro |
|
||||
|
Quote:
When your EA runs, the "bid" price is also available as the variable named "Bid" and the "ask" price as the variable named "Ask". So the code snippet would be better looking like: PHP Code:
|
|
|||
|
Please help in code, thanks...
Hi,
I have new in writing EA, I was trying the following but got an error of "Invalid ticket for OrderModify function", Can someone please kindly have a look and help? Thanking in advance. void ModifyHedgeSL(int SL) { if (SL<1) return; bool bres; double sl,openadj; if (lastopenbuy==1 && lastopensell==0) {openadj=Ask-Bid;} else {openadj=0;} for (int i = 0; i < OrdersTotal(); i++) { OrderSelect (i, SELECT_BY_POS,MODE_TRADES); if ( OrderSymbol() == Symbol() || OrderMagicNumber() == expertId && OrderType() == OP_BUY ) { sl = GetLastLongOpenPrice()-openadj-SL*Point; bres = OrderModify (OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, White); if (bres) Print("Modifing Hedge BUY completed"); if (!bres) Print("Error Modifying Hedge BUY order : ",ErrorDescription(GetLastError())); } if ( OrderSymbol() == Symbol() || OrderMagicNumber() == expertId && OrderType() == OP_SELL ) { sl = GetLastShortOpenPrice()-openadj+SL*Point; bres = OrderModify (OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0, Gold); if (bres) Print("Modifing Hedge SELL completed"); if (!bres) Print("Error Modifying Hedge SELL order : ",ErrorDescription(GetLastError())); } } return; } double GetLastLongOpenPrice() { int ord; double LastLongOpenPrice=0; //---- for (int i = 0; i <= OrdersTotal(); i++) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber()==expertId && OrderType() == OP_BUY) { LastLongOpenPrice=OrderOpenPrice(); } } if (LastLongOpenPrice>0) {return(LastLongOpenPrice);} else {return(-1);} } |
|
||||
|
How to code buy/sell orders when SL is hit
For example, if I buy 1 lot of EUR/JPY at 164.30 and Sl at 164.00.
if SL is hit, then I'll place another buy order at the same price, 164.30, with the same SL at 164, and with more lots, say 1.5. Then if SL is hit again, another buy order will be placed to buy 2 lots at the same price with the same SL. Is there any code for this?? Thanks! |
|
|||
|
Quote:
I think it is what you need or you can use it as an example. |
|
||||
|
ok
Quote:
|
|
||||
|
TP issue
PHP Code:
as you can see I call a separate function CloseOrder() where i had used 'Ask' and 'Bid' as you recommend but the problem still exist. // Function CloseOrder ************************************************** ******** bool CloseOrder(int orderT) { double sA; if (OrderSelect(orderT, SELECT_BY_TICKET)==true) { if (OrderType() == OP_BUY) sA = Bid; else sA = Ask; bool bClosed = OrderClose(orderT,OrderLots(),sA,0,CLR_NONE); if (bClosed == 1) { pTrades = 0; return(1); } else return(0); }} ************************************************** ******** I was hoping it will quarantee that the trade will be closed once TP is hit, but that is not the case, see chart attached, where the short order was opened at 104.03 with TP at 103.79. Althouth the price hit it (TP) the order wasn't closed. |
![]() |
| Bookmarks |
| Tags |
| candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading |
| Thread Tools | |
| Display Modes | |
|
|
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 |