Menu
Brokers
MT4 Forex Brokers
MT5 Forex brokers
PayPal Brokers
Skrill Brokers
Oil Trading Brokers
Gold Trading Brokers
Web Browser Platform
Brokers with CFD Trading
ECN Brokers
Bitcoin FX Brokers
PAMM Forex Brokers
With Cent Accounts
With High Leverage
Cryptocurrency Brokers
Forums
All threads
New threads
New posts
Trending
Search forums
What's new
New threads
New posts
Latest activity
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Reply to thread
Forums
Trading Platforms
MetaTrader Expert Advisors
[MQL4 Code Help] Converting If else condition to function for more indicator & Time-frame flexibility
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
[QUOTE="shanmugapradeep, post: 242656, member: 70475"] Thanks for verifying. I tested again and it look working. [B]Code 1 : [/B] [CODE=mql4]void CheckMovingAverageConditions() { gMovingAverageSignal = "NoSignal"; bool conditionsUp[7], conditionsDown[7]; ENUM_TIMEFRAMES periods[7]; int count = 0; if(PeriodM1) periods[count++] = PERIOD_M1; if(PeriodM5) periods[count++] = PERIOD_M5; if(PeriodM15) periods[count++] = PERIOD_M15; if(PeriodM30) periods[count++] = PERIOD_M30; if(PeriodH1) periods[count++] = PERIOD_H1; if(PeriodH4) periods[count++] = PERIOD_H4; if(PeriodD1) periods[count++] = PERIOD_D1; if(count == 0) return; // Exit if no timeframes are selected bool allTrueUp = true, allTrueDown = true; double bidPrice = MarketInfo(gRandomSymbol, MODE_BID); double askPrice = MarketInfo(gRandomSymbol, MODE_ASK); for(int i = 0; i < count; i++) { double MA_Value = iMA(gRandomSymbol, periods[i], MovingAverage_Period, MovingAverage_MAShift, MovingAverage_Method, MovingAverage_AppliedPrice, MovingAverage_Shift); conditionsUp[i] = (bidPrice > MA_Value); conditionsDown[i] = (askPrice < MA_Value); allTrueUp &= conditionsUp[i]; // If any condition is false, allTrueUp becomes false allTrueDown &= conditionsDown[i]; // If any condition is false, allTrueDown becomes false } if(allTrueUp) gMovingAverageSignal = "ABOVE"; if(allTrueDown) gMovingAverageSignal = "BELOW"; }[/CODE] [B]Code 2 : [/B] [CODE=mql4]void CheckMovingAverageConditions() { gMovingAverageSignal = "NoSignal"; ENUM_TIMEFRAMES periods[7]; int count = 0; if(PeriodM1) periods[count++] = PERIOD_M1; if(PeriodM5) periods[count++] = PERIOD_M5; if(PeriodM15) periods[count++] = PERIOD_M15; if(PeriodM30) periods[count++] = PERIOD_M30; if(PeriodH1) periods[count++] = PERIOD_H1; if(PeriodH4) periods[count++] = PERIOD_H4; if(PeriodD1) periods[count++] = PERIOD_D1; if(count == 0) return; // Exit if no timeframes are selected bool allTrueUp = true, allTrueDown = true; double bidPrice = MarketInfo(gRandomSymbol, MODE_BID); double askPrice = MarketInfo(gRandomSymbol, MODE_ASK); for(int i = 0; i < count; i++) { double MA_Value = iMA(gRandomSymbol, periods[i], MovingAverage_Period, MovingAverage_MAShift, MovingAverage_Method, MovingAverage_AppliedPrice, MovingAverage_Shift); if(bidPrice <= MA_Value) allTrueUp = false; // If any fails, set allTrueUp to false if(askPrice >= MA_Value) allTrueDown = false; // If any fails, set allTrueDown to false } if(allTrueUp) gMovingAverageSignal = "ABOVE"; else if(allTrueDown) gMovingAverageSignal = "BELOW"; } [/CODE] Is code 1 and code 2 do exactly same operation? Checking indicator according different timeframe together? If, both do same function, which one should i use for better performance, speed execution and accuracy? [/QUOTE]
Insert quotes…
Verification
Post reply
Top
Bottom
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…