Hi all! Such a problem: I connected a custom indicator to the adviser via #resource, everything works fine except for OnTick(), this function does not work stupidly. As soon as I turn off the indicator, OnTick() starts working... Maybe someone has come across this?
...And, unfortunately, there is no indicator source code.
- New MetaTrader 5 Platform build 4150: Trading report export and new machine learning methods in MQL5
- Recursive Indicator as #resource fail to execute. (solved)
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
Maksim Neimerik:
Hi all! Such a problem: I connected a custom indicator to the adviser via #resource, everything works fine except for OnTick(), this function does not work stupidly. As soon as I turn off the indicator, OnTick() starts working... Maybe someone has come across this?
...And, unfortunately, there is no indicator source code.
Show your code if you want suggestions.
Here:
#property copyright "Copyright 2022, Maksim Neimerik" #property link "https://www.mql5.com/ru/users/istrebitel" #property version "1.00" #property strict #resource "\\Indicators\\GFX2.ex4" extern string trade="===Trade Settings===";//===Trade Settings=== extern double Lot_Size=0.01;//Lot Size extern int Magic=777;//Magic Number extern string _Comment="Your Comment";//Comment extern int EntryDelay=2;//Entry Delay (minute) extern bool Time_Filter=true;//Enable Time Filter extern string StartTime="00:00";//Start Time extern string StopTime="23:59";//Stop Time extern string gfx="===GFX2 Settings===";//===GFX2 Settings=== extern double Deviation=1.0; extern int Length=8; extern int MoneyRisk=1; int pb=0,ps=0,x=0; double UpArr=0,DnArr=0; static datetime prevtime,arrowtimeB=0,arrowtimeS=0; MqlDateTime str1,str2; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { EventSetTimer(1); ObjectCreate(0,"Label",OBJ_LABEL,0,0,0); ObjectSetString(0,"Label",OBJPROP_TEXT,"0"); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectDelete("Label"); EventKillTimer(); } //+------------------------------------------------------------------+ //| Expert Timer function | //+------------------------------------------------------------------+ void OnTimer() { x++; ObjectSetString(0,"Label",OBJPROP_TEXT,IntegerToString(x)); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { Run(); } //+------------------------------------------------------------------+ void Run() { if((Time_Filter&&TimeToStr(TimeCurrent(),TIME_MINUTES)>=StartTime&&TimeToStr(TimeCurrent(),TIME_MINUTES)<StopTime)||!Time_Filter) { if(prevtime!=Time[0]) { if(CountOrders(-1)==0) { if(GFX(0,1)!=EMPTY_VALUE&&GFX(0,0)!=EMPTY_VALUE&&GFX(4,0)>GFX(0,0)&&GFX(5,0)>GFX(0,0))OpenOrder(0,Lot_Size); if(GFX(1,1)!=EMPTY_VALUE&&GFX(1,0)!=EMPTY_VALUE&&GFX(4,0)<GFX(1,0)&&GFX(5,0)<GFX(1,0))OpenOrder(1,Lot_Size); } prevtime=Time[0]; } if(CountOrders(-1)==0) { if(GFX(3,0)!=EMPTY_VALUE) { if(pb==0){arrowtimeB=TimeCurrent();pb=1;} if(timer(arrowtimeB))OpenOrder(0,Lot_Size); } else pb=0; if(GFX(2,0)!=EMPTY_VALUE) { if(ps==0){arrowtimeS=TimeCurrent();ps=1;} if(timer(arrowtimeS))OpenOrder(1,Lot_Size); } else ps=0; } } if(CountOrders(0)!=0&&((MathMin(GFX(5,0),GFX(4,0))<=GFX(0,0))||(GFX(1,0)!=EMPTY_VALUE)))CloseOrders(0); if(CountOrders(1)!=0&&((MathMax(GFX(5,0),GFX(4,0))>=GFX(1,0))||(GFX(0,0)!=EMPTY_VALUE)))CloseOrders(1); } //+------------------------------------------------------------------+ void CloseOrders(int cmd) { int n=0; for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS)) { if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic) { RefreshRates(); if(OrderType()==cmd||cmd<0) { if(!OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),10,clrLimeGreen)) { if(n<10) { i++; n++; } } } } } } } //+------------------------------------------------------------------+ int CountOrders(int cmd) { int res=0; for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS)) { if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic&&(OrderType()==cmd||cmd<0)) res++; } } return(res); } //+------------------------------------------------------------------+ double GFX(int mode,int shift) { double res=0; res=NormalizeDouble(iCustom(_Symbol,PERIOD_CURRENT,"::Indicators\\GFX2.ex4",Deviation,Length,MoneyRisk,clrNONE,clrNONE,clrNONE,clrNONE,mode,shift),_Digits); return(res); } //+------------------------------------------------------------------+ void OpenOrder(int cmd,double lot) { int ticket=0; double Price=0; color clr=0; if(cmd==0) { clr=clrBlue; Price=NormalizeDouble(Ask,_Digits); } if(cmd==1) { clr=clrRed; Price=NormalizeDouble(Bid,_Digits); } ticket=OrderSend(_Symbol,cmd,CheckVolumeValue(NormalizeDouble(lot,2)),Price,10,0,0,"Project_185",Magic,0,clr); if(ticket<0)Print("Order not opened! Error = ",GetLastError(),". Order type=",cmd,", Order Lot=",lot,", Order open price=",Price); } //+------------------------------------------------------------------+ bool timer(datetime t) { bool res=false; TimeToStruct(TimeCurrent(),str1); TimeToStruct(t,str2); if(str1.min-str2.min>=EntryDelay)res=true; return(res); } //+------------------------------------------------------------------+ double CheckVolumeValue(double volume) { double res=volume; double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN); if(volume<min_volume) res=min_volume; double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX); if(volume>max_volume) res=max_volume; double volume_step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP); int ratio=(int)MathFloor(volume/volume_step); if(MathAbs(ratio*volume_step-volume)>0.0000001) res=NormalizeDouble(ratio*volume_step,2); return(res); }
Here is the indicator:
<ex4 file deleted>Why was the indicator file deleted?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register