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: 24519, member: 13610"] Hi Enivid, I made some changes to the EA, its giving me the correct stop loss only that if price reverses then the stop reverses. Do you know the logic of telling the EA that the highest profit has been reached? I am thinking of adding a line at each level: {if(OrderStopLoss() < OrderOpenPrice()+trailing_stop_level4) This will help the trailing stop stay at level 4 from level 3. But not sure that this won't be just accepted and then if the function below is true the stop will move back down. Also if I put this EA on different currency pairs - I get the Stop loss as appearing for the different currency pairs this is on. I think this is a magic number issue - would that be right? Thanks [code=mql4]//+------------------------------------------------------------------+ //| BlueprintV1.8.mq4 | //| Not working| //| [email]cam_tong@hotmail.com[/email] | //+------------------------------------------------------------------+ #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 = 0; //+------------------------------------------------------------------+ //| 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))) { OrderModify (OrderTicket(), OrderOpenPrice(),OrderOpenPrice()+ trailing_stop_level1 * PointValue, OrderTakeProfit(), Red); } } { if (((SecTrailingStop> 0) && (Bid - OrderOpenPrice() >= TSTP2) && (Bid - OrderOpenPrice() <TSTP3))) { OrderModify (OrderTicket(), OrderOpenPrice(),OrderOpenPrice() + trailing_stop_level2 * PointValue, OrderTakeProfit(), Red); } } { if (((ThirdTrailingStop > 0) && (Bid - OrderOpenPrice() >= TSTP3)&& (Bid - OrderOpenPrice() <TSTP4))) { OrderModify (OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+trailing_stop_level3 * PointValue, OrderTakeProfit(), Red); } } {if ((( FourthTrailingStop > 0) && (Bid - OrderOpenPrice() >= TSTP4)&& (Bid - OrderOpenPrice() <TSTP5))) {if(OrderStopLoss() < OrderOpenPrice()+trailing_stop_level4) { OrderModify (OrderTicket(), OrderOpenPrice(),OrderOpenPrice()+trailing_stop_level4 * PointValue, OrderTakeProfit(), Red); } } } {if (( FifthTrailingStop > 0) && (Bid - OrderOpenPrice() >= TSTP5) && (Bid - OrderOpenPrice() < Trail_From)) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + trailing_stop_level5 * PointValue, OrderTakeProfit(), Red); } } My_Profit = MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice(); My_Trail = MathMin(My_Profit * TrailPercent/100,Digits); { if (Bid - OrderOpenPrice() > TSTP5) { if(OrderStopLoss()< Bid - My_Trail * PointValue) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid - My_Trail*PointValue,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))) {OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-trailing_stop_level1 * PointValue, OrderTakeProfit(), Red); } } { if ((( SecTrailingStop > 0) && (OrderOpenPrice() - Ask >= TSTP2) && (OrderOpenPrice() - Ask < TSTP3))) {OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()- trailing_stop_level2 * PointValue, OrderTakeProfit(), Red); } } { if (((ThirdTrailingStop > 0) && (OrderOpenPrice() - Ask >= TSTP3) && (OrderOpenPrice() - Ask < TSTP4))) {OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-trailing_stop_level3 * PointValue, OrderTakeProfit(), Red); } } { if (((FourthTrailingStop > 0) && (OrderOpenPrice() - Ask >= TSTP4) && (OrderOpenPrice() - Ask < TSTP5))) {OrderModify(OrderTicket(), OrderOpenPrice(),OrderOpenPrice() - trailing_stop_level4 * PointValue , OrderTakeProfit(), Red); } } {if (( FifthTrailingStop > 0) && (OrderOpenPrice() - Ask >= TSTP5) && (OrderOpenPrice() - Ask < Trail_From)) {OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - trailing_stop_level5 * PointValue, OrderTakeProfit(), Red); } } My_Profit = OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_ASK); My_Trail = MathMin(My_Profit * TrailPercent/100,Digits); {if((OrderOpenPrice()-Ask)> TSTP5) {if((OrderStopLoss()>(Ask+My_Trail*PointValue)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+My_Trail*PointValue,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…