Im still stuck on this.
once trigger = 0
if trigger = 0 and high < bolldown then
trigger = 1
triggersignal = barindex
endif
if (barindex-triggersignal) >8 then
trigger = 0
endif
if trigger = 1 and close > bollup then
trigger = 2
endif
IF Trigger = 2 and c1 and close>c2 AND Not OnMarket and not daysForbiddenEntry THEN
BUY 1 Contract AT Market
SET TARGET pPROFIT 10
SET STOP ploss 10
Trigger = 0
ENDIF
From what i understand the trigger = 1 is not reset and keeps adding. How do i reset all variables after trade.
Your variable “trigger” is reset to 0 as soon as you enter an order at line 17.
At next bar, the code is read and if the condition are fulfilled at line 2, the variable is set to 1.
How do i reset variable 1 if the conditions for variable 2 arent met?
I tried to reset it 8 bars after variable 1, seems to not work.
Sorry what are variables 1 and 2 please?
When the high is < bolldown this is variable 1. I named it trigger = 1.
When trigger = 1 is active and within 8 bars if price closed above bollup i named it trigger =2 ( variable 2).
If it dosent close above bollup within 8 bars i tried to reset it back to trigger =0.
Im sorry i know my explanation is a little confusing.
Defparam cumulateorders = false
DEFPARAM FLATBEFORE = 090000
DEFPARAM FLATAFTER = 160000
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
//INDICATORS
c1 = AverageTrueRange[14](close) > 2
c2 = ExponentialAverage[200](close)
Bollup = CALL "Example2 : Bollinger(1)upup"[0.66, 10]
Bolldown = CALL "Example2 : Bollinger(1)down"[0.66, 10]
//SIGNALS
once trigger = 0
ONCE trigger = 1
if trigger = 0 and high < bolldown then
trigger = 1
triggersignal = barindex
endif
if (barindex-triggersignal) >8 then
trigger = 0
endif
if trigger = 1 and close > bollup then
trigger = 2
endif
//BUY CONDITIONS
IF Trigger = 2 and c1 and close>c2 and bolldown > c2 AND Not OnMarket and not daysForbiddenEntry THEN
BUY 1 Contract AT market
SET TARGET pPROFIT 10
SET STOP ploss 10
Trigger = 0
ENDIF
This is the full code.
If you GRAPH trigger, you will see at what moment the variable is set to what value, did you try? This is the first step to understand why a code is not functioning at it should, GRAPH the variables! 😉