Help Coding strategy
//==========================================================================================================
DEFPARAM CUMULATEORDERS = false
DEFPARAM PRELOADBARS = 10000
cciP = 20
atrP = 14
atrM = 1
smaP = 5
cciP = max(1,min(999,cciP))
atrP = max(1,min(999,atrP))
atrM = max(0.0000001,min(999,atrM))
smaP = max(1,min(999,smaP))
//
IF BarIndex > max(cciP,atrP) THEN
lastCCI = thisCCI
thisCCI = CCI[cciP](typicalPrice)
myATR = AverageTrueRange[atrP](close)
//
temp1 = myATR * atrM
upT = low - temp1
downT = high + temp1
//
temp2 = Average[smaP,0](myATR) * atrM
buffDN = high + temp2
buffUP = low - temp2
//
IF (thisCCI >= 0) AND (lastCCI < 0) THEN
buffUP = buffDN[1]
ENDIF
IF (thisCCI <= 0) AND (lastCCI > 0) THEN
buffDN = buffUP[1]
ENDIF
IF (thisCCI >= 0) THEN
IF (buffUP < buffUP[1]) THEN
buffUP = buffUP[1]
ENDIF
ELSIF (thisCCI <= 0) THEN
IF (buffDN > buffDN[1]) THEN
buffDN = buffDN[1]
ENDIF
ENDIF
IF thisCCI >= 0 THEN
MagicTrend = buffUP
ELSIF thisCCI <= 0 THEN
MagicTrend = buffDN
ENDIF
ELSE
thisCCI = 0
lastCCI = 0
myATR = 0
buffUP = 0
buffDN = 0
buffDN = 0
buffUP = 0
MagicTrend = 0
ENDIF
// Conditions to enter long positions
IF buffUP=1 THEN
BUY 1 CONTRACTS AT MARKET
SET STOP %LOSS 1 //sl=1
set target %profit 2 //TP=2
ENDIF
// Conditions to exit long positions
If buffDN=1 THEN
SELL AT MARKET
SET STOP %LOSS 1 //sl=1
set target %profit 2 //TP=2
ENDIF
Whats Wrong with this code?
Try below in place of your Lines 59 to 71 above …
Lng = Close crosses over buffUp
Sht = Close crosses under buffDn
// Conditions to enter long positions
IF Lng THEN
BUY 1 CONTRACTS AT MARKET
SET STOP %LOSS 1 //sl=1
set target %profit 2 //TP=2
ENDIF
// Conditions to exit long positions
If Sht THEN
SELLShort AT MARKET
SET STOP %LOSS 1 //sl=1
set target %profit 2 //TP=2
ENDIF
Hi,
i wont buy or sell by a crossover, only if the trend is change.
If the trend goes down the i want have a sell signal, if the trend goes up i want have a buy signal.
If the color from the trend switch from green to red sell, from red to green buy.
I have no idea how to code this.
thx for help.
RazzParticipant
Master
Hello Killerplautze is just a simple code maybe it will help 😉
// Festlegen der Code-Parameter
DEFPARAM CumulateOrders = False // Kumulieren von Positionen deaktiviert
myMagicTrend = CALL "Magic Trend custom"[20, 9, 2, 5]
Gruen = myMagicTrend > myMagicTrend[1]
Rot = myMagicTrend < myMagicTrend[1]
// Verhindert das Trading an bestimmten Wochentagen
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Bedingungen zum Einstieg in Long-Positionen
IF Gruen AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Bedingungen zum Ausstieg von Long-Positionen
IF Rot THEN
SELL AT MARKET
ENDIF
// Bedingungen zum Einstieg in Short-Positionen
IF Rot AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Bedingungen zum Ausstieg aus Short-Positionen
IF gruen THEN
EXITSHORT AT MARKET
ENDIF
i wont buy or sell by a crossover, only if the trend is change. If the trend goes down the i want have a sell signal, if the trend goes up i want have a buy signal. If the color from the trend switch from green to red sell, from red to green buy
This IS exactly what a crossover does, as @GraHal coded.
The code posted by @Razz , only checks when the Magic Trend rises or falls, not when a crossover occurs.