![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Hey, I've got a question for some really good metatrader programmers. In my EA, I switch between timeframes depending on a function. If the EA determines I should be using the 15 minute timeframes, then it calls on RangePrefetch() right after start(). If I should be using 1-hour charts, then the EA calls on TrendPrefetch() right after start(). Both RangePrefetch() and TrendPrefetch() are the exactly the same except for the period, and they're defined and right after init().
The problem is because of this switching back and forth between timeframes, it takes considerably longer to test it and optimize it. So I'm wondering if there's some way of rearranging the code or just coding it a more efficient way so it all runs much quicker. thanks a lot.
string Trend,Buy,Sell,TradeComm;
double Close1,Close2,Close3,Close4,Close5,Close6,Open1,Open2,Open3,Open4,Open5,Open6,
Fast1,Fast2,Fast3,Fast4,Fast5,Fast6,Slow1,Slow2,Slow3,Slow4,Slow5,Slow6,
Average,FastW,Currency_momentumA,Currency_momentumB,Currency_momentumC,
Trend_momentumFastA,Trend_momentumFastB,Trend_momentumFastC,Trend_momentumFastD,
Trend_momentumSlowA,Trend_momentumSlowB,
Width1,Width2,Width3,Width4,Width5,Width6,
WidthW1,WidthW2,WidthW3,WidthW4,WidthW5,WidthW6,
FastTrend,SlowTrend;
int Trendd,MaxpipfromEMA,Ranging,RangingS,TFTime;
void TrendPreFetch()
{
Average=iMA(NULL,PERIOD_H1,3,0,MODE_EMA,PRICE_CLOSE,1);
FastW=iMA(NULL,PERIOD_H1,fastma*3.8,0,MODE_EMA,PRICE_CLOSE,1);
Currency_momentumA=iCustom(NULL,PERIOD_H1,"OSMAMA",4,6,currency_momentum,1,currency_momentum,0,1);
Currency_momentumB=iCustom(NULL,PERIOD_H1,"OSMAMA",4,6,currency_momentum,1,currency_momentum,1,1);
Currency_momentumC=iCustom(NULL,PERIOD_H1,"OSMAMA",4,6,currency_momentum,1,currency_momentum,0,5);
Trend_momentumFastA=iCustom(NULL,PERIOD_H1,"OSMAMA",4,6,trend_momentum,1,trend_momentum,0,1);
Trend_momentumFastB=iCustom(NULL,PERIOD_H1,"OSMAMA",4,6,trend_momentum,1,trend_momentum,0,2);
Trend_momentumFastC=iCustom(NULL,PERIOD_H1,"OSMAMA",4,6,trend_momentum,1,trend_momentum,0,3);
Trend_momentumFastD=iCustom(NULL,PERIOD_H1,"OSMAMA",4,6,trend_momentum,1,trend_momentum,1,1);
Trend_momentumSlowA=iCustom(NULL,PERIOD_H1,"OSMAMA",6,8,slowma*3,currency_momentum*3,currency_momentum*3,0,1);
Trend_momentumSlowB=iCustom(NULL,PERIOD_H1,"OSMAMA",6,8,slowma*3,currency_momentum*3,currency_momentum*3,0,5);
}
void RangePreFetch()
{
Average=iMA(NULL,PERIOD_M15,3,0,MODE_EMA,PRICE_CLOSE,1);
FastW=iMA(NULL,PERIOD_M15,fastma*3.8,0,MODE_EMA,PRICE_CLOSE,1);
Currency_momentumA=iCustom(NULL,PERIOD_M15,"OSMAMA",4,6,currency_momentum,1,currency_momentum,0,1);
Currency_momentumB=iCustom(NULL,PERIOD_M15,"OSMAMA",4,6,currency_momentum,1,currency_momentum,1,1);
Currency_momentumC=iCustom(NULL,PERIOD_M15,"OSMAMA",4,6,currency_momentum,1,currency_momentum,0,5);
Trend_momentumFastA=iCustom(NULL,PERIOD_M15,"OSMAMA",4,6,trend_momentum,1,trend_momentum,0,1);
Trend_momentumFastB=iCustom(NULL,PERIOD_M15,"OSMAMA",4,6,trend_momentum,1,trend_momentum,0,2);
Trend_momentumFastC=iCustom(NULL,PERIOD_M15,"OSMAMA",4,6,trend_momentum,1,trend_momentum,0,3);
Trend_momentumFastD=iCustom(NULL,PERIOD_M15,"OSMAMA",4,6,trend_momentum,1,trend_momentum,1,1);
Trend_momentumSlowA=iCustom(NULL,PERIOD_M15,"OSMAMA",6,8,slowma*3,currency_momentum*3,currency_momentum*3,0,1);
Trend_momentumSlowB=iCustom(NULL,PERIOD_M15,"OSMAMA",6,8,slowma*3,currency_momentum*3,currency_momentum*3,0,5);
}
int start()
{
double Averagepips,Opentime,Stopip;
int i,open,Spike,SpikeW,Buyjump,Selljump,BuyjumpR,SelljumpR,Ticket,Cnt,Can;
double SlowTrend=iMA(NULL,PERIOD_H1,slowma,0,MODE_EMA,PRICE_CLOSE,1);
double FastTrend=iMA(NULL,PERIOD_H1,fastma,0,MODE_EMA,PRICE_CLOSE,1);
if((MathAbs(FastTrend-SlowTrend)>RangePoint*Point))
{
RangingS=2;
}
else
{
RangingS=1;
}
if((TFTime!=iTime(Symbol(),PERIOD_M15,1)) && (RangingS==1))
{
RangePreFetch();
MaxpipfromEMA=MaxpipfromEMAM;
Ranging=1;
TFTime=iTime(Symbol(),PERIOD_M15,1);
}
if((TFTime!=iTime(Symbol(),PERIOD_H1,1)) && (RangingS==2))
{
TrendPreFetch();
MaxpipfromEMA=MaxpipfromEMAH;
Ranging=0;
TFTime=iTime(Symbol(),PERIOD_H1,1);
}