if(TimeMonth(Time[i])==2 && TimeDay(Time[i]) >=19 && TimeHour(Time[i])>=16 && (TimeHour(Time[i])<=21 && TimeMinute(Time[i])<=45))
This will be false before Feb 19 16:00, 16:46-16:59, 17:46-17:59, 18:46-18:59, 18:46-18:59, 19:46-19:59, 20:46-20:59, and after 20:45
Thanks for that.
This helped to work out how to get the line to be drawn at the right level too.
I now have the below code:
i=Bars; while(i>=0) { //Trading starts at 15.30 server time. This system ignores the first hour of trading. if(TimeMonth(Time[i])==2 && TimeDay(Time[i]) >=19 && TimeHour(Time[i])>=16) { if(TradingOpen==false) { text+="Trading open: "+TimeDay(Time[i])+"/"+TimeMonth(Time[i])+"/"+TimeYear(Time[i]); OpenBar=i; text+="\nOpenBar: "+OpenBar; TradingOpen=true; } text+="\ni: "+i; text+="\nBars since open bar: "+(OpenBar-i); HOD_Index=iHighest(Symbol(),TimeFrame,MODE_HIGH,OpenBar-i,i+1); text+="\nHOD_Index: "+HOD_Index; HOD=High[HOD_Index]; text+="\nHOD: "+HOD; Hv[i+1]=HOD; } else if(TimeMonth(Time[i])==2 && TimeDay(Time[i]) >=19 && TimeHour(Time[i]>=21) && TimeMinute(Time[i])>=45) { //text+="\nTrading closed"; TradingOpen=false; } Comment(text); i--; }
which looks like:
That's what I want but when I apply it with the below code, which is the same except it starts a day earlier:
i=Bars; while(i>=0) { //Trading starts at 15.30 server time. This system ignores the first hour of trading. if(TimeMonth(Time[i])==2 && TimeDay(Time[i]) >=18 && TimeHour(Time[i])>=16) { if(TradingOpen==false) { text+="Trading open: "+TimeDay(Time[i])+"/"+TimeMonth(Time[i])+"/"+TimeYear(Time[i]); OpenBar=i; text+="\nOpenBar: "+OpenBar; TradingOpen=true; } text+="\ni: "+i; text+="\nBars since open bar: "+(OpenBar-i); HOD_Index=iHighest(Symbol(),TimeFrame,MODE_HIGH,OpenBar-i,i+1); text+="\nHOD_Index: "+HOD_Index; HOD=High[HOD_Index]; text+="\nHOD: "+HOD; Hv[i+1]=HOD; } else if(TimeMonth(Time[i])==2 && TimeDay(Time[i]) >=18 && TimeHour(Time[i]>=21) && TimeMinute(Time[i])>=45) { //text+="\nTrading closed"; TradingOpen=false; } Comment(text); i--; }
this happens:
The line for the first trading day is correct.
The line for the second day should be same as the first screen shot, but picks up on the same level as the previous trading day.
Since OpenBar is assigned a new value every trading day, I think this should work.
Regards and thanks.
TradingOpen doesn't get set to false.
There is a last bug I'm having trouble finding, or don't know how to find.
The indicator draws these long vertical lines at the start of each session.
Looks like some how the first value that prints out for the session is huge.
It looks like this.
i=Bars; while(i>=0) { //Trading starts at 15.30 server time. This system ignores the first hour of trading. //else if(TimeMonth(Time[i])==2 && TimeDay(Time[i]) >=18 && TimeHour(Time[i])>=16) if(TimeToStr(Time[i],TIME_MINUTES)>="16:00" && TimeToStr(Time[i],TIME_MINUTES<="21:45")) { if(TradingOpen==false) { OpenBar=i; TradingOpen=true; } //text+="\ni: "+i; //text+="\nBars since open bar: "+(OpenBar-i); HOD_Index=iHighest(Symbol(),TimeFrame,MODE_HIGH,OpenBar-i,i+1); LOD_Index=iLowest(Symbol(),TimeFrame,MODE_LOW,OpenBar-i,i+1); //text+="\nHOD_Index: "+HOD_Index; HOD=High[HOD_Index]; LOD=Low[LOD_Index]; text+="\nHOD: "+HOD; Hv[i+1]=HOD; Lv[i+1]=LOD; } else { //text+="\nTrading closed"; TradingOpen=false; } Comment(text); i--; }
Could you please assist/advise?
You are mixing apples and oranges HOD_Index=iHighest(Symbol(),TimeFrame,MODE_HIGH,OpenBar-i,i+1); LOD_Index=iLowest(Symbol(),TimeFrame,MODE_LOW,OpenBar-i,i+1); HOD=High[HOD_Index]; LOD=Low[LOD_Index];
- What happens when OpenBar == i?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi there,
I've had a poke around and not found what I'm looking for.
I'm trying to create an indicator that draws a line along the prevailing HOD level during the trading session.
In the code below I've limited the indicator to work only since the most recent trading day of posting for testing.
I thought the simplest way would be to draw the highest price since the index of the bar at the start of the trading session.
I'm getting results I don't understand.
The result this displays is:
From the comments printed it appears the OpenBarSet keeps getting set to false somehow.
Why is the HOD_Index always 1?
It looks like the indicator is drawing something between the right times, but there are spaces because OpenBarSet gets set to false.
The drawing should appear at the horizontal line, and should increase with the higher highs of the day, but instead appears way above it.
Can you please assist/advice re the above issues?
Kind regards and thanks.