static datetime next_check = 0; datetime time_now = TimeCurrent(); if(time_now >= next_check) { // put your code in here next_check = time_now + 300; // 5 minutes = 300 seconds }
excuse me , i don't understand where i have to put my code .
excuse me , i don't understand where i have to put my code .
You need to put the code you want to be run every 5 minutes in the section I marked "// put your code in here"
In your case, probably something like this:
static datetime next_check = 0; datetime time_now = TimeCurrent(); if(time_now >= next_check) { val=iStochastic(Symbol(),timeframe,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,STO_CLOSECLOSE,MODE_MAIN,Shift); next_check = time_now + 300; // 5 minutes = 300 seconds }
If you want it to check on the open of a new M5 bar (rather than 5 minutes from when you last called the function), the code looks a little different:
static datetime last_M5 = 0; datetime this_M5 = iTime(_Symbol,PERIOD_M5,0); if(this_M5 != last_M5) { val=iStochastic(Symbol(),timeframe,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,STO_CLOSECLOSE,MODE_MAIN,Shift); this_M5 = last_M5; }
You need to put the code you want to be run every 5 minutes in the section I marked "// put your code in here"
In your case, probably something like this:
If you want it to check on the open of a new M5 bar (rather than 5 minutes from when you last called the function), the code looks a little different:
//Controllo stocastico ogni 5 minuti double StochValue(ENUM_TIMEFRAMES timeframe,int buffer) { double val; static datetime last_M5 = 0; datetime this_M5 = iTime(_Symbol,PERIOD_M5,0); if(this_M5 != last_M5 && buffer==0 ) { val=iStochastic(Symbol(),timeframe,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,STO_CLOSECLOSE,MODE_MAIN,Shift); this_M5 = last_M5; // 5 minutes = 300 seconds } if(this_M5 != last_M5 && buffer==1 ) { val=iStochastic(Symbol(),timeframe,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,STO_CLOSECLOSE,MODE_SIGNAL,Shift); this_M5 = last_M5; // 5 minutes = 300 seconds } return(val); }
or here is a better idea ?
void FindSignal() { if(dayfilter()==1 && WorkingHour(1)==true && ContinueTrading==true) { if(TimeFrame1==true && trade1==1) { if(GetTime(TF1,9) != EMPTY_VALUE) LastSellSignalTF1 = GetTime(TF1,9); if(GetTime(TF1,7) != EMPTY_VALUE) LastBuySignalTF1 = GetTime(TF1,7); if(RSIDiv(TF1,0)>0 && RSIDiv(TF1,0)!=EMPTY_VALUE && (MMRange(TF1,0)==true || useMM==false) && StochValue(StochTF1,0)>StochValue(StochTF1,1)+StochDelta && iStochastic(NULL,StochTF1,5,3,3,MODE_SMA,STO_CLOSECLOSE,MODE_MAIN,0)>20 && GetTime(TF1,6)>LastSellSignalTF1 && Bid<iHigh(Symbol(),TF1,2)) { lastTime=(int)(GetTime(TF1,7)-GetTime(TF1,6)); OrderEntry(0,"TF1 Trade",lastTime); trade1=0; int timen=(int)TimeCurrent(); }
Thank you very much.
You need to put the code you want to be run every 5 minutes in the section I marked "// put your code in here"
In your case, probably something like this:
If you want it to check on the open of a new M5 bar (rather than 5 minutes from when you last called the function), the code looks a little different:
i need that ea check stochastic value when new bar at m5 is opened and memorize it . So i can compare kline and dline and set the order, because stochastic value change anytime so there is too flase signal. Thank you.
i need that ea check stochastic value when new bar at m5 is opened and memorize it . So i can compare kline and dline and set the order, because stochastic value change anytime so there is too flase signal. Thank you.
Perhaps there is an easier approach.
All you need to do is check the M5 stochastic value from the (end of) the previous M5 bar.
This is always easily accessible so no need to store the value or worry about times
double M5_stoch = iStochastic(_Symbol,PERIOD_M5,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,STO_CLOSECLOSE,MODE_MAIN,1);
Or, only check for your signal once per bar.
Perhaps there is an easier approach.
All you need to do is check the M5 stochastic value from the (end of) the previous M5 bar.
This is always easily accessible so no need to store the value or worry about times
Or, only check for your signal once per bar.
ok but it is a problem if the kline cross dline because the ea still use the old direction .
ok but it is a problem if the kline cross dline because the ea still use the old direction .
I'm sorry, I don't understand what you mean.
What is your exact criteria for opening a trade?
I'm sorry, I don't understand what you mean.
What is your exact criteria for opening a trade?
my ea check rsi divergence on tf m1 and use stochastic on tf m5 as confirmation .
my ea check rsi divergence on tf m1 and use stochastic on tf m5 as confirmation .
void OnTick() { if(/*your code to check for RSI divergence buy*/ && StochConfirmation(OP_BUY)) OrderSend(_Symbol,OP_BUY ...) if(/*your code to check for RSI divergence sell*/ && StochConfirmation(OP_SELL)) OrderSend(_Symbol,OP_SELL ...) } bool StochConfirmation(int order_type) { double M5_main = iStochastic(_Symbol,PERIOD_M5,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,STO_CLOSECLOSE,MODE_MAIN,1), M5_signal = iStochastic(_Symbol,PERIOD_M5,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,STO_CLOSECLOSE,MODE_SIGNAL,1); if(order_type==OP_BUY && M5_signal > M5_main) return(true); if(order_type==OP_SELL && M5_signal < M5_main) return(true); return(false); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need that my ea check stochastic value only every 5 minutes . So i wrote like this :
....
But it seems that it doesn't work. I use timeframe m5 on mt4 hoping that in this way it will check only every new bar .
Thanks.