Menu
Brokers
MT4 Forex Brokers
MT5 Forex brokers
PayPal Brokers
Skrill Brokers
Oil Trading Brokers
Gold Trading Brokers
Web Browser Platform
Brokers with CFD Trading
ECN Brokers
Bitcoin FX Brokers
PAMM Forex Brokers
With Cent Accounts
With High Leverage
Cryptocurrency Brokers
Forums
All threads
New threads
New posts
Trending
Search forums
What's new
New threads
New posts
Latest activity
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Reply to thread
Forums
Trading Platforms
MetaTrader Expert Advisors
Open candel EA + TS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
[QUOTE="MRT, post: 207638, member: 84584"] Hello Forum! I'm trying to code a very simple EA which opens a trade when the new / next candle occurs + TS . Part of the code is working as I want and new trades are opening fine but TS simply doesn't work. I was wondering if somebody would be so kind and help me fixing this code ? [CODE] #property strict input double lot = 0.07; // lot input int slippage = 10; // max slippage input int TP=1000; // Take Profiti input int SL=55; // Stop Loss input int MagicNumber=100; // Magic Number extern bool ProfitTrailing = True; extern int TrailingStop = 20; extern int TrailingStep = 10; extern bool UseSound = True; extern string NameFileSound = "expert.wav"; //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ void start() { for (int i=0; i<OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { TrailingPositions(); } } } //+------------------------------------------------------------------+ //|sssssssssssssssssssssss | //+------------------------------------------------------------------+ void TrailingPositions() { double pBid, pAsk, pp; pp = MarketInfo(OrderSymbol(), MODE_POINT); if (OrderType()==OP_BUY) { pBid = MarketInfo(OrderSymbol(), MODE_BID); if (!ProfitTrailing || (pBid-OrderOpenPrice())>TrailingStop*pp) { if (OrderStopLoss()<pBid-(TrailingStop+TrailingStep-1)*pp) { ModifyStopLoss(pBid-TrailingStop*pp); return; } } } if (OrderType()==OP_SELL) { pAsk = MarketInfo(OrderSymbol(), MODE_ASK); if (!ProfitTrailing || OrderOpenPrice()-pAsk>TrailingStop*pp) { if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) { ModifyStopLoss(pAsk+TrailingStop*pp); return; } } } } //+------------------------------------------------------------------+ //| | //| : | //| StopLoss | //+------------------------------------------------------------------+ void ModifyStopLoss(double ldStopLoss) { bool fm; fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE); if (fm && UseSound) PlaySound(NameFileSound); } datetime tlast; int OnInit() { tlast = INT_MAX; return INIT_SUCCEEDED; } void OnTick() { if(Time[0] > tlast) { if(Open[1] >= Close[1]) bool res = OrderSend(Symbol(),OP_SELL,lot,Bid,slippage,Bid+SL*Point,Bid-TP*Point,NULL,MagicNumber,0); else if(Open[1] <= Close[1]) bool res = OrderSend(Symbol(),OP_SELL,lot,Bid,slippage,Bid+SL*Point,Bid-TP*Point,NULL,MagicNumber,0); } tlast = Time[0]; } [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Top
Bottom
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…