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
myRandom
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="competent123, post: 40904, member: 21910"] [code=mql4] extern double Lots = 0.1; extern double Slippage = 3; extern int RandomEntryPeriod = 80; //In bars. How many bars to wait before entering a new position. extern int StopLoss = 90; extern int TakeProfit = 600; extern int MaxPositions = 4; extern int TrailingStop = 20; extern bool ECN_Mode = false; // In ECN mode, SL and TP aren't applied on OrderSend() but are added later with OrderModify() extern color clOpenBuy = Blue; extern color clOpenSell = Red; int Magic; int LastBars = 0; int OrderTaken = 0; double Poin; int Deviation; int init() { //Checking for unconvetional Point digits number if ((Point == 0.00001) || (Point == 0.001)) { Poin = Point * 10; Deviation = Slippage * 10; } else { Poin = Point; //Normal Deviation = Slippage; } Magic = Period()+1339005; return(0); } //+------------------------------------------------------------------+ //| Random entry expert advisor | //+------------------------------------------------------------------+ int start() { if (ECN_Mode) { DoTrailing(); DoSLTP(); } if (LastBars == Bars) return(0); else LastBars = Bars; if (AccountFreeMargin() < (Lots*2*1000)) return(0); if (Lots < 0.1) return(0); MathSrand(TimeLocal()); int count = 0; int total = OrdersTotal(); for (int pos = 0; pos < total; pos++) { if (OrderSelect(pos, SELECT_BY_POS) == false) continue; if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) count++; } if (count >= MaxPositions) return(0); if (Bars >= OrderTaken + RandomEntryPeriod) { if ((MathRand()%2) == 1) { fSell(); } else { fBuy(); } OrderTaken = Bars; } } //+------------------------------------------------------------------+ //| Buy | //+------------------------------------------------------------------+ void fBuy() { double SL = 0, TP = 0; RefreshRates(); if (!ECN_Mode) { if (StopLoss > 0) SL = Ask - StopLoss * Poin; if (TakeProfit > 0) TP = Ask + TakeProfit * Poin; } int result = OrderSend(Symbol(), OP_BUY, Lots, Ask, Deviation, SL, TP, "myRandom", Magic, 0, clOpenBuy); if (result == -1) { int e = GetLastError(); Print("OrderSend Error: ", e); } } //+------------------------------------------------------------------+ //| Sell | //+------------------------------------------------------------------+ void fSell() { double SL = 0, TP = 0; RefreshRates(); if (!ECN_Mode) { if (StopLoss > 0) SL = Bid + StopLoss * Poin; if (TakeProfit > 0) TP = Bid - TakeProfit * Poin; } int result = OrderSend(Symbol(), OP_SELL, Lots, Bid, Deviation, SL, TP, "myRandom", Magic, 0, clOpenSell); if (result == -1) { int e = GetLastError(); Print("OrderSend Error: ", e); } } //+------------------------------------------------------------------+ //| Applies SL and TP to open positions if ECN mode is on. | //+------------------------------------------------------------------+ void DoSLTP() { double SL = 0, TP = 0; for (int i = 0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) { RefreshRates(); if (OrderType() == OP_BUY) { if (StopLoss > 0) SL = NormalizeDouble(Ask - StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(Ask + TakeProfit * Poin, Digits); if ((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) if ((SL > OrderStopLoss()) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0); } } else if (OrderType() == OP_SELL) { if (StopLoss > 0) SL = NormalizeDouble(Bid + StopLoss * Poin, Digits); if (TakeProfit > 0) TP = NormalizeDouble(Bid - TakeProfit * Poin, Digits); if ((OrderStopLoss() != SL) || (OrderTakeProfit() != TP)) if ((SL < OrderStopLoss()) || (OrderStopLoss() == 0)) { OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0); } } } } } void DoTrailing() { int total = OrdersTotal(); for (int pos = 0; pos < total; pos++) { if (OrderSelect(pos, SELECT_BY_POS) == false) continue; if ((OrderMagicNumber() == Magic) && (OrderSymbol() == Symbol())) { if (OrderType() == OP_BUY) { RefreshRates(); if (Bid - OrderOpenPrice() >= TrailingStop * Poin) //If profit is greater or equal to the desired Trailing Stop value { if (OrderStopLoss() < (Bid - TrailingStop * Poin)) //If the current stop-loss is below the desired trailing stop level OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop * Poin, OrderTakeProfit(), 0); } } else if (OrderType() == OP_SELL) { RefreshRates(); if (OrderOpenPrice() - Ask >= TrailingStop * Poin) //If profit is greater or equal to the desired Trailing Stop value { if ((OrderStopLoss() > (Ask + TrailingStop * Poin)) || (OrderStopLoss() == 0)) //If the current stop-loss is below the desired trailing stop level OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop * Poin, OrderTakeProfit(), 0); } } } } } [/code] i am so sorry for posting again, i have spun my head for many days now, with 0 success.! i tried as you said, with that other EA you referred to. it didnt work ( i mentioned i am NOT a programmer, a copy paster, at best) in this code BOTH stop loss and take profit move. it gives no error with mt editor. if you would be kind enough to modify it so that tp does not move, only sl moves. i am using MRCmarkets.com broker , it gives order 130 error if i don't use ecn mode. Thank you so much in advance. [/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…