//+------------------------------------------------------------------+ //| Fibo.mq4 | /* Lots := 1.00 Stop Loss := 30 Take Profit := 100 Trailing Stop := 0 */ //+------------------------------------------------------------------+ #property copyright "O.Petersen" #property link "O.P" extern double Lots= 0.1; extern double MaximumRisk= 0.1; extern int StopLoss=49,TakeProfit=300,TrailingStop=26; extern int StartHour=9,EndHour=18,Range=45,fib=50; double H=0,L=0,ma=0,ma1=0,ma2=0,t1=0,t2=0,rsi=0; int total,cnt; //+------------------------------------------------------------------+ //| Calculate optimal lot size | //+------------------------------------------------------------------+ double LotsOptimized() { double lot=Lots; int orders=HistoryTotal(); // history orders total int losses=0; // number of losses orders without a break //---- select lot size lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1); //---- return lot size if(lot<0.1) lot=0.1; return(lot); } int start(){ H=iHigh(NULL,PERIOD_D1,0); L=iLow(NULL,PERIOD_D1,0); ma=iMA(NULL,PERIOD_M30,20,0,MODE_SMA,PRICE_CLOSE,0); ma1=iMA(NULL,PERIOD_M30,21,0,MODE_EMA,PRICE_CLOSE,0); ma2=iMA(NULL,PERIOD_M30,21,1,MODE_EMA,PRICE_CLOSE,0); rsi=iRSI(NULL,PERIOD_M30,8,PRICE_CLOSE,0); datetime some_time=iTime(NULL,PERIOD_D1,0); int shift=iBarShift(NULL,PERIOD_M15,some_time); int ht=Highest(NULL,PERIOD_M15,MODE_HIGH,shift,0); int lt=Lowest(NULL,PERIOD_M15,MODE_LOW,shift,0); total=OrdersTotal(); if(total<1) { if (H-L<Range*Point) { if((Ask>ma) && (Ask>(L+(H-L)*(fib/100))) && (ma1>ma2) && (Hour()>StartHour) && ( Hour()<EndHour) && (rsi>60) && (ht>lt)){ OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,5,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Fibo",0,Blue); return; } if((Bid<ma) && (Bid<(H-(H-L)*(fib/100)))&& (ma1<ma2) && (Hour()>StartHour) && ( Hour()<EndHour) && (rsi<40) &&(lt>ht)){ OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,5,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Fibo",0,Red); return; } } } int i; if (Hour()==18){ for (i = OrdersTotal() - 1; i >= 0; i--) { OrderSelect(i, SELECT_BY_POS); OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,HotPink); } } // it is important to enter the market correctly, // but it is more important to exit it correctly... for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==Symbol()) // check for symbol { if(OrderType()==OP_BUY) // long position is opened { // check for trailing stop if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); return(0); } } } } else // go to short position { // check for trailing stop if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } } } } return(0); } // the end.
Sample
Analysis
Market Information Used:
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Indicator Curves created:
Indicators Used:
Moving average indicator
Relative strength index
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It Closes Orders by itself
It can change open orders parameters, due to possible stepping strategy
Other Features: