Hi,
I want to trade a level only once and do not want to enter the trade same level twice. But below code isn’t working:
RTHoperate = (TIME > 142000 AND TIME < 203000) // GMT+1
if time < 143000 then
spread = 2
else
spread = 1
endif
MyLongPrice = round(max(myBarLower, myBarUpper))
distance = abs(myBarHigh – myBarLow)
if NOT ONMARKET and RTHoperate and close > MyLongPrice then and (MyLongPrice <> tradeprice[1]) then
SET STOP PLOSS distance + spread
set target pprofit distance*20
endif
Above code (if no market …) keep rentering the same location.
2nd question: If i want to go long using the same myLongPrice twice, what protection I can put in the code?
Regards
Ash
You can use the previous entry price exactly, but the two prices are unlikely to be identical, even to the decimal point!
This example divides the price by 100 (but you can change it to 50 or 10, etc…), in this way it is easy for the price of the new entry to be in the same range as the previous one and therefore the entry is not made:
DEFPARAM CUMULATEORDERS = False
ONCE myDivisor = 100
ONCE EntryLevel = 0
myLONGconditions = close CROSSES OVER Average[20,0](close)
mySHORTconditions = close CROSSES UNDER Average[20,0](close)
CurrentLevel = round(close / myDivisor,0)
IF Not OnMarket AND CurrentLevel <> EntryLevel THEN
IF myLONGconditions THEN
BUY 1 Contract AT MARKET
EntryLevel = round(close / myDivisor,0)
ELSIF mySHORTconditions THEN
SELLSHORT 1 Contract AT MARKET
EntryLevel = round(close / myDivisor,0)
ENDIF
ENDIF
SET STOP pLOSS 100
SET TARGET pPROFIT 200
graphonprice CurrentLevel * myDivisor coloured("Blue")
graph myLONGconditions coloured("Blue")
graph mySHORTconditions coloured("Red")