//--- period detector switch(Period()) { case PERIOD_M1: //Do Something... break; case PERIOD_M5: //Do Something... break; case PERIOD_M15: //Do Something... break; case PERIOD_M30: //Do Something... break; case PERIOD_H1: //Do Something... break; case PERIOD_H4: //Do Something... break; case PERIOD_D1: //Do Something... break; case PERIOD_W1: //Do Something... break; case PERIOD_MN1: //Do Something... break; } //---
is not possible use if ?
Of course it is.
i use this costruct
if((TimeFrameChoice!=PERIOD_W1)||(TimeFrameChoice!=PERIOD_MN1)||(TimeFrameChoice!=PERIOD_D1))
but not respect it
I have no idea what you are trying to do.
If you want to check the TimeFrame use Period();
is simple code when attach indicator choice by menu a time frame with this code
sinput ENUM_TIMEFRAMES TimeFrameChoice=PERIOD_CURRENT;// Timeframe
after choice if you choice weekle dayly or monthly
popup error message and detach indicator
void OnInit() { IndicatorShortName("Screener"); Print ("il periodo e questo "+TimeFrameChoice); if((TimeFrameChoice!=PERIOD_W1)||(TimeFrameChoice!=PERIOD_MN1)||(TimeFrameChoice!=PERIOD_D1)) { if(Period() != TimeFrameChoice) { ChartSetSymbolPeriod(0,Symbol(),TimeFrameChoice); // imposto il timeframe } } else { MessageBox("Non puoi usare il daily e il weekly e il montly "); bool RetKill=ChartIndicatorDelete(0,0,"Screener"); } }
sinput ENUM_TIMEFRAMES TimeFrameChoice=PERIOD_CURRENT;// Timeframe void OnInit(){ if(( TimeFrameChoice!=10080)||(TimeFrameChoice!=43200)||(TimeFrameChoice!=1440)){ if(Period() != TimeFrameChoice) {
- PERIOD_CURRENT is the value of zero. It will always be not equal to Period().
ENUM_TIMEFRAMES tfc = TimeFrameChoice == PERIOD_CURRENT ? ENUM_TIMEFRAMES(_Period) : TimeFrameChoice; if(Period() != tfc) // if(Period() != TimeFrameChoice)
- Don't hard code numbers, use the enumeration.
thankz but continue to not understund , because suppose
ENUM_TIMEFRAMES tfc = TimeFrameChoice == PERIOD_CURRENT ? ENUM_TIMEFRAMES(_Period) : TimeFrameChoice; if(Period() != tfc) // if(Period() != TimeFrameChoice)
the user change timeframe at 1day tfc = 1 day , this condition is true
if(Period() != tfc)
but if user choice M5 also in this case is true
if(Period() != tfc)
i resolve in this mode
enum TimeFrame { Time_Frame_1M = PERIOD_M1, Time_Frame_5M = PERIOD_M5, Time_Frame_15M = PERIOD_M15, Time_Frame_30M = PERIOD_M30, Time_Frame_1H = PERIOD_H1, Time_Frame_4M = PERIOD_H4, }; extern TimeFrame TimeFrameChoice = PERIOD_H1; //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ void OnInit() { if(Period() != TimeFrameChoice) { ChartSetSymbolPeriod(0,Symbol(),TimeFrameChoice); // imposto il timeframe } }
much simple much easy to understund and do not have a cicle and more
static input ENUM_TIMEFRAMES TimeFrameChoice = PERIOD_H1;// Choose Timeframe //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ void OnInit() { if(Period() != TimeFrameChoice ) { ChartSetSymbolPeriod(0,Symbol(),TimeFrameChoice); // imposto il timeframe } }
Marco vd Heijden:
Doesn't work if the variable is set to PERIOD_CURRENT and that is what OP originally had.
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
hi guys i try to compare the time frame for exclude 3 type of time frame but not work i tryed also with use a second like but nothing , whats wrong ?