JJF:
Is there a command to transfer that var to a 'command type' string?
James
Just do it manually:
int
getPeriod(string pPeriod) {
if (pPeriod="PERIOD_H4") return PERIOD_H4
else if (pPeriod="PERIOD_H1") return PERIOD_H1
etc....
}
HTH,
--
Luke
ChartsAccess.com - metatrader charts in any phone.
- example: I extract a string from the trade comment, let's say it is 'PERIOD_H4' into var 'timeFrame'
int textToPeriod(string text){ int TFperiod[] = { PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1 }; string TFtext[] = { "PERIOD_M1","PERIOD_M5","PERIOD_M15","PERIOD_M30", "PERIOD_H1","PERIOD_H4","PERIOD_D1", "PERIOD_W1", "PERIOD_MN1" }; for(int index=8; index >= 0; index--) if (TFtext[index] == text) // Or use stringFind(text, TFtext[index])>=0 return(TFperiod[index]); return(-1); // Invalid }
- But it's Not a good idea, brokers can change comments, including complete replacement. Instead I'd use a range of magic numbers.
extern int Magic.Number.Base = 20110202; int magic.number; int magic.number.last; int TFperiod[] = { PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1 }; int init(){ magic.number.last = Magic.Number.Base + 8; for(int index=0;; index++) if (TFperiod[index]==Period()){ magic.number = Magic.Number.Base + index; break; } } ... for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() >= Magic.Number.Base // my magic number && OrderMagicNumber() <= magic.number.last // my magic number && OrderSymbol() == Symbol() ){ // and my pair. int period = TFperiod[OrderMagicNumber() - Magic.Number.Base]; ...

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
I would like simplify my EA and use a string made var as the timeFrame value in a eMA formula.