Hello guys, I have a problem..
According to the logic, regarding the position ticketTL, the ea should move the trailingstop up. Instead, it remains a fixed stoploss. No errors in the journal.
- Close part of Trade and Trailingstop
- What is wrong with this logic? Trailingstop for half position
- Adding TrailingStop to My EA
ticket=OrderSend(Symbol(),OP_BUY,Lotti/2,prezzo,3,StopLoss,prezzo+Atr,"Momentum Method",MagicNumber,0); OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES); if (ordtot>=1) { if(OrderTicket()==ticket) { if (prezzo>(OrderOpenPrice()+Spread)) { OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+Spread,OrderTakeProfit(),0,Green); } } }
Did this fail ???
You open the trade and directly you trie to get no loss this always fails
,OP_BUY,Lotti/2,prezzo,3
You can't just divide by 2. The amount must be a multiple of lotstep and at least minlot. See my reply to your other question.- What is prezzo, you can ONLY open a buy at the ASK.
- EA's must adjust for 4/5 digit brokers, tp, sl, AND slippage. On ECN brokers you must open first and then set stops.
- Always test your return codes
//++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.015 0.0150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits % 2 == 1){ // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345 pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl //---- These are adjusted for 5 digit brokers. /* On ECN brokers you must open first and THEN set stops int ticket = OrderSend(..., 0,0,...) if (ticket < 0) Alert("OrderSend failed: ", GetLastError()); else if (!OrderSelect(ticket, SELECT_BY_TICKET)) Alert("OrderSelect failed: ", GetLastError()); else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0) Alert("OrderModify failed: ", GetLastError()); */
- if the ordersend worked AND the orderSelect worked, when would this not be true?
if(OrderTicket()==ticket)
OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice()+Spread,OrderTakeProfit(),0,Green);
You opened at the ASK. Now the market is at the Bid (BELOW the orderOpenPrice.) Do you really expect to be able to set a stop ABOVE market (at the Bid + 2*spread)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register