visual indicator on price (with array ?)

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #181980 quote
    philae38
    Participant
    Junior

    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
    Simple_visual_indicator.jpg Simple_visual_indicator.jpg
    #182122 quote
    robertogozzi
    Moderator
    Master

    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?

    #182164 quote
    philae38
    Participant
    Junior

    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.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

visual indicator on price (with array ?)


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
philae38 @philae38 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by philae38
4 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/21/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...