LordTwig wrote:1) If I want to use 10 periods before end of day (instead of the (1 period) used here), which values do I only change?
1).1) Can it be easily made into user selectable choice?
The 10th period before the end is
- Code: Select all
l = e - currLength * 10;
So, the check for the current candle is after the l candle but before the end of the day is
- Code: Select all
if c >= l and c < e then
...
LordTwig wrote:2) Also, lets say I need the same to happen again, but at a different earlier time ((so twice) for different condition) but 10 hours before, How would that effect the code, ie, can I use most of it or do I have to write it as though it was separate from each other?
example: trigger for a possible trade activated, but 10 hours pass by and no Buy or Sell is activated, so I want to stop trade taking place after this amount of time(10 Hours). and preferably user settable any time amount.
Just remember the time of the start and then check it against the current time. Let's suggest that the Marketscope time is converted to the seconds, i.e. via math.floor(x * 86400 + 0.5).
So, the check is
- Code: Select all
-- 10 hours is 10 x 60 (minutes) x 60 (seconds) = 36000
if currentTime - startTime >= 36000 then
...
LordTwig wrote:Is there any way to use Time format (HH:MM:SS) for any of this (or convert what you have done to easily use Time formats), so it can be used several times throughout the same indicator?
for example, if EndDay >= 16:59:59 then....
or if StopTrade >= 5:00:00 then .....
or ...... and so on.
There is no such datatype as a time in lua (as well as in the most programming languages, even used for the trading. So, nohow. However, you can a couple of simple functions such as:
- Code: Select all
function hms_seconds(hour, minute, seconds)
return hour * 60 * 60 + minute * 60 + seconds;
end
...
function date_seconds(date)
return math.floor(date * 86400 + 0.5);
end
So, if you wanna check whether the current candle is more than 5 hours 12 minutes and 35 seconds past the collection start, just use:
- Code: Select all
if date_second(source:date(period)) - date_second(source:date(0)) > hms_seconds(5, 12, 35) then