คือ อยากให้ EA มันทำงานทุกๆวินาที ตรวจสอบดูว่า Indicators Bollinger-Bands-2-Dev-MTF-Arrows-Alerts มันสร้างสัญลักษณ์ ครบ 5 วินาทีแล้วหรือยัง ถ้าครบแล้ว ใช้ Alert เตือน และ แสดง Comment บอกกำไรขาดทุน
//+------------------------------------------------------------------+
//| EA_V7.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
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
input int StopLoss = 5 ;
input bool Alert_PC = True ;
input bool Alert_Mobile = True ;
int total , histotal , sum = 0 , t_f = 99 , t_s = 99 ;
double factor = 1 , P_Close , P_Buy , P_Sell , P_Now , low = 0 , high = 0 , gap = 0 ;
bool Ans , signal_buy = False , signal_sell = False ;
int MagicNumber = 1111 ;
double sl = NormalizeDouble(( StopLoss * factor * Point ),Digits) ;
double pip10 = NormalizeDouble(( 10 * factor * Point ),Digits) ;
int OnInit()
{
//---
//---
EventSetTimer(1);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
double sar0 = iSAR(NULL,0,0.02,0.2,0) ;
double sar1 = iSAR(NULL,0,0.02,0.2,1) ;
// Singnal Buy
if( iCustom(NULL,0,"Bollinger-Bands-2-Dev-MTF-Arrows-Alerts",6,0) != EMPTY_VALUE || iCustom(NULL,0,"Bollinger-Bands-2-Dev-MTF-Arrows-Alerts",5,0) != EMPTY_VALUE )
{
if( t_f == 99 ) { t_f = Seconds() ; t_s = Seconds() ; }
if( t_f != 99 && Seconds() > t_f && t_s != Seconds() ) { t_s = Seconds() ; }
if( ( t_s - t_f ) >= 5 ) { signal_buy = True ; }
}
// Singnal Sell
else if( iCustom(NULL,0,"Bollinger-Bands-2-Dev-MTF-Arrows-Alerts",7,0) != EMPTY_VALUE || iCustom(NULL,0,"Bollinger-Bands-2-Dev-MTF-Arrows-Alerts",8,0) != EMPTY_VALUE )
{
if( t_f == 99 ) { t_f = Seconds() ; t_s = Seconds() ; }
if( t_f != 99 && Seconds() > t_f && t_s != Seconds() ) { t_s = Seconds() ; }
if( ( t_s - t_f ) >= 5 ) { signal_sell = True ; }
}
else { signal_buy = False ; signal_sell = False ; t_f = 99 ; t_s = 99 ; }
// Check Profit Order
for( int i = 0 ; i < total ; i++ )
{
Ans = OrderSelect( i,SELECT_BY_POS,MODE_TRADES) ;
if( OrderSymbol() == Symbol() )
{
if( OrderType() == OP_BUY )
{
sum = 0 ;
low = iClose(NULL,0, ( iBarShift(NULL,0,OrderOpenTime()) + 1 ) ) - sl ;
gap = OrderOpenPrice() - low ;
// Check Profit Order Buy By Order
P_Buy = P_Buy + ( OrderProfit() + OrderCommission() + OrderSwap() ) ;
if( Ask > sar1 ) { sum = sum + 1 ; }
if( Ask > sar0 ) { sum = sum + 1 ; }
if( OrderTakeProfit() == 0 )
{
if( Alert_PC == True ) { Alert (" Modify Take Profit Order Buy "+ Symbol() ) ; }
if( Alert_Mobile == True ) { SendNotification (" Modify Take Profit Order Buy "+ Symbol() ) ; }
if( sum >= 2 ) { Ans = OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss() , OrderOpenPrice() + ( gap * 3 ) ,0,clrNONE) ; }
else if( sum >= 1 ) { Ans = OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss() , OrderOpenPrice() + ( gap * 2 ) ,0,clrNONE) ; }
else { Ans = OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss() , OrderOpenPrice() + gap ,0,clrNONE) ; }
}
if( OrderStopLoss() == 0 )
{
Ans = OrderModify(OrderTicket(),OrderOpenPrice(), low ,OrderTakeProfit(),0,clrNONE) ;
if( Alert_PC == True ) { Alert (" Modify Stop Loss Order Buy "+ Symbol() ) ; }
if( Alert_Mobile == True ) { SendNotification (" Modify Stop Loss Order Buy "+ Symbol() ) ; }
}
if( OrderStopLoss() != 0 && ( Bid - OrderStopLoss() ) > ( gap * 2 ) ) //
{
if( Alert_PC == True ) { Alert (" Modify Stop Win Order Buy "+ Symbol() ) ; }
if( Alert_Mobile == True ) { SendNotification (" Modify Stop Win Order Buy "+ Symbol() ) ; }
Ans = OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss() + gap ,OrderTakeProfit(),0,clrNONE) ;
}
}
if( OrderType() == OP_SELL )
{
sum = 0 ;
high = iClose(NULL,0, ( iBarShift(NULL,0,OrderOpenTime()) + 1 ) ) + sl ;
gap = high - OrderOpenPrice() ;
// Check Profit Order Sell By Order
P_Sell = P_Sell + ( OrderProfit() + OrderCommission() + OrderSwap() ) ;
if( Bid < sar1 ) { sum = sum + 1 ; }
if( Bid < sar0 ) { sum = sum + 1 ; }
if( OrderTakeProfit() == 0 )
{
if( Alert_PC == True ) { Alert (" Modify Take Profit Order Sell "+ Symbol() ) ; }
if( Alert_Mobile == True ) { SendNotification (" Modify Take Profit Order Sell "+ Symbol() ) ; }
if( sum >= 2 ) { Ans = OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss() , OrderOpenPrice() - ( gap * 3 ) ,0,clrNONE) ; }
else if( sum >= 1 ) { Ans = OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss() , OrderOpenPrice() - ( gap * 2 ) ,0,clrNONE) ; }
else { Ans = OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss() , OrderOpenPrice() - gap ,0,clrNONE) ; }
}
if( OrderStopLoss() == 0 ) //&& Ask < ( OrderOpenPrice() + ( gap * 1.5 ) )
{
Ans = OrderModify(OrderTicket(),OrderOpenPrice(), high ,OrderTakeProfit(),0,clrNONE) ;
if( Alert_PC == True ) { Alert (" Modify Stop Loss Order Sell "+ Symbol() ) ; }
if( Alert_Mobile == True ) { SendNotification (" Modify Stop Loss Order Sell "+ Symbol() ) ; }
}
if( OrderStopLoss() != 0 && ( OrderStopLoss() - Ask ) > ( gap * 2 ) ) //
{
if( Alert_PC == True ) { Alert (" Modify Stop Win Order Sell "+ Symbol() ) ; }
if( Alert_Mobile == True ) { SendNotification (" Modify Stop Win Order Sell "+ Symbol() ) ; }
Ans = OrderModify(OrderTicket(),OrderOpenPrice(), OrderStopLoss() - gap ,OrderTakeProfit(),0,clrNONE) ;
}
}
}
}
P_Now = P_Buy + P_Sell ;
// Check Profit_Close
for(int i = 0 ; i < histotal ; i++ )
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
{
//if( OrderSymbol() == Symbol() )
//{
if( TimeToStr(OrderCloseTime(),TIME_DATE) == TimeToStr(TimeCurrent(),TIME_DATE) )
{
P_Close = P_Close + ( OrderProfit() + OrderCommission() + OrderSwap() );
}
//}
}
}
// Open Order
// Singnal Open Order Buy
if( signal_buy == True )
{
if( Alert_PC == True ) { Alert (" Open Order Buy "+ Symbol() ) ; }
if( Alert_Mobile == True ) { SendNotification (" Open Order Buy "+ Symbol() ) ; }
}
// Singnal Open Order Sell
if( signal_sell == True )
{
if( Alert_PC == True ) { Alert (" Open Order Sell "+ Symbol() ) ; }
if( Alert_Mobile == True ) { SendNotification (" Open Order Sell "+ Symbol() ) ; }
}
Comment(
"\n\n Profit Close = "+(string)P_Close
+"\n\n Profit Buy = "+(string)P_Buy
+"\n\n Profit Sell = "+(string)P_Sell
+"\n\n Signal Buy = "+(string)signal_buy
+"\n\n Signal Sell = "+(string)signal_sell
);
P_Close = 0 ; P_Buy = 0 ; P_Sell = 0 ;
}
//+------------------------------------------------------------------+