tavParticipant
Junior
How do I define a variable in the morning before trading?
I would like variable traded=0 each morning until a trade has occured then traded=1 for rest of trading day.
You must first decide what is your trading time.
Example if you only want to have the variable “traded” set between 10:00:00 and 19:00:00, each day (of course this won’t work in a Daily, or greater, timeframe):
ONCE StartTime = 100000
ONCE EndTime = 190000
ONCE Traded = 0
IF (time < StartTime) OR (time > EndTime) THEN
Traded = 0
ELSE
Traded = 1
ENDIF
Roberto
tavParticipant
Junior
ok thank you. I have it as you have shown it but I want trade=1 when another condition is fulfilled ie when a trade has happened. The problem I’m facing is traded randomly sets to 1 just before the condition is fulfilled usuallyjsut before DEFPARAM FlatBefore = 080500. |Does DEFPARAM FlatBefore affect variable initialisation?
DEFPARAM FlatBefore does not affect variables, it affects conditions, though, because trades will not be triggered even if all conditions are met (but variables still retain their values as set at each new bar).
To combine other conditions you may add them as follows:
ONCE StartTime = 100000
ONCE EndTime = 190000
ONCE Traded = 0
IF (time < StartTime) OR (time > EndTime) THEN
Traded = 0
ELSEIF (conditions) THEN // you may add other conditions here
Traded = 1
ENDIF