Hi,
Does someone may help me to improve my indicator ?
I developed a simple visual indicator on price that is working fine (for my personal use) : see attached picture and code.
Basically, it’s just to visualize a winning or losing position : In when a buying condition is fulfilled and exiting position if Stop Loss (red rectangle) or TakeProfit (green rectangle) are achieved.
I would like now to upgrade this visual indicator to allow multiple entry points. : i.e. being able to ‘open’ a new position even if the previous one is not closed (and then exiting to the corresponding exit points on SL or TP).
I guess, it is necessary to use variable arrays but I cannot code it. Especially, I do know how to affect to the value of current bar array the value of the previous bar array : I tested $test[i] = $test[i][1] but it doesn’t work.
Thank for your replies.
P.S. : I’ve read previous posts on arrays but did not find a clue to help me.
// version test qui permet d'entrer une fois sur la valeur lorsque la condition d'achat est remplie
// Indicateurs utilisés
ATR = averagetruerange(20)
sma7 = average[7](close)
sma20 = average[20](close)
sma50 = average[50](close)
//Constantes
signal = 0
stoploss=0 // obligé de le mettre à 0 sinon il existe toujours sur les cours
takeprofit = 0 // obligé de le mettre à 0
vente=0 // 0 ou 1 : pour definir si on vend ou pas
jourachat=0
/////////////////////////////////////////////////////////////
// définition des conditions d'achats
condIN = sma7[1] < sma20[1] and sma7 > sma20 and close > sma50
//condOUT = close < sma50
// Test pour prévenir déclenchement le lendemain
if longmarket = 0 then //or vente = 1 then
if condIN then
stoploss = close - 3*Averagetruerange[20](close)
takeprofit = close + 2*(close - stoploss)
signal = close
ca = signal
longmarket = 1
dateachat = barindex
else
signal = 0
longmarket = 0
endif
endif
if longmarket[1]= 1 then
longmarket =1
stoploss = stoploss[1]
takeprofit = takeprofit[1]
endif
// Si on est dans le marché, vérifie les conditions pour en sortir ou pas
if longmarket = 1 then
if Low < stoploss then
vente = 1
signal = stoploss
endif
if high > takeprofit then
vente = 1
signal = takeprofit
endif
// Si les conditions de sortie sont remplies, on détermine le cours de sortie
if vente = 1 then
longmarket =0
datevente = barindex
if signal >= ca then //on sort du trade avec un gain
drawrectangle(dateachat, ca, datevente, signal) coloured(0,255,0,50) bordercolor(0,255,0)
else //on sort du trade avec une perte
drawrectangle(dateachat, ca, datevente, signal) coloured(255,0,0,50) bordercolor(255,0,0)
endif
endif
endif
return signal, stoploss, takeprofit
If I got what you mean, you would like to ADD (accumulate) another position whn already On Market if condIN is true again, right?
But do you want to keep the same target and the same stop loss already set for the previous position?
Hi robertogozzi,
Yes I want to ADD (accumulate) another position when already On Market if condIN is true again.
But for the new position, I want to have a new SL and TP defined with the new entry condition.