Good morning gentlemen,
I have an issue in my code.
Here what I want the code do: when a stop loss is touched, a variable is set to 1 and a “range” is set too (+X and -X points at the Tradeprice(1) )
Here, visually:
-----Range Up (10020)
.
.
- Tradeprice (10000)
.
.
-----Range Down (9980)
In ordrer to do that, I code this:
// ForbidddenTradingRange
NoTrade = 0
if notrade = 1 then
RangeNoTradeUp = Tradeprice(1)+20
endif
if notrade = 1 then
RangeNoTradeDown = Tradeprice(1)-20
endif
// Long
indicator1, ignored, ignored = CALL "Unicorn Color"(close)
indicator2 = Average[30](close)
c1 = (indicator1 CROSSES OVER indicator2)
IF c1 and notrade=0 AND timeEnterBefore AND timeEnterAfter THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Close Long
indicator3, ignored, ignored = CALL "Unicorn Color"(close)
indicator4 = Average[30](close)
c2 = (indicator3 CROSSES UNDER indicator4)
IF c2 THEN
SELL AT MARKET
notrade=1
ENDIF
if close>RangeNoTradeUp or close<RangeNoTradeDown then
NoTrade=0
endif
// Short
indicator5, ignored, ignored = CALL "Unicorn Color"(close)
indicator6 = Average[30](close)
c3 = (indicator5 CROSSES UNDER indicator6)
IF c3 and notrade=0 AND timeEnterBefore AND timeEnterAfter THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Close Short
indicator7, ignored, ignored = CALL "Unicorn Color"(close)
indicator8 = Average[30](close)
c4 = (indicator7 CROSSES OVER indicator8)
IF c4 THEN
EXITSHORT AT MARKET
notrade=1
ENDIF
if close>RangeNoTradeUp or close<RangeNoTradeDown then
NoTrade=0
endif
// SL and TP
SET STOP pLOSS 20
SET TARGET pPROFIT 20
When I backtest it, some trade don’t respect the rule “Forbidden Traading Range”.
I think I miss something, but I don’t know what 😉
Thank you for your help.
I wish you a good day.
Start line 3 with ONCE, otherwise it will ALWAYS be false!
Start line 3 with ONCE, otherwise it will ALWAYS be false!
…or just delete line 3 as the value of NoTrade will always start at zero!