transfer a string var to a 'command type'?

 
Hi Guys
,

I would like simplify my EA and use a string made var as the timeFrame value in a eMA formula.

example: I extract a string from the trade comment, let's say it is 'PERIOD_H4' into var 'timeFrame'

Now I want to use that var in the eMA formula like this:

iMA(Symbol(),timeFrame,14,0,1,0,0);

It doesn't work. The eMA formula won't accept that var (it consider it a zero)

Is there a command to transfer that var to a 'command type' string?


James
 
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.

 
  1. 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
    }
    

  2. 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];
            ...
Reason: