When I tried to trade on demo account my codes do not place trades.
However, everything seems fine on Strategy Tester.
No errors in Expert Tab or Logs. Yes the code compiles
I played around with your code, rewriting it as follows for easier debugging:
timeToTrade = TimeToTrade() ; isCandleNew = IsNewCandle(); if(isCandleNew) { DebugBreak(); if(previous_low < MA[0] && current_low > MA[0] && Ask > MA[0] && timeToTrade) { m_trade.Buy(1,_Symbol,0,StopLossLevelBUY,TakeProfitLevelBUY,NULL); DebugBreak(); } if(previous_high > MA[0] && current_high < MA[0] && Bid < MA[0] && timeToTrade) { m_trade.Sell(1,_Symbol,0,StopLossLevelSELL,TakeProfitLevelSELL,NULL); DebugBreak(); } }
Your IsNewCandle() is working fine, so I commented it out to make it easier to debug the remaining statements.
I then commented out your other if statements to check the m_trade functions - they seem to work fine and are creating trades.
So the issue is that your next if statements are rarely evaluating to true (if ever - they never did during my tests) - that's why you are not getting trades.
if(previous_low < MA[0] && current_low > MA[0] && Ask > MA[0] && timeToTrade) { } if(previous_high > MA[0] && current_high < MA[0] && Bid < MA[0] && timeToTrade) { }
As they are complicated if statements with 4 terms (16 possible outcomes of which only 1 can be true), it can be hard to analyse. So I suggest breaking these down into simpler steps and debugging to figure out how to fix the logic to what you want it to be.
I would suggest removing TimeToTrade() for the time being so you can focus on fixing the high/low Ask/Bid comparisons in isolation.
My leaning would be to separate the timing conditions from the financial ones
if((isCandleNew) && (timeToTrade)) { //financial computations }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
When I tried to trade on demo account my codes do not place trades.
However, everything seems fine on Strategy Tester.
No errors in Expert Tab or Logs. Yes the code compiles