Im a complete novice and am learn from the videos. Even bought and watched the advanced videos. Im having diffuculty excuting a loop code.
Im trying to have the code that detects when the prices closes below the bollinger and then closes above the bollinger – in just this two part sequence.
Can someone help me with the template of the code and if it is even a loop code or not?
Thank you in advance
There you go:
Found = -1
BollUP = BollingerUp[20](close)
For j = BarIndex downto 0
i = BarIndex - j
If close[i+1] < BollUP and close[i] > BollUP Then
Found = i
Break
Endif
Next
// or
Found = -1
BollUP = BollingerUp[20](close)
For j = BarIndex downto 0
i = BarIndex - j
If close[i] Crosses Over BollUP Then
Found = i
Break
Endif
Next
The variable FOUND, if <> -1 retains the bar ID where the event most recently occurred.
Thank you for your reply.
It is my fault, i meant to say when prices closes below the lower bollinger and then (any amount of periods later) closes above the upper bollinger – buy.
I will try to use the IF NEXT structure you provided to try to make it work.
There you go:
DEFPARAM CumulateOrders = false
ONCE Trigger = 0
BollUP = BollingerUp[20](close)
BollDOWN = BollingerDown[20](close)
IF close < BollDOWN Then
Trigger = 1
ENDIF
IF close > BollUP AND Trigger = 1 THEN
Trigger = 2
ENDIF
IF Trigger = 2 AND Not OnMarket THEN
BUY 1 Contract AT Market
SET TARGET pPROFIT 100
SET STOP pLOSS 50
Trigger = 0
ENDIF
There’s no need to use LOOPS, just wait close < BollDOWN then start triggering, as soon as it closes above BollUP you can enter Long.
Hi again, i cant seem to get the code working perfectly. Most of the trades are working then some odd trades happens that goes against my code. It makes trades below the bollinger.
Im trying to make it work by the code you have given me plus – bollinger above 200ema as core. (Experimenting with the other indicators.)
This is my code:
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = ExponentialAverage[200](close)
c1 = (close > indicator1)
BollUP = CALL “Example2 : Bollinger(1)upup”[0.66, 10]
BollDOWN = CALL “Example2 : Bollinger(1)down”[0.66, 10]
indicator3 = ExponentialAverage[200](close)
c2 = (bolldown > indicator3)
indicator4 = CCI[20]
c3 = (indicator4 < 0)indicator6 = AverageTrueRange[14](close)
c5 = (indicator6 > 3)
IF high < BollDOWN Then
Trigger = 1
ENDIF
IF close> BollUP AND Trigger = 1 THEN
Trigger = 2
ENDIF
if trigger= 2 and c1 and c2 and c3 and c5 then
trigger = 3
endif
IF trigger = 3 THEN
BUY 1 PERPOINT AT MARKET
trigger = 0
ENDIF
// Stops and targets
SET STOP pTRAILING 30
SET TARGET pPROFIT 60
Any advice of what im doing wrong? Much appreciated.
thank you
Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Thank you 🙂
To be able to replicate your trades you should post the complete code, not just the strategy.
Moreover we need to know:
- instrument traded
- TF used
- date and time of at leasr one bar where a traded was entered incorrectly.
Sorry i thought i had attached a screenshot before. ill try again now
5min tf
eur/usd
Examples in the screenshot
You are never resetting the triggers variables, so they last forever in their actual states until “trigger3”, then the order is executed at next bar open.
How do i reset the variables?