Rejoindre la communauté
banner_forum
Devenez membre de la plus grande
communauté francophone sur le Forex
Partagez, échangez et apprenez en gagnant des crédits sur votre compte de trading

RENGOU MTF ORDRES STOPS

  • lefeuvr3

    Code
    //+------------------------------------------------------------------+ //| RENGOU MTF ORDRES STOPS.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //#property strict //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| RENGOU MTF.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //+------------------------------------------------------------------+ extern int MagicNumber=1618; double lot; extern int StopLoss=0; extern int TakeProfit=0; extern int TrailingStop=37; extern int Slippage=3; double point = MarketInfo(Symbol(), MODE_POINT); int spread = MarketInfo(Symbol(), MODE_SPREAD); extern int size = 0; int shiftOpenBuy =0; int shiftCloseBuy =1; int shiftOpenSell =0; int shiftCloseSell =1; extern double LotFactor =180; //lotsize factor int Amount = 250; int LockDown = 310; extern int Start_Hour = 1; extern int End_Hour = 23; extern string Name_EA = "RENGOU-MTF-EURUSD"; extern bool TrailingStop_ = true; extern string tp="TP IN MONEY"; extern bool Tp_in_Money = true; extern double TP_in_money = 15.1;//agir sur ce levier extern bool PERIOD_M5=true; extern bool PERIOD_M15=true; extern bool PERIOD_M30=true; extern bool PERIOD_H1=true; extern int ecartask=5; extern int ecartbid=22; double pt; int ras; //+------------------------------------------------------------------+ // expert start function //+------------------------------------------------------------------+ int start() { if(TrailingStop_)dtrailing(); if(Tp_in_Money && TP_in_money<=money()) //closeall(); double MyPoint=Point; if(Digits==3 || Digits==5) MyPoint=Point*10; double TheStopLoss=0; double TheTakeProfit=0; if( TotalOrdersCount()==0 ) { int result=0; //+------------------------------------------------------------------+ // Here is your open buy rule //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // Here is the beginning of your open buy rule strategy //+------------------------------------------------------------------+ // double Price=(Ask+Bid)/2; // if(PERIOD_M5==true) if(PERIOD_M5==true) if(PERIOD_M15==true) if(PERIOD_M30==true) if(PERIOD_H1==true) if (((iOpen(Symbol(),0, shiftOpenBuy)> iClose(Symbol(),0, shiftCloseBuy)+ (size + spread)*point)) &&(Bid >iOpen(Symbol(),PERIOD_M5,0)) &&(Bid >iOpen(Symbol(),PERIOD_M15,0)) &&(Bid >iOpen(Symbol(),PERIOD_M30,0)) &&(Bid >iOpen(Symbol(),PERIOD_H1,0))) //+------------------------------------------------------------------+ // Here is the end of your buy rule strategy //+------------------------------------------------------------------+ //if (!IsTradeContextBusy() && IsTradeAllowed()) { result=OrderSend(Symbol(),OP_BUYSTOP, (AccountBalance() * 0.01 /LotFactor)*5,Ask+ecartask*Point,5,(Ask+ecartask*Point)-StopLoss*Point,(Ask+ecartask*Point)+TakeProfit*Point,"SCALPING LONG SHORT V2",MagicNumber,0,clrBlue); if(result>0) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint; if(OrderSelect(result,SELECT_BY_TICKET)) bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,clrMediumSpringGreen); } return(0); } //+------------------------------------------------------------------+ // Here is your open sell rule //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // Here is the beginning of your open sell rule strategy //+------------------------------------------------------------------+ if(PERIOD_M5==true) if(PERIOD_M15==true) if(PERIOD_M30==true) if(PERIOD_H1==true) if ((( iOpen(Symbol(),0, shiftOpenSell)< iClose(Symbol(),0, shiftCloseSell)- (size + spread)*point)) &&(Bid <iOpen(Symbol(),PERIOD_M5,0)) &&(Bid <iOpen(Symbol(),PERIOD_M15,0)) &&(Bid <iOpen(Symbol(),PERIOD_M30,0)) &&(Bid <iOpen(Symbol(),PERIOD_H1,0))) //+------------------------------------------------------------------+ // Here is the end of your sell rule strategy //+------------------------------------------------------------------+ //if (!IsTradeContextBusy() && IsTradeAllowed()) { result=OrderSend(Symbol(),OP_SELLSTOP, (AccountBalance() * 0.01 /LotFactor)*2,Bid-ecartbid*Point,5,(Bid-ecartbid*Point)+StopLoss*Point,(Bid-ecartbid*Point)-TakeProfit*Point,NULL,MagicNumber,0,clrBlue); if(result>0) { TheStopLoss=0; TheTakeProfit=0; if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint; if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint; if(OrderSelect(result,SELECT_BY_TICKET)) bool modif2=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,clrMediumSpringGreen); } return(0); } } for(int cnt=0;cnt<OrdersTotal();cnt++) { if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber ) { if(OrderType()==OP_BUY) { if(TrailingStop>0) { if(Bid-OrderOpenPrice()>MyPoint*TrailingStop) { if(OrderStopLoss()<Bid-MyPoint*TrailingStop) { if(OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,clrMediumSpringGreen)) return(0); } } } } else { if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop)) { if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0)) { if(OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,clrMediumSpringGreen)) return(0); } } } } } } return(0); } int TotalOrdersCount() { int result=0; for(int i=0;i<OrdersTotal();i++) { if (OrderSelect(i,SELECT_BY_POS ,MODE_TRADES)) if (OrderMagicNumber()==MagicNumber) result++; } return (result); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //********************************************************************* //+------------------------------------------------------------------+ int Hour_trade() { bool trade=false; if(Start_Hour>End_Hour) { if(Hour()>=Start_Hour || Hour()<End_Hour) trade=true; } else if(Hour()>=Start_Hour && Hour()<End_Hour) trade=true; return (trade); } //+------------------------------------------------------------------+ // //+------------------------------------------------------------------+ int totalorder(int tipe) { int total=0; for(int i=0; i<OrdersTotal(); i++) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber || OrderType()!=tipe) continue; total++; } return(total); } void dtrailing() { int i,r;double tpn; for(i=0; i<OrdersTotal(); i++) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue; tpn=OrderTakeProfit(); if(OrderType()==OP_BUY) { if(Bid-OrderOpenPrice()>pt*TrailingStop) { if((OrderStopLoss()<Bid-pt*TrailingStop) || (OrderStopLoss()==0)) { if(tpn) r=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-pt*TrailingStop,OrderTakeProfit(),0,clrMediumSpringGreen); } } } if(OrderType()==OP_SELL) { if((OrderOpenPrice()-Ask)>(pt*TrailingStop)) { if(OrderStopLoss()>(Ask+pt*TrailingStop) || (OrderStopLoss()==0)) { if(tpn) r=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+pt*TrailingStop,OrderTakeProfit(),0,clrMediumSpringGreen); } } } } } //+------------------------------------------------------------------+ //| //+------------------------------------------------------------------+ double money() { double dp=0; int i; for(i=0; i<OrdersTotal(); i++) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue; dp+=OrderProfit(); } return(dp); } //+------------------------------------------------------------------+ bool CheckMoneyForTrade(string symb,double lots,int type) { double free_margin=AccountFreeMarginCheck(symb,type, lots); //-- if there is not enough money if(free_margin<0) { string oper=(type==OP_BUY)? "Buy":"Sell"; //fPrint("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError()); return(false); } //--- checking successful return(true); } //--------------------------------------------------------------------------- int CheckForClose() { if(getProfit()>=Amount)//{CloseAll();} if(LockDown>0) { for(int TradeNumber = OrdersTotal(); TradeNumber >= 0; TradeNumber--) { if (OrderSelect(TradeNumber, SELECT_BY_POS, MODE_TRADES)&&(LockDown>0)) { int Pos=OrderType(); if((Pos==OP_BUY)&&(Bid-OrderOpenPrice()>Point*LockDown)&&(OrderStopLoss() == 0)) {bool modif1=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point,OrderTakeProfit(),0,CLR_NONE);} if((Pos==OP_SELL)&&(OrderOpenPrice()-Ask>Point*LockDown)&&(OrderStopLoss() == 0)) {bool modif2=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point,OrderTakeProfit(),0,CLR_NONE);} } } } return(0); } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- double getProfit() { double Profit = 0; for (int TradeNumber = OrdersTotal(); TradeNumber >= 0; TradeNumber--) { if (OrderSelect(TradeNumber, SELECT_BY_POS, MODE_TRADES)) Profit = Profit + OrderProfit() + OrderSwap(); } return (Profit); } //+------------------------------------------------------------------+ //Calculates Lot Size based on balance and factor //+------------------------------------------------------------------+ double NR(double thelot) { double maxlots=MarketInfo(Symbol(),MODE_MAXLOT), minilot=MarketInfo(Symbol(),MODE_MINLOT), lstep=MarketInfo(Symbol(),MODE_LOTSTEP); double lots=lstep*NormalizeDouble(thelot/lstep,0); lots=MathMax(MathMin(maxlots,lots),minilot); return (lots); } //+------------------------------------------------------------------+ double Lot_Volume() { lot=AccountBalance() * 0.01 /LotFactor ; return(lot); } //+------------------------------------------------------------------+ //-------------------------------------------------------------------+
    lefeuvr3 a joint une image
    rengou-mtf-ordres-stops-11871