Hello and thanks for you time! I have this problem with all the candle pattern EAs, when i backtest them at daylie timeframes and they have to open a trade at open price the trade doesnt open, at 8H timeframes and lower i dont have this problem, so maybe there is a problem with opening trade at open price? Do you have any solution for that? I post an example of the code.
- Daily timeframe backtest doesn't work
- problem with take profit
- 100% drawdown at the end of backtesting
Maybe that is because new daily candle open coincides with brokers' rollover time.
any idea how can i put a timer condition if the candle patern is true?
Emmanouil Bampalos #:
any idea how can i put a timer condition if the candle patern is true?
any idea how can i put a timer condition if the candle patern is true?
try this :
#include <Trade\Trade.mqh> input double Lots = 0.1; input int TakeProfit = 1000; input int StopLoss = 500; input ENUM_TIMEFRAMES Timeframe = PERIOD_D1; input long IntervalMinSecs=60;//Minimum interval between trade attempts int barsTotal; CTrade trade; int OnInit(){ LINTRADE.reset(); barsTotal = iBars(_Symbol,Timeframe); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ } void OnTick(){ int bars = iBars(_Symbol,Timeframe); if(barsTotal != bars){ barsTotal = bars; double open1 = iOpen(_Symbol,Timeframe,1); double close1 = iClose(_Symbol,Timeframe,1); double open2 = iOpen(_Symbol,Timeframe,2); double close2 = iClose(_Symbol,Timeframe,2); double open3 = iOpen(_Symbol,Timeframe,3); double close3 = iClose(_Symbol,Timeframe,3); double open4 = iOpen(_Symbol,Timeframe,4); double close4 = iClose(_Symbol,Timeframe,4); double open5 = iOpen(_Symbol,Timeframe,5); double close5 = iClose(_Symbol,Timeframe,5); if(open1 > close1 && open2 > close2 && open3 > close3 && open4 > close4 && open5 < close5){ LINTRADE.arm_buy(); }else if(open1 < close1 && open2 < close2 && open3 < close3 && open4 < close4 && open5 > close5){ LINTRADE.arm_sell(); } } LINTRADE.check(TimeTradeServer(),IntervalMinSecs); } //lingering trade struct linTrade{ char direction;//0 none -1 sell 1 buy datetime latestAttempt;//time of last attempt bool armed; linTrade(void){reset();} ~linTrade(void){reset();} void reset(){ direction=0; latestAttempt=0; armed=false; } void arm_buy(){ direction=1; armed=true; } void arm_sell(){ direction=-1; armed=true; } void check(datetime time_now,long interval_min_secs){ //if it is armed if(armed){ long diff=((long)time_now)-((long)latestAttempt); //if enough time has passed since last attempt if(diff>=interval_min_secs){ ResetLastError(); int errors=0; double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK); errors+=GetLastError(); ask = NormalizeDouble(ask,_Digits); ResetLastError(); double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID); errors+=GetLastError(); bid = NormalizeDouble(bid,_Digits); //if no errors if(errors==0){ //buy if(direction==1){ double tp = ask + TakeProfit * _Point; tp = NormalizeDouble(tp,_Digits); double sl = ask - StopLoss * _Point; sl = NormalizeDouble(sl,_Digits); if(trade.Buy(Lots,_Symbol,ask,sl,tp)){ reset(); }else{ latestAttempt=time_now; } } //sell if(direction==-1){ double tp = bid - TakeProfit * _Point; tp = NormalizeDouble(tp,_Digits); double sl = bid + StopLoss * _Point; sl = NormalizeDouble(sl,_Digits); if(trade.Sell(Lots,_Symbol,bid,sl,tp)){ reset(); }else{ latestAttempt=time_now; } } } //if no errors ends here }//if enough time has passed since last attempt ends here }//if armed ends here } }; linTrade LINTRADE;
WHAT KIND OF SORCERY IS THAT? :D thx a lot!!!

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