Hi I am trying to write a code to compare the price of previous bars and trigger a flag. what is wrong with this condition? It looks like the close[2]>close[3] doesnt return anything and T always become T=1 at 101000.
If time=100000 then
T=0
end if
If close[2]>close[3] and time>101000 then
T=1
Endif
It’s probably easier to say, in text, what you want to achieve?
close[2]>close[3] doesnt return anything
Abobe returns boolean logic, i.e. either 0 or 1.
close[2]>close[3] and time>101000
When close[2]>close[3] is coincident with time>101000 then T will stay at 1 until the next day at 100000 when T will become 0 for a minimum of 1 minute (until this cycle repeats).
T will become 0 for a minimum of 1 minute
Above should have read … T will become 0 for a minimum of 10 minutes.
I want to have conditions to check if for the last 3 bars the price was closing lower each time and if so then make T=1
T = summation[3](Open>Close)=3
JSParticipant
Senior
If you want to check if the last three “closes” where lower, you can also use the following code…
Including the current bar:
Close[0]<Close[1] and Close[1]<Close[2]
Or excluding the current bar:
Close[1]<Close[2] and Close[2]<Close[3]
The code will be (including the current bar):
If Time>101000 then
If Close[0]<Close[1] and Close[1]<Close[2] then
T=1
Else
T=0
EndIf
EndIf
Return T as "T"
when I use the condition in strategy for back testing it doesn’t work.
Close[0]<Close[1] and Close[1]<Close[2] doesn’t return anything
The other formula (summation) also not right because i want to compare the closes, there might be a time when close is lower than open but the close is still higher than the privous bar, i need to compare the close of each bar.
T = summation[3](Close<Close[1])=3
Above wont ‘return’ anything other than True / 1.
But then you might code …
If T = 1 Then
SellShort at Market
Endif
JSParticipant
Senior
Maybe someone else can help you…
You’re clearly a lot further along when you can judge that the formulas are wrong and not working…
Thanks but still not working. I used the below code:
if time=100000 then
TL=0
endif
TL=summation[3](close<close[1])=3
if time>101000 and time<140000 and TL=1 and countoflongshares<2 and close>open[1] then
buy 2 contracts at market
set stop loss lowest[5]-close+10
endif
if longonmarket and close<open[1] then
sell 2 contracts at market
endif
JSParticipant
Senior
The code doesn’t work because you’ve taken a strange combination of conditions…
TL=Summation[3](Close<Close[1])=3 in combination with Close>Open[1]
Try:
if time>101000 and time<140000 and TL=1 and countoflongshares<2 then