MarcParticipant
Average
Hi together,
pls find attached code.
For some reasons I want to have a secure SL
When system is long this SL should trigger when MA10 < MA200
When system is short this SL should trigger when MA10 > MA200
SL for Long is called SLL, SL for short is called SLS.
I think there is an issue with this EA…can somebody confirm if this coding is correct or not and help me to amend it?
DEFPARAM CUMULATEORDERS = false
REM Money Management
//Capital = 10000
//Risk = 0.001 // Faktor für Kontraktgröße
//StopLoss = 10 // StoppLoss
REM Calculate contracts
//equity = Capital + StrategyProfit
//maxrisk = round(equity*Risk)
//x = abs(round((maxrisk/StopLoss)/PointValue)*pipsize)
x = 1
//Indikatoren
MM200 = average[200](close)
MM10 = average[10](close)
RSI2 =RSI[2]((close+high+low)/3)
IBS = (Close-Low) / (High-Low) * 100
//STOP LOSS SIGNAL
//SLL = MM10 < MM200
//SLS = MM10 > MM200
//LONG
ca1 = close > MM200 AND MM200[1] < MM200[0]
ca2 = RSI2 < a //DAX 9, BUND 6, S&P 8, EURUSD 10, Gold 6, WTI 10
ca3 = IBS < b //DAX 9, BUND 10, S&P 8, EURUSD 8, Gold 10, WTI 10
IF NOT LONGONMARKET AND ca1 and ca2 and ca3 THEN
BUY x CONTRACT at market NEXTBAROPEN
ENDIF
//EXIT LONG
IF LONGONMARKET AND close > MM10 THEN
sell at market NEXTBAROPEN
//SET STOP LOSS SLL
ENDIF
//SHORT
cv1 = close < MM200 AND MM200[1] > MM200 [0]
cv2 = RSI2 > c //DAX 95, BUND 90, S&P 97, EURUSD 90, Gold 95, WTI 95
cv3 = IBS > d //DAX 90, BUND 98, S&P 90, EURUSD 92, Gold 93, WTI 90
IF NOT SHORTONMARKET AND cv1 and cv2 and cv3 THEN
SELLSHORT x CONTRACT at market NEXTBAROPEN
ENDIF
//EXIT SHORT
IF SHORTONMARKET AND close < MM10 THEN
exitshort at market NEXTBAROPEN
//SET STOP LOSS SLS
ENDIF
Add these lines (or more if you need) at the end of your code to check the value retained by those variables each bar, as from the screenshot. This will help you discover errors:
graph MM10
graph MM200
graph close
I’ve tried a few things but I can’t get your code to execute a Short trade.
I’m sure there is a simple explanation. I’ll probably try again later! 🙂
Sorted … I get Short trades now … I was testing on too low / short a timeframe!
MarcParticipant
Average
Thank you very much for your help…I think it works now…check out screenshot attached…not many trades, but they seem to be okay
MarcParticipant
Average
Now I see it is not working as it should be… SL for long and short doesn’t work -.-
Graph shows this
What you call the “SL” are coded at lines 34 and 49. The orders should be exited when Close is above or below the 10 periods moving average, why do you think it is not working?
MarcParticipant
Average
I understand. I want to have sth like an emergency Stop: line 35 and 50.
Do I have to implement this to snippets after line 29 and 44?
MarcParticipant
Average
One additional question…
How can I instert the feature to type in externaml parameters?
Pls see Screenshot below.
When playcing RSI I am able to change oversold and overbought zones within the code…I tried to add this feature to IBS…but it doesn’t work without changin paraemters in all other chartwindows