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
Percentage Trail Stop
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="Colonel Sponsz, post: 24186, member: 13610"] I couldn't get this out. I have no errors but the programming is clearly wrong as no stop loss is appearing in mt4 on the trades. I couldn't really find any clear programming examples to use either. Most of the trailing stop EAs on the net don't work. I have to research that mode stop level indication you gave. [code=mql4]/+------------------------------------------------------------------+ #property copyright "not working" #property link "notworking@hotmail.com" extern double InitialTrailingStop = 10; extern double trailing_stop_level1 = 3; extern double SecTrailingStop = 20; extern double trailing_stop_level2 = 8; extern double ThirdTrailingStop = 30; extern double trailing_stop_level3 = 15; extern double FourthTrailingStop = 40; extern double trailing_stop_level4 = 24; extern double FifthTrailingStop = 60; extern double trailing_stop_level5 = 42; extern double TrailPercent = 70; extern double Trail_From = 61.0; // Set it to some value above 0 to activate stop-loss extern double StopLoss = 40; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() {double PointValue; for (int i = 0; i < OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //Calculate the point value in case there are extra digits in the quotes if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.00001) PointValue = 0.0001; else if (MarketInfo(OrderSymbol(), MODE_POINT) == 0.001) PointValue = 0.01; else PointValue = MarketInfo(OrderSymbol(), MODE_POINT); //Normalize trailing stop value to the point value double TSTP = InitialTrailingStop * PointValue; double TSTP2 = SecTrailingStop * PointValue; double TSTP3 = ThirdTrailingStop * PointValue; double TSTP4 = FourthTrailingStop * PointValue; double TSTP5 = FifthTrailingStop * PointValue; double Trail_From = Trail_From * PointValue; double sl = OrderStopLoss(); double My_Profit; double My_Trail; double My_SL; if (OrderType() == OP_BUY) { if (((InitialTrailingStop> 0) && (Bid - OrderOpenPrice() >= TSTP) && (Bid - OrderOpenPrice() < TSTP2))) sl = (trailing_stop_level1 * PointValue); { OrderModify(OrderTicket(), OrderOpenPrice(),sl, OrderTakeProfit(), Red); } } { if (((SecTrailingStop> 0) && (Bid - OrderOpenPrice() >= TSTP2) && (Bid - OrderOpenPrice() <TSTP3))) sl = (trailing_stop_level2 * PointValue); { OrderModify(OrderTicket(), OrderOpenPrice(),sl, OrderTakeProfit(), Red); } } { if (((ThirdTrailingStop > 0) && (Bid - OrderOpenPrice() >= TSTP3)&& (Bid - OrderOpenPrice() <TSTP4))) sl = (trailing_stop_level3 * PointValue); { OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), Red); } } {if ((( FourthTrailingStop > 0) && (Bid - OrderOpenPrice() >= TSTP4)&& (Bid - OrderOpenPrice() <TSTP5))) sl = (trailing_stop_level4 * PointValue); { OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), Red); } } {if (( FifthTrailingStop > 0) && (Bid - OrderOpenPrice() >= TSTP5)) sl = (trailing_stop_level5*PointValue); { OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), Red); } } My_Profit = MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice(); My_Trail = MathMin(My_Profit * TrailPercent/100,Digits); My_SL = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID)-My_Trail,Digits); { if (My_Profit > Trail_From) OrderModify(OrderTicket(),OrderOpenPrice(),My_SL,OrderTakeProfit(),0, Red); } } if ((OrderStopLoss() != Bid - StopLoss * PointValue) && (StopLoss != 0)) OrderModify(OrderTicket(), OrderOpenPrice(), Bid - StopLoss * PointValue, OrderTakeProfit(), Red); if (OrderType() == OP_SELL) { if (((InitialTrailingStop> 0) && (OrderOpenPrice() - Ask >= TSTP) && (OrderOpenPrice() - Ask < TSTP2))) sl = (trailing_stop_level1 * PointValue); {OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), Red); } } { if ((( SecTrailingStop > 0) && (OrderOpenPrice() - Ask >= TSTP2) && (OrderOpenPrice() - Ask < TSTP3))) sl = (trailing_stop_level1 * PointValue); {OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), Red); } } { if (((ThirdTrailingStop > 0) && (OrderOpenPrice() - Ask >= TSTP3) && (OrderOpenPrice() - Ask < TSTP4))) sl = (trailing_stop_level1 * PointValue); {OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), Red); } } { if (((FourthTrailingStop > 0) && (OrderOpenPrice() - Ask >= TSTP4) && (OrderOpenPrice() - Ask < TSTP5))) sl = (trailing_stop_level1 * PointValue); {OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), Red); } } {if (( FifthTrailingStop > 0) && (OrderOpenPrice() - Ask >= TSTP5)) sl = (trailing_stop_level5*PointValue); {OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), Red); } } My_Profit = OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_ASK); My_Trail = MathMin(My_Profit * TrailPercent/100,Digits); My_SL = NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK)+My_Trail,Digits); if (My_Profit > Trail_From) { OrderModify(OrderTicket(),OrderOpenPrice(),My_SL,OrderTakeProfit(),0,Red); } if ((OrderStopLoss() != Ask + StopLoss * PointValue) && (StopLoss != 0)) OrderModify(OrderTicket(), OrderOpenPrice(), Ask + StopLoss * PointValue, OrderTakeProfit(), Red); //---- //---- return(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…