//+------------------------------------------------------------------+ //| JFM TEND.mq4 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #include #include //input double StopLoss=50; //input double TakeProfit=50; //input double TP1=25; //input double SL1=0; double StopLoss; double TakeProfit; double TP1; double SL1; double myPoint; bool BE =false; bool First = true; input int Divisa; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int init() { switch (Divisa) { case 1: //EURUSD StopLoss=200; TakeProfit=200; TP1=100; SL1=0; break; case 2: //AUDUSD StopLoss=100; TakeProfit=100; TP1=50; SL1=0; break; case 3: //USDJPY StopLoss=200; TakeProfit=200; TP1=100; SL1=0; break; case 4: //USDCAD StopLoss=50; TakeProfit=50; TP1=25; SL1=0; default: MessageBox("Divisa errónea", "Divisa errónea", 0); break; } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { BE =false; First = true; return (0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { //--- int digits, ticket, Newticket, j, OT; double pBid, pAsk, BuyStop, BTeorico,BReal,OOP; //bool BE; myPoint = SetPoint(); digits = MarketInfo(Symbol(), MODE_DIGITS) ; for(int j=0; j= OOP + TakeProfit*Point && BE == true) { if(!OrderClose(OrderTicket(), OrderLots(), pBid, 3, Violet)) Print(GetLastError()); BE = false; First = true; } else { if((pBid >= OOP + TP1*Point) && (BE == false)) { if(!OrderClose(OrderTicket(), OrderLots()/2, pBid, 3, Violet)) Print(GetLastError()); BuyStop = OOP; BE=true; if(digits > 0) BuyStop = NormalizeDouble(BuyStop, digits); BuyStop = ValidStopLoss(0, pBid, BuyStop); Newticket = searchNewTicket(ticket); OrderModify(Newticket,OOP,BuyStop,OOP+TakeProfit*Point,0,LightGreen); } } } void Corto(int ticket, double OOP) { int digits, Newticket; double pBid, pAsk, BuyStop; OrderSelect(ticket,SELECT_BY_TICKET); if(BE == false) //STOP INICIAL { while(First == true) { First=false; OrderModify(ticket,OOP,OOP+StopLoss*Point,OOP-TakeProfit*Point,0,Green); } } pAsk = MarketInfo(Symbol(), MODE_ASK); if(pAsk <= (OOP - TakeProfit*Point) && (BE == true)) { if(!OrderClose(OrderTicket(), OrderLots(), pAsk, 3, Violet)) Print(GetLastError()); BE = false; First = true; } else { if(pAsk <= (OOP - TP1*Point) && (BE == false)) { if(!OrderClose(OrderTicket(), OrderLots()/2, pAsk, 3, Violet)) Print(GetLastError()); BuyStop = OOP; BE=true; if(digits > 0) BuyStop = NormalizeDouble(BuyStop, digits); BuyStop = ValidStopLoss(1, pAsk, BuyStop); Newticket = searchNewTicket(ticket); OrderModify(Newticket,OOP,BuyStop,OOP-TakeProfit*Point,0,LightGreen); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int searchNewTicket(int oldTicket) { for(int i=OrdersTotal()-1; i>=0; i--) if(OrderSelect(i,SELECT_BY_POS) && StrToInteger(StringSubstr(OrderComment(),StringFind(OrderComment(),"#")+1)) == oldTicket) return (OrderTicket()); return (-1); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double ValidStopLoss(int type, double price, double SL) { double mySL; double minstop; minstop = MarketInfo(Symbol(),MODE_STOPLEVEL); if(Digits == 3 || Digits == 5) minstop = minstop / 10; mySL = SL; if(type == 0) { if((price - mySL) < minstop*myPoint) mySL = price - minstop*myPoint; } if(type == 1) { if((mySL-price) < minstop*myPoint) mySL = price + minstop*myPoint; } return(NormalizeDouble(mySL,MarketInfo(Symbol(), MODE_DIGITS))); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double SetPoint() { double mPoint; if(Digits < 4) mPoint = 0.01; else mPoint = 0.0001; return(mPoint); } //+------------------------------------------------------------------+ //+----------------------------------------