Software Developer and Music Producer
News Fundamentals All Time Return:
1,159.1%
I will code your pivot EAs for no charge 28 replies
I will code your scalping EAs for no charge 163 replies
Oanda MT4 - Indicators and EAs not showing 2 replies
EAs and indicators relating to moutaki... 22 replies
InterbankFX has loaded its MT4 platform with custom EAs, indicators and scripts 1 reply
Disliked{quote} Thank you!! This robot does not trade. It starts but does nothing.Ignored
Disliked{quote} thanks brother sir some signals are created without following strategy rules. Arrow appears without following the rulesIgnored
Disliked{quote} I can see how it may be annoying always loading as on. OHLC_info_mouse - show ohlc prices at the mouse cursor - optional time - optional 1minute of high/low - optional vline - v1.2 - defaulted option to only show when hotkey is pressed ie loads unshown {image} {file}Ignored
Disliked{quote} Exactly what I was looking for. Do you have any for MT5? Because I am using MT5. Thank you so much for helping me.Ignored
Disliked{quote} Adicionei M1 a H4, pois provavelmente tudo o que necessrio para a negociao diria e adicionei um rtulo para mostrar qual clculo est sendo usado. {file} {image}Ignored
#property copyright "Copyright :copyright: 2005, Mr.Sun" #property link "mailto:[email protected]" #property indicator_separate_window #property indicator_buffers 6 #property indicator_color1 Blue #property indicator_color2 Coral #property indicator_color3 Red #property indicator_color4 Magenta #property indicator_color5 clrChocolate #property indicator_color6 clrSilver #property indicator_level1 0 #property indicator_levelcolor clrSilver #property indicator_levelstyle STYLE_SOLID //#include <kholuutru.mqh> //---- input parameters extern int Fast =12; extern int Slow =26; extern int Signal =9; extern int Fast_TF1 =12; extern int Slow_TF1 =26; extern int Signal_TF1 =9; //---- buffers double MACDLineBuffer[], SignalLineBuffer[], main_TF1[], sign_TF1[]; double SignalDown[]; double SignalUp[]; int Count_signal=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorShortName("Check Only one Signal"); SetIndexBuffer(0,MACDLineBuffer); SetIndexStyle(0,DRAW_LINE,1,2,Blue); SetIndexDrawBegin (0,Slow); SetIndexBuffer(1,SignalLineBuffer); SetIndexStyle(1,DRAW_LINE,1,2,clrCoral); SetIndexDrawBegin (1,Slow+Signal); //Arrow SetIndexBuffer(2, SignalDown); SetIndexStyle(2,DRAW_ARROW,0,1); SetIndexDrawBegin (2,Slow+Signal); SetIndexArrow(2, 234); SetIndexBuffer(3, SignalUp); SetIndexStyle(3,DRAW_ARROW,0,1); SetIndexDrawBegin (3,Slow+Signal); SetIndexArrow(3,233); //Check main + sign off TF1 SetIndexBuffer(4,main_TF1); SetIndexStyle(4,DRAW_LINE,2,0,clrBlue); SetIndexDrawBegin (4,Slow+Signal); SetIndexBuffer(5,sign_TF1); SetIndexStyle(5,DRAW_LINE,2,0,clrCoral); SetIndexDrawBegin (5,Slow+Signal); return(0); } int TF1() { int TF=0; switch (Period()) { case 1: TF= 15; break; case 5: TF= 30; break; case 15: TF= 60; break; case 30: TF= 240; break; case 60: TF= 240; break; case 240: TF= 1440; break; case 1440: TF= PERIOD_W1; break; case 10080: TF= PERIOD_MN1;break; case 43200: TF= 43200; break; } return(TF); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(0); if(counted_bars > 0) counted_bars--; int limit = fmin(Bars - counted_bars,Bars-1); int Count_buy=0; for(int i=limit; i>=0; i--) { int shift = iBarShift(Symbol(),TF1(), Time[i], true); if (shift == -1) continue; { main_TF1[i]= iMACD(Symbol(), TF1(), Fast_TF1, Slow_TF1, 2,PRICE_CLOSE,MODE_SIGNAL,shift); sign_TF1[i]= iMACD(Symbol(), TF1(), Fast_TF1, Slow_TF1, Signal_TF1,PRICE_CLOSE,MODE_SIGNAL,shift); if(main_TF1[i] > sign_TF1[i]) int tin_hieu_TF1 =0; else tin_hieu_TF1 =1; } MACDLineBuffer[i] = iMACD(Symbol(),0,Fast,Slow,2,PRICE_CLOSE,MODE_SIGNAL,i); SignalLineBuffer[i] = iMACD(Symbol(),0,Fast,Slow,Signal,PRICE_CLOSE,MODE_SIGNAL,i); //SELL signal if (MACDLineBuffer[i]<=SignalLineBuffer[i]) { SignalDown[i]= SignalLineBuffer[i] ; } //BUY signal if (MACDLineBuffer[i]>=SignalLineBuffer[i]) { SignalUp[i]= MACDLineBuffer[i] ; } } return(0); }
Disliked/*-------------------------------------------------------------------- Change-log: mrsunftu_LSMA_EA_ver1 Date: 2025-01-08 By: MwlRCT -------------------------------------------------------------------- - Fixed array out of range errors across multiple currency pairs: - Implemented dynamic array sizing based on required calculation periods - Added proper array bounds checking in calculations - Fixed array initialization sequence - Enhanced array management: - Added safety checks for ArrayResize operations - Implemented proper ArraySetAsSeries for...Ignored
Dislikeddvzlm! Szeretnk hozzadni egy automatikus kereskedsi idő belltst. Pldul a robot 11 rtl kereskedik s 13 rakor r vget. Mdosthatom s bellthatom az időt. Megprbltam minden lehetsges mdon kdolni, de egyszerűen nem j. Mindig elrontom. Nagyon fontos lenne! Nagyon ksznm!{file}
Ignored
//+------------------------------------------------------------------+
//| Simple.mq4 |
//| Sofii Butenko |
//| https://www.mql5.com/ru/users/galina_bobro |
//+------------------------------------------------------------------+
#property copyright "Sofii Butenko"
#property link "https://www.mql5.com/ru/users/galina_bobro"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
////+------------------------------------------------------------------+
#define RESOURCE_IND
#define TESTER_HIGHT_IND
//+------------------------------------------------------------------+
enum ENUM_ON{
ON = (int)true,
OFF = (int)false};
enum ENUM_TREND{
TREND_UP=0,
TREND_DN=1,
TREND_NO=-1,
TREND_ER=-2
};
datetime gl_tm_old = 0;
#ifdef RUS
enum ENUM_bar{
bar_0=0, //#0 ???????
bar_1=1, //#1 ????????
};
#else
enum ENUM_bar{
bar_0=0, //#0 current
bar_1=1, //#1 close
};
#endif
#ifdef RUS
sinput string inp_s1 = "---------------------------"; //------ ????????? ----
input ENUM_bar inp_sign_bar = bar_1; //?????????? ???
input short inp_sign_shift = 0; //???????? (???) ?? ???????? ????
sinput string inp_s2 = "---------------------------"; //------ ???????? ----
input double inp_ord_lot = 0.01; //???
input uint inp_ord_tp = 0; //?? ????
input uint inp_ord_sl = 0; //?? ????
input ushort inp_ord_magic = 888; //?????
input ushort inp_ord_count = 1; //????. ??????? ? ?????
input ENUM_ON inp_cls = true; //????????? ?????? ??? ??????????????? ???????
sinput string inp_s3 = "---------------------------"; //------ ????? ----
input int inp_trade_start_hour = 0; //????? ?????? ???????? (???)
input int inp_trade_start_min = 0; //????? ?????? ???????? (??????)
input int inp_trade_end_hour = 23; //????? ????? ???????? (???)
input int inp_trade_end_min = 59; //????? ????? ???????? (??????)
#else
sinput string inp_s1 = "---------------------------"; //------ Indicator ----
input ENUM_bar inp_sign_bar = bar_1; //signal bar
input short inp_sign_shift = 0; //delay (sec) from bar opening
sinput string inp_s2 = "---------------------------"; //------ Trade ----
input double inp_ord_lot = 0.01; //Lot
input uint inp_ord_tp = 0; //TP pips
input uint inp_ord_sl = 0; //SL pips
input ushort inp_ord_magic = 888; //Magic
input ushort inp_ord_count = 1; //Max orders in the market
input ENUM_ON inp_cls = true; //Close orders opposite to the signal
sinput string inp_s3 = "---------------------------"; //------ Time ----
input int inp_trade_start_hour = 0; //Trading start hour (0-23)
input int inp_trade_start_min = 0; //Trading start minute (0-59)
input int inp_trade_end_hour = 23; //Trading end hour (0-23)
input int inp_trade_end_min = 59; //Trading end minute (0-59)
#endif
//---------------INDICATOR
#define ind_name "precentualzz_victor"
#ifdef RESOURCE_IND
#resource "\\Indicators\\"+ind_name+".ex4"
#endif
//--------------- MESSAGE
#define MessageBoxE(msg) MessageBox(msg, msg_e, MB_ICONERROR|MB_OK);
#define MessageBoxQ(msg) MessageBox(msg, "", MB_OKCANCEL|MB_ICONQUESTION)==IDOK
#ifdef RUS
#define msg_e "??????"
#define msg_s " ??? "
#define msg_10 "????????? \"???????? (???) ?? ???????? ????\" \n?? ????? ???? ????? ??? ?????? ? ???? "
#define msg_11 "????????? ???? ?????? ???????? ???????? "
#else
#define msg_e "Error"
#define msg_s " sec "
#define msg_10 "The setting is \"delay (sec) from bar opening\" \ncannot be more than seconds in the bar "
#define msg_11 "Trading time settings are invalid "
#endif
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit(){
if(inp_sign_shift>=PeriodSeconds()){ MessageBoxE(msg_10+" ["+IntegerToString(PeriodSeconds())+msg_s+"] !"); return(INIT_FAILED);}
// Check if trading hours are valid
if(inp_trade_start_hour < 0 || inp_trade_start_hour > 23 ||
inp_trade_start_min < 0 || inp_trade_start_min > 59 ||
inp_trade_end_hour < 0 || inp_trade_end_hour > 23 ||
inp_trade_end_min < 0 || inp_trade_end_min > 59){
MessageBoxE(msg_11+"!");
return(INIT_FAILED);
}
gl_tm_old = Time[0];
#ifdef TESTER_HIGHT_IND
TesterHideIndicators(true);
#endif
return(INIT_SUCCEEDED);}
//+------------------------------------------------------------------+
//| Check if current time is within trading hours |
//+------------------------------------------------------------------+
bool IsWithinTradingHours(){
datetime current_time = TimeCurrent();
int current_hour = TimeHour(current_time);
int current_min = TimeMinute(current_time);
// Convert time to minutes for easier comparison
int current_time_in_minutes = current_hour * 60 + current_min;
int start_time_in_minutes = inp_trade_start_hour * 60 + inp_trade_start_min;
int end_time_in_minutes = inp_trade_end_hour * 60 + inp_trade_end_min;
// Check if current time is within trading hours
if(start_time_in_minutes <= end_time_in_minutes){
// Normal case (e.g., 9:00 to 17:00)
return (current_time_in_minutes >= start_time_in_minutes &&
current_time_in_minutes <= end_time_in_minutes);
} else {
// Overnight case (e.g., 22:00 to 6:00)
return (current_time_in_minutes >= start_time_in_minutes ||
current_time_in_minutes <= end_time_in_minutes);
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick(){
datetime tm_new = Time[0];
if(gl_tm_old != tm_new){
bool b = false;
// Check if within trading hours
if(!IsWithinTradingHours()) return;
//--- GET SIGNAL
ENUM_TREND sig = ( TimeCurrent() < (tm_new+inp_sign_shift) ? TREND_NO : Fn_signal(inp_sign_bar) );
if(sig==TREND_UP || sig==TREND_DN){ b = true;
//--- CLOSE
if(inp_cls)
b = Fn_ord_cls_all( (sig!=TREND_UP), _Symbol, inp_ord_magic) && b;
//--- OPEN
if(inp_ord_count<=0 || inp_ord_count > Fn_ord_count(-1, _Symbol, inp_ord_magic) )
b = Fn_ord_set( (sig==TREND_UP), inp_ord_lot, inp_ord_sl, inp_ord_tp, inp_ord_magic, NULL, tm_new) && b;
}
if(b) gl_tm_old = tm_new;}
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason){
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Signal |
//+------------------------------------------------------------------+
double Fn_ind_get_value(int buf_num, int index){
return(iCustom(_Symbol,PERIOD_CURRENT, #ifdef RESOURCE_IND "::Indicators\\"+ #endif ind_name, 0.028, buf_num, index)); }
ENUM_TREND Fn_signal(int index=1){
double val_b = Fn_ind_get_value(0 , index); bool is_b = (val_b!=0.0 && val_b!=EMPTY_VALUE);
double val_s = Fn_ind_get_value(1, index); bool is_s = (val_s!=0.0 && val_s!=EMPTY_VALUE);
if( is_b && !is_s){ return(TREND_UP); }
if(!is_b && is_s){ return(TREND_DN); }
return(TREND_NO); }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//| ORDS |
//| |
//+------------------------------------------------------------------+
int Sp_order_select(int index, int is_buy=-1, string symb=NULL, int magic=-1, string comm=NULL, int pool = MODE_TRADES, datetime time_start=0, bool only_loss = false){
if(!OrderSelect(index, SELECT_BY_POS, pool) ) return(0);
if( magic >= 0 && magic != OrderMagicNumber() ) return(0);
if( time_start >= 0 && time_start > OrderOpenTime () ) return(0);
if( is_buy >= 0 && is_buy != ((OrderType()%2)==0) ) return(0);
if( symb != NULL && StringFind(OrderSymbol (), symb)<0 ) return(0);
if( comm != NULL && StringFind(OrderComment(), comm)<0 ) return(0);
if( only_loss && (OrderProfit()+OrderSwap()+OrderCommission())>=0 ) return(0);
return(OrderTicket());}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
#define IN int is_buy=-1, string symb = NULL, int magic=-1, string comm=NULL, bool is_hist=false, datetime time_start=0, bool only_loss = false
#define FOR for(int i = (is_hist?OrdersHistoryTotal():OrdersTotal())-1 ; i>=0 ; i--){ \
int tic = Sp_order_select(i, is_buy, symb, magic, comm, (is_hist?MODE_HISTORY:MODE_TRADES), time_start, only_loss);
//.....................................................
int Fn_ord_find(IN){
FOR if(tic>0) return(tic); }
return(0);}
//.....................................................
int Fn_ord_count(IN){
int rez = 0;
FOR if(tic>0) rez++; }
return(rez);}
//.....................................................
bool Fn_ord_cls_all(int is_buy=-1, string symb = NULL, int magic=-1, string comm=NULL, datetime time_start=0, bool only_loss = false){
const bool is_hist=false;
bool rez = true;
FOR if(!Fn_ord_cls(tic)) rez = false; }
return(rez);}
//.....................................................
#undef IN
#undef FOR
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void _print_err(string s){ Print("ERROR! "+s); }
bool IsOkTerminal(){
static bool alrt = true;
if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) ) { string str="Terminal trade NO allowed!"; if(alrt){ alrt=false; _print_err(str); } return(false); }
if(!MQLInfoInteger (MQL_TRADE_ALLOWED) ) { string str="MQL trade NO allowed!" ; if(alrt){ alrt=false; _print_err(str); } return(false); }
alrt = true;
return(true);}
double NormalizeLevel(double val, bool is_up, double lev, double point, int min_dist=0){
if (lev<=0 || val<=0) return(val);
int razn=(int)((is_up?(val-lev):(lev-val))/point);
if(razn<min_dist) return(is_up?(lev+min_dist*point):(lev-min_dist*point));
return(val); }
double NormalizeLot(string symbol, double lot, bool is_margin=true){
if(lot<=0) return(0);
double min=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
double max=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
double step=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
double free = AccountFreeMargin();
double margin = MarketInfo(Symbol(),MODE_MARGINREQUIRED);
double _lot=(lot<min)?min:((lot>max)?max:lot);
_lot=MathRound(_lot/step)*step;
if(is_margin && _lot*margin>=free) { _lot= MathFloor(free/margin/step)*step; }
return(_lot);}
//+------------------------------------------------------------------+
bool Fn_ord_set(bool is_buy, double volume, int SL, int TP, int magic, string comm, datetime time_start=0){
if(!IsOkTerminal()) return(false);
// Check if within trading hours
if(!IsWithinTradingHours()) return(false);
//...............................
static bool is_alert = true;
string symb = _Symbol;
int Min_SL =(int)SymbolInfoInteger(symb,SYMBOL_TRADE_STOPS_LEVEL)+1;
int dig =(int)SymbolInfoInteger(symb,SYMBOL_DIGITS);
double point = SymbolInfoDouble (symb,SYMBOL_POINT);
double zn = (is_buy?1:(-1));
//...............................
for(int i=0; (i<5 && !IsStopped()); i++){
if(volume<=0) return(false);
if(time_start>0){
if(Fn_ord_find((int)is_buy, symb, magic, comm, false, time_start)> 0 ) return(true);
if(Fn_ord_find((int)is_buy, symb, magic, comm, true , time_start)> 0 ) return(true); }
//------
double pr_opn = NormalizeDouble((is_buy?SymbolInfoDouble(symb, SYMBOL_ASK):SymbolInfoDouble(symb, SYMBOL_BID)), dig);
double pr_cls = NormalizeDouble((is_buy?SymbolInfoDouble(symb, SYMBOL_BID):SymbolInfoDouble(symb, SYMBOL_ASK)), dig);
//---- level
double tp = ((TP<=0)?0:NormalizeDouble(NormalizeLevel((pr_opn+(is_buy?( 1):(-1))*TP*point), is_buy, pr_opn, point, Min_SL), dig));
double sl = ((SL<=0)?0:NormalizeDouble(NormalizeLevel((pr_opn-(is_buy?( 1):(-1))*SL*point), !is_buy, pr_cls, point, Min_SL), dig));
//----- Lot
double lot=NormalizeLot(symb, volume);
if(lot<=0){ if(is_alert){Alert("Very big lot!"); is_alert=false;} return(false);}
//----- Set
int tic=OrderSend(symb, (is_buy?ORDER_TYPE_BUY:ORDER_TYPE_SELL), lot, pr_opn, 0, sl, tp, comm, magic);
//----- Err
if (tic>0){ is_alert=true; return(true); }
else if (!Errors(GetLastError(), is_alert)) return(false);}
//--------------------
return(false); }
//+------------------------------------------------------------------+
bool Fn_ord_cls(int ticket, double lot_close=0, string comm=""){
if(!IsOkTerminal()) return(false);
static bool is_alert = true;
for(int i=0; (i<5 && !IsStopped()); i++){
if(!OrderSelect(ticket, SELECT_BY_TICKET)) return(true);
if(OrderCloseTime()>0) return(true);
bool ans = true;
if(OrderType()==ORDER_TYPE_BUY || OrderType()==ORDER_TYPE_SELL){
double pr = SymbolInfoDouble(OrderSymbol(), (OrderType()==ORDER_TYPE_BUY?SYMBOL_BID:SYMBOL_ASK) );
double lot = (lot_close<=0 || lot_close>OrderLots())?OrderLots():NormalizeLot(OrderSymbol(), lot_close);
ans = OrderClose(ticket, lot, pr, 0);}
else{ ans = OrderDelete(ticket); }
if (ans) {is_alert=true; if(comm!="") Print("CLOSE Order : "+comm); return(true); }
else if (!Errors(GetLastError(), is_alert)) return(false);
}
return(false); }
//+------------------------------------------------------------------+
bool Errors(int err, bool &alerts){
string str="";
bool rez=false;
switch(err) {
case 4: str="Trade server is busy. once again..."; Sleep(500); RefreshRates(); rez=true; break;
case 128: str="Trade timeout. once again..."; RefreshRates(); rez=true; break;
case 135: str="Price changed. once again..."; RefreshRates(); rez=true; break;
case 136: str="Off quotes. once again..."; RefreshRates(); rez=true; break;
case 137: str="Broker is busy. once again..."; Sleep(500); RefreshRates(); rez=true; break;
case 138: str="Requote. once again..."; Sleep(500); RefreshRates(); rez=true; break;
case 146: str="Trade context is busy. once again..."; Sleep(500); RefreshRates(); rez=true; break;
//------------------------------------------------------------
case 2: str="Common error"; rez=false; break;
case 5: str="Old version of the client terminal"; rez=false; break;
case 6: str="No connection with trade server"; rez=false; break;
case 64: str="Account disabled"; rez=false; break;
case 65: str="Invalid account"; rez=false; break;
case 129: str="Invalid price"; rez=false; break;
case 130: str="Invalid stops"; rez=false; break;
case 131: str="Invalid trade volume"; rez=false; break;
case 132: str="Market is closed"; rez=false; break;
case 133: str="Trade is disabled"; rez=false; break;
case 134: str="Not enough money"; rez=false; break;
case 145: str="Modification denied because order is too close to market"; rez=false; break;
case 4109: str="Trade is not allowed"; rez=false; break;
case 4108: /*????? ???????? ?????? ??? ?? ?????? ???-?? ???????*/ rez=false; break;
default: str= "Error ord "+IntegerToString(err); rez=false; break;}
if(str!="" && alerts){ Alert(str); alerts=false;}
return (rez);}
//+------------------------------------------------------------------+
Disliked{quote} //+------------------------------------------------------------------+ //| Egyszerű.mq4 | //| Szfij Butenko | //| https://www.mql5.com/ru/users/galina_bobro | +------------------------------------------------------------------+ #property szerzői jog "Sofii Butenko" #property link "https://www.mql5.com/ru/users/galina_bobro" #property "1.00" verzi #property szigor //+------------------------------------------------------------------+ /////+------------------------------------------------------------------+ #define RESOURCE_IND #define TESTER_HIGHT_IND...Ignored
DislikedFor example i drag one horizontal line this is my entry and input stop-loss take profit number so draw another 2 horizontal and now show pips/usd and now i can move lines to measure entry sl tp .Ignored
https://forex-station.com/app.php/attach/file/3359829
void OnTick(){
datetime tm_new = Time[0];
if(gl_tm_old != tm_new){
bool b = false;
// Check if within trading hours
if(!IsWithinTradingHours()) return; // <--- This line *prevents further actions in OnTick* if outside hours, but doesn't CLOSE orders
//--- GET SIGNAL
ENUM_TREND sig = ( TimeCurrent() < (tm_new+inp_sign_shift) ? TREND_NO : Fn_signal(inp_sign_bar) );
// ... rest of OnTick ...
}
} ENUM_TREND Fn_signal(int index=1){
double val_b = Fn_ind_get_value(0 , index); bool is_b = (val_b!=0.0 && val_b!=EMPTY_VALUE);
double val_s = Fn_ind_get_value(1, index); bool is_s = (val_s!=0.0 && val_s!=EMPTY_VALUE);
if( is_b && !is_s){ return(TREND_UP); } // Buy signal logic
if(!is_b && is_s){ return(TREND_DN); } // Sell signal logic
return(TREND_NO); } //+------------------------------------------------------------------+
//| Simple.mq4 |
//| Sofii Butenko |
//| https://www.mql5.com/ru/users/galina_bobro |
//+------------------------------------------------------------------+
#property copyright "Sofii Butenko"
#property link "https://www.mql5.com/ru/users/galina_bobro"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
#define RESOURCE_IND
#define TESTER_HIGHT_IND
//+------------------------------------------------------------------+
enum ENUM_ON {
ON = (int)true,
OFF = (int)false
};
enum ENUM_TREND {
TREND_UP=0,
TREND_DN=1,
TREND_NO=-1,
TREND_ER=-2
};
datetime gl_tm_old = 0;
#ifdef RUS
enum ENUM_bar {
bar_0=0, //#0 текущий
bar_1=1 //#1 закрытый
};
#else
enum ENUM_bar {
bar_0=0, //#0 current
bar_1=1 //#1 close
};
#endif
#ifdef RUS
sinput string inp_s1 = "---------------------------"; //------ Индикатор ----
input ENUM_bar inp_sign_bar = bar_1; //Сигнальный бар
input short inp_sign_shift = 0; //Задержка (сек) от открытия бара
sinput string inp_s2 = "---------------------------"; //------ Торговля ----
input double inp_ord_lot = 0.01; //Лот
input uint inp_ord_tp = 0; //ТП пункты
input uint inp_ord_sl = 0; //СЛ пункты
input ushort inp_ord_magic = 888; //Магия
input ushort inp_ord_count = 1; //Макс. ордеров в рынке
input ENUM_ON inp_cls = true; //Закрывать ордера против сигнала
sinput string inp_s3 = "---------------------------"; //------ Время ----
input int inp_trade_start_hour = 0; //Часы начала торговли (час)
input int inp_trade_start_min = 0; //Часы начала торговли (минуты)
input int inp_trade_end_hour = 23; //Часы конца торговли (час)
input int inp_trade_end_min = 59; //Часы конца торговли (минуты)
#else
sinput string inp_s1 = "---------------------------"; //------ Indicator ----
input ENUM_bar inp_sign_bar = bar_1; //Signal bar
input short inp_sign_shift = 0; //Delay (sec) from bar opening
sinput string inp_s2 = "---------------------------"; //------ Trade ----
input double inp_ord_lot = 0.01; //Lot
input uint inp_ord_tp = 0; //TP pips
input uint inp_ord_sl = 0; //SL pips
input ushort inp_ord_magic = 888; //Magic
input ushort inp_ord_count = 1; //Max orders in the market
input ENUM_ON inp_cls = true; //Close orders opposite to the signal
sinput string inp_s3 = "---------------------------"; //------ Time ----
input int inp_trade_start_hour = 0; //Trading start hour (0-23)
input int inp_trade_start_min = 0; //Trading start minute (0-59)
input int inp_trade_end_hour = 23; //Trading end hour (0-23)
input int inp_trade_end_min = 59; //Trading end minute (0-59)
#endif
//---------------INDICATOR
#define ind_name "precentualzz_victor"
#ifdef RESOURCE_IND
#resource "\\Indicators\\"+ind_name+".ex4"
#endif
//--------------- MESSAGE
#define MessageBoxE(msg) MessageBox(msg, msg_e, MB_ICONERROR|MB_OK)
#define MessageBoxQ(msg) MessageBox(msg, "", MB_OKCANCEL|MB_ICONQUESTION)==IDOK
#ifdef RUS
#define msg_e "Ошибка"
#define msg_s " сек "
#define msg_10 "Настройка \"Задержка (сек) от открытия бара\" \nне может быть больше секунд в баре "
#define msg_11 "Настройки времени начала торговли неверны "
#else
#define msg_e "Error"
#define msg_s " sec "
#define msg_10 "The setting is \"delay (sec) from bar opening\" \ncannot be more than seconds in the bar "
#define msg_11 "Trading time settings are invalid "
#endif
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit() {
if(inp_sign_shift >= PeriodSeconds()) {
MessageBoxE(msg_10 + " [" + IntegerToString(PeriodSeconds()) + msg_s + "] !");
return(INIT_FAILED);
}
if(inp_trade_start_hour < 0 || inp_trade_start_hour > 23 ||
inp_trade_start_min < 0 || inp_trade_start_min > 59 ||
inp_trade_end_hour < 0 || inp_trade_end_hour > 23 ||
inp_trade_end_min < 0 || inp_trade_end_min > 59) {
MessageBoxE(msg_11 + "!");
return(INIT_FAILED);
}
gl_tm_old = Time[0];
#ifdef TESTER_HIGHT_IND
TesterHideIndicators(true);
#endif
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Check if current time is within trading hours |
//+------------------------------------------------------------------+
bool IsWithinTradingHours() {
datetime current_time = TimeCurrent();
int current_hour = TimeHour(current_time);
int current_min = TimeMinute(current_time);
int current_time_in_minutes = current_hour * 60 + current_min;
int start_time_in_minutes = inp_trade_start_hour * 60 + inp_trade_start_min;
int end_time_in_minutes = inp_trade_end_hour * 60 + inp_trade_end_min;
if(start_time_in_minutes <= end_time_in_minutes) {
return (current_time_in_minutes >= start_time_in_minutes &&
current_time_in_minutes <= end_time_in_minutes);
} else {
return (current_time_in_minutes >= start_time_in_minutes ||
current_time_in_minutes <= end_time_in_minutes);
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick() {
// Check trading hours on every tick and close orders if outside
if(!IsWithinTradingHours()) {
if(Fn_ord_count(-1, _Symbol, inp_ord_magic) > 0) {
Print("Trading hours ended - Closing all open orders.");
Fn_ord_cls_all(-1, _Symbol, inp_ord_magic);
}
return;
}
datetime tm_new = Time[0];
if(gl_tm_old != tm_new) {
bool b = false;
// Get signal from indicator
ENUM_TREND sig = (TimeCurrent() < (tm_new + inp_sign_shift) ? TREND_NO : Fn_signal(inp_sign_bar));
Print("OnTick: Signal from Fn_signal=", sig); // Debug signal value
if(sig == TREND_UP || sig == TREND_DN) {
b = true;
// Close opposite orders if enabled
if(inp_cls)
b = Fn_ord_cls_all((sig != TREND_UP), _Symbol, inp_ord_magic) && b;
// Open new order if within order count limit
if(inp_ord_count <= 0 || inp_ord_count > Fn_ord_count(-1, _Symbol, inp_ord_magic))
b = Fn_ord_set((sig == TREND_UP), inp_ord_lot, inp_ord_sl, inp_ord_tp, inp_ord_magic, NULL, tm_new) && b;
}
if(b) gl_tm_old = tm_new;
}
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
}
//+------------------------------------------------------------------+
//| Signal functions |
//+------------------------------------------------------------------+
double Fn_ind_get_value(int buf_num, int index) {
return(iCustom(_Symbol, PERIOD_CURRENT, #ifdef RESOURCE_IND "::Indicators\\"+ #endif ind_name, 0.028, buf_num, index));
}
ENUM_TREND Fn_signal(int index=1) {
double val_b = Fn_ind_get_value(0, index); bool is_b = (val_b != 0.0 && val_b != EMPTY_VALUE);
double val_s = Fn_ind_get_value(1, index); bool is_s = (val_s != 0.0 && val_s != EMPTY_VALUE);
Print("Fn_signal: Buffer 0 (Buy)=", val_b, ", Buffer 1 (Sell)=", val_s, ", is_b=", is_b, ", is_s=", is_s); // Debug buffer values
if(is_b && !is_s) return(TREND_UP);
if(!is_b && is_s) return(TREND_DN);
return(TREND_NO);
}
//+------------------------------------------------------------------+
//| Order management functions |
//+------------------------------------------------------------------+
int Sp_order_select(int index, int is_buy=-1, string symb=NULL, int magic=-1, string comm=NULL, int pool = MODE_TRADES, datetime time_start=0, bool only_loss = false) {
if(!OrderSelect(index, SELECT_BY_POS, pool)) return(0);
if(magic >= 0 && magic != OrderMagicNumber()) return(0);
if(time_start >= 0 && time_start > OrderOpenTime()) return(0);
if(is_buy >= 0 && is_buy != ((OrderType() % 2) == 0)) return(0);
if(symb != NULL && StringFind(OrderSymbol(), symb) < 0) return(0);
if(comm != NULL && StringFind(OrderComment(), comm) < 0) return(0);
if(only_loss && (OrderProfit() + OrderSwap() + OrderCommission()) >= 0) return(0);
return(OrderTicket());
}
#define IN int is_buy=-1, string symb = NULL, int magic=-1, string comm=NULL, bool is_hist=false, datetime time_start=0, bool only_loss = false
#define FOR for(int i = (is_hist?OrdersHistoryTotal():OrdersTotal())-1 ; i>=0 ; i--) { \
int tic = Sp_order_select(i, is_buy, symb, magic, comm, (is_hist?MODE_HISTORY:MODE_TRADES), time_start, only_loss);
int Fn_ord_find(IN) {
FOR if(tic > 0) return(tic); }
return(0);
}
int Fn_ord_count(IN) {
int rez = 0;
FOR if(tic > 0) rez++; }
return(rez);
}
bool Fn_ord_cls_all(int is_buy=-1, string symb = NULL, int magic=-1, string comm=NULL, datetime time_start=0, bool only_loss = false) {
const bool is_hist = false;
bool rez = true;
FOR if(!Fn_ord_cls(tic)) rez = false; }
return(rez);
}
#undef IN
#undef FOR
void _print_err(string s) { Print("ERROR! " + s); }
bool IsOkTerminal() {
static bool alrt = true;
if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)) {
string str = "Terminal trade NO allowed!";
if(alrt) { alrt = false; _print_err(str); }
return(false);
}
if(!MQLInfoInteger(MQL_TRADE_ALLOWED)) {
string str = "MQL trade NO allowed!";
if(alrt) { alrt = false; _print_err(str); }
return(false);
}
alrt = true;
return(true);
}
double NormalizeLevel(double val, bool is_up, double lev, double point, int min_dist=0) {
if(lev <= 0 || val <= 0) return(val);
int razn = (int)((is_up ? (val - lev) : (lev - val)) / point);
if(razn < min_dist) return(is_up ? (lev + min_dist * point) : (lev - min_dist * point));
return(val);
}
double NormalizeLot(string symbol, double lot, bool is_margin=true) {
if(lot <= 0) return(0);
double min = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN);
double max = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
double step = SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
double free = AccountFreeMargin();
double margin = MarketInfo(symbol, MODE_MARGINREQUIRED);
double _lot = (lot < min) ? min : ((lot > max) ? max : lot);
_lot = MathRound(_lot / step) * step;
if(is_margin && _lot * margin >= free) { _lot = MathFloor(free / margin / step) * step; }
return(_lot);
}
bool Fn_ord_set(bool is_buy, double volume, int SL, int TP, int magic, string comm, datetime time_start=0) {
if(!IsOkTerminal()) return(false);
if(!IsWithinTradingHours()) return(false);
static bool is_alert = true;
string symb = _Symbol;
int Min_SL = (int)SymbolInfoInteger(symb, SYMBOL_TRADE_STOPS_LEVEL) + 1;
int dig = (int)SymbolInfoInteger(symb, SYMBOL_DIGITS);
double point = SymbolInfoDouble(symb, SYMBOL_POINT);
for(int i = 0; (i < 5 && !IsStopped()); i++) {
if(volume <= 0) return(false);
if(time_start > 0) {
if(Fn_ord_find((int)is_buy, symb, magic, comm, false, time_start) > 0) return(true);
if(Fn_ord_find((int)is_buy, symb, magic, comm, true, time_start) > 0) return(true);
}
double pr_opn = NormalizeDouble((is_buy ? SymbolInfoDouble(symb, SYMBOL_ASK) : SymbolInfoDouble(symb, SYMBOL_BID)), dig);
double pr_cls = NormalizeDouble((is_buy ? SymbolInfoDouble(symb, SYMBOL_BID) : SymbolInfoDouble(symb, SYMBOL_ASK)), dig);
double tp = (TP <= 0) ? 0 : NormalizeDouble(NormalizeLevel((pr_opn + (is_buy ? 1 : -1) * TP * point), is_buy, pr_opn, point, Min_SL), dig);
double sl = (SL <= 0) ? 0 : NormalizeDouble(NormalizeLevel((pr_opn - (is_buy ? 1 : -1) * SL * point), !is_buy, pr_cls, point, Min_SL), dig);
double lot = NormalizeLot(symb, volume);
if(lot <= 0) { if(is_alert) { Alert("Very big lot!"); is_alert = false; } return(false); }
int tic = OrderSend(symb, (is_buy ? OP_BUY : OP_SELL), lot, pr_opn, 0, sl, tp, comm, magic);
if(tic > 0) { is_alert = true; return(true); }
else if(!Errors(GetLastError(), is_alert)) return(false);
}
return(false);
}
bool Fn_ord_cls(int ticket, double lot_close=0, string comm="") {
if(!IsOkTerminal()) return(false);
static bool is_alert = true;
for(int i = 0; (i < 5 && !IsStopped()); i++) {
if(!OrderSelect(ticket, SELECT_BY_TICKET)) return(true);
if(OrderCloseTime() > 0) return(true);
bool ans = true;
if(OrderType() == OP_BUY || OrderType() == OP_SELL) {
double pr = SymbolInfoDouble(OrderSymbol(), (OrderType() == OP_BUY ? SYMBOL_BID : SYMBOL_ASK));
double lot = (lot_close <= 0 || lot_close > OrderLots()) ? OrderLots() : NormalizeLot(OrderSymbol(), lot_close);
ans = OrderClose(ticket, lot, pr, 0);
} else {
ans = OrderDelete(ticket);
}
if(ans) { is_alert = true; if(comm != "") Print("CLOSE Order : " + comm); return(true); }
else if(!Errors(GetLastError(), is_alert)) return(false);
}
return(false);
}
bool Errors(int err, bool &alerts) {
string str = "";
bool rez = false;
switch(err) {
case 4: str = "Trade server is busy. once again..."; Sleep(500); RefreshRates(); rez = true; break;
case 128: str = "Trade timeout. once again..."; RefreshRates(); rez = true; break;
case 135: str = "Price changed. once again..."; RefreshRates(); rez = true; break;
case 136: str = "Off quotes. once again..."; RefreshRates(); rez = true; break;
case 137: str = "Broker is busy. once again..."; Sleep(500); RefreshRates(); rez = true; break;
case 138: str = "Requote. once again..."; Sleep(500); RefreshRates(); rez = true; break;
case 146: str = "Trade context is busy. once again..."; Sleep(500); RefreshRates(); rez = true; break;
case 2: str = "Common error"; rez = false; break;
case 5: str = "Old version of the client terminal"; rez = false; break;
case 6: str = "No connection with trade server"; rez = false; break;
case 64: str = "Account disabled"; rez = false; break;
case 65: str = "Invalid account"; rez = false; break;
case 129: str = "Invalid price"; rez = false; break;
case 130: str = "Invalid stops"; rez = false; break;
case 131: str = "Invalid trade volume"; rez = false; break;
case 132: str = "Market is closed"; rez = false; break;
case 133: str = "Trade is disabled"; rez = false; break;
case 134: str = "Not enough money"; rez = false; break;
case 145: str = "Modification denied because order is too close to market"; rez = false; break;
case 4109: str = "Trade is not allowed"; rez = false; break;
case 4108: str = "Invalid ticket"; rez = false; break;
default: str = "Error ord " + IntegerToString(err); rez = false; break;
}
if(str != "" && alerts) { Alert(str); alerts = false; }
return(rez);
}
//+------------------------------------------------------------------+ /*-------------------------------------------------------------------- Change-log: precentualzz_victor_EA Date: 15-03-2025 By: MwlRCT -------------------------------------------------------------------- - Moved IsWithinTradingHours() check outside the new bar condition in OnTick() to evaluate on every tick, preventing trading activity beyond specified hours (inp_trade_end_hour:inp_trade_end_min). - Added Print() statements in Fn_signal() and OnTick() to log indicator buffer values and signals, enabling debugging of trade failures on precentualzz_victor indicator signals. - Added logic in OnTick() to close all open orders using Fn_ord_cls_all() with magic number (inp_ord_magic) when outside trading hours, ensuring positions don’t persist beyond the end time. - Replaced ORDER_TYPE_BUY with OP_BUY and ORDER_TYPE_SELL with OP_SELL in Fn_ord_set() and Fn_ord_cls() to resolve MQL4 compatibility issues and fix compilation errors. - Optimized code by removing redundant checks, improving clarity and efficiency. --------------------------------------------------------------------*/
Disliked{quote} Thank you very much! There is a problem that the robot does not trade according to the indicator. Trading starts according to the time, but after an hour it does not finish trading, the robot continues. Trading started on time. The indicator closed nicely short from above. The robot did not trade. The long position closed in red. and exceeded the time. The indicator does not work. The robot does not trade. {image}Ignored