Traielrstop/step with Stoploss

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #192405 quote
    marinusvrij
    Participant
    New

    Hello agasin,

     

    I have a question about scripting the following options.

    i have a stoploss in my code as also a trailerstop with a trailerstep.  The backtest on this script is very good but somehow when the

    algo set on live the Stoploss only appears and when the price of the indices targets the Trailerstop / step nothing happens.. the Stoploss will be there – when the price targets the trailerstop / step  the stoploss must disappear.

    Also when the algo is putting up for live there is no feedback from the the backtrest that there is a error in the code…

    Some one who cna help  me ?

    there should be a scrypt who can  combine these two (or 3) options in one script.

    #192406 quote
    Nicolas
    Keymaster
    Master

    How is it set your trailing stop please? Is it a soft coded one from the forum? Or are you using the SET STOP TRAILING instruction please? We need more information to understand what is happening in live trading.

    Did you check the orders rejection list please?

    #192415 quote
    marinusvrij
    Participant
    New

    Hello

     

    There is no rejection in any journal. Or maybe you can show me where it must be written down

    The Algo opens the position on the indicator with the normal stoploss (not via the …… ) but as i saidwhen the pricaction reach the trailerstop/step the algo won’t use this command

    while the backtest doesn’t show any errors (Tick by Thick)

    underneath mentioned thje script

    //trailerstep
    trailingstart = 25 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the “stoploss”
    //0 is off 1 is on
    trailerStepFlag = 1

     

    with thanks

    Marco

    #192418 quote
    marinusvrij
    Participant
    New

    ps. i’m not using the stoprtrailing code from the wizard..

    Again, there are no rejecting orders the algo does its thing but only with th estoploss and doesn’t use the script for the trailerstop/step

     

    greetings

    Marco

    #192436 quote
    Nicolas
    Keymaster
    Master

    Are you using a limited risk account?

    What is “the normal stoploss”, how do you set it?

    Difficult to know where is the trouble with your code as you did not post the full content of the trailing stop part, it seems to come from the forum however?

    #192439 quote
    marinusvrij
    Participant
    New

    Hello

    Indeed, i use a stoploss 150 euro…

    And i dont have a limited risk account and yes i use the code from the forum. ( wich is of no use as i use a stoploss of 1 % of my balance)

    May the code from the forum is not right?  herunder the code – where also some code is secured..

    //trailerstep
    trailingstart = 12 //trailing will start @trailinstart points profit
    trailingstep = 3 //trailing step to move the "stoploss"
    //0 is off 1 is on
    trailerStepFlag = 1
    //stoploss
    stopLoss = 150
    dynTS = 0
    dynTrail = 40
    TIMEFRAME(5 MINUTES, UPDATEONCLOSE)
    // Stops en targets : Voer uw beschermende stops en winst targets hier in
    // secured xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    //Sigals
    longSignal = 0
    shortSignal = 0
    //long = (xxxxxxxxxxxxxxxsecuredxxx
    //short =(xxxxxxxxxxxxsecuredxxxxxxxxxxxxxxxxxx
    // Condities om long posities te openen
    IF NOT LongOnMarket AND long AND active THEN
    BUY numContr CONTRACTS AT MARKET
    longSignal = 1
    ENDIF
    // Condities om long posities te sluiten
    If LongOnMarket AND short THEN
    SELL AT MARKET
    ENDIF
    //Close positions for end of the day
    IF (time >= closePositions) and LONGONMARKET THEN
    SELL AT MARKET
    ENDIF
    // Condities om short posities te openen
    IF NOT ShortOnMarket AND short AND active THEN
    SELLSHORT numContr CONTRACTS AT MARKET
    shortSignal = 1
    ENDIF
    // Condities om short posities te sluiten
    IF ShortOnMarket AND long THEN
    EXITSHORT AT MARKET
    ENDIF
    //Close positions for end of the day
    IF (time >= closePositions) and ShortOnMarket THEN
    EXITSHORT AT MARKET
    ENDIF
    timeframe(1 minutes)
    ONCE noSignal = 1
    // reset newSL Long
    IF longSignal AND noSignal THEN
    newSL = 0
    dynStop = 0
    noSignal = 0
    ENDIF
    IF NOT longSignal and NOT noSignal THEN
    noSignal = 1
    ENDIF
    // reset newSL short
    IF shortSignal AND noSignal THEN
    newSL = 0
    dynStop = 0
    noSignal = 0
    ENDIF
    IF NOT shortSignal and NOT noSignal THEN
    noSignal = 1
    ENDIF
    IF trailerStepFlag THEN
    IF LONGONMARKET THEN
    //next moves
    IF newSL>0 AND close-newSL>=trailingstart*pipsize THEN
    newSL = newSL+(trailingstep*pipsize)
    ENDIF
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstep*pipsize THEN
    newSL = tradeprice(1)+(trailingstep*pipsize)
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //next moves
    IF newSL>0 AND newSL-close>=trailingstart*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstep*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    ENDIF
    
    // dynamic trailer step
    IF dynTS THEN
    ONCE dynStop = 0
    IF LONGONMARKET THEN
    IF dynStop = 0 THEN
    dynStop = tradeprice(1) - dynTrail
    ENDIF
    IF dynStop > close - dynTrail THEN
    dynStop = close - dynTrail
    ENDIF
    ENDIF
    IF SHORTONMARKET THEN
    IF dynStop = 0 THEN
    dynStop = tradeprice(1) + dynTrail
    ENDIF
    IF dynStop < close + dynTrail THEN
    dynStop = close + dynTrail
    ENDIF
    ENDIF
    IF dynStop>0 THEN
    SELL AT dynStop STOP
    EXITSHORT AT dynStop STOP
    ENDIF
    ENDIF
    // Stops en targets
    SET STOP $LOSS stopLoss
    #192442 quote
    marinusvrij
    Participant
    New

    Ps.

     

    The Dynamic trailer is set on OFF so that doesnt’work  but is not of use in this code.

    greetings

    Marco

    #192445 quote
    Nicolas
    Keymaster
    Master

    Remove lines with “newsl=0”

    and place that code at the top, below TIMEFRAME(1 minutes):

    if not onmarket then 
     newsl=0
    endif
    marinusvrij thanked this post
    #192447 quote
    marinusvrij
    Participant
    New

    Hello

     

    Thanks , i went live and i think it works… only the pips in the code are disturbing for me…

    Greetings

    Marco

    #192452 quote
    marinusvrij
    Participant
    New

    Hello,

     

    I tried the adjustments and the backtest shows more then 36% upto  45% of neutral trades… very strange ( this is with the same Trailerstep/stop and stoploss  – with the newsl=o code i get 80% of profit trades in my backtest)

    can you explain this?

    kind regards

    #193048 quote
    Nicolas
    Keymaster
    Master

    Why don’t you just GRAPH the newsl to see how it behaves in the market? You’ll see how and when it is calculated, and how and when orders are closed on that trailing stop price:

    GRAPHONPRICE newsl

    Always GRAPH your variables when there is something you don’t understand, otherwise it is very difficult to analyze the results of the algo 🙂

    #193051 quote
    marinusvrij
    Participant
    New

    Hello

    I always Graph my result to see if its works

    But in this case the advise you gave – to erase the News=0 lines was not good,

    More then 50% were neutral trades

     

    Kind regards

    Marco

    #193052 quote
    marinusvrij
    Participant
    New

    Hello Nicoals

     

    i have solved the problem myself , just a few adjustments on the script.. and it worked..

    butr thanks anyway for the effort.

    Also

    Also this algo works now- (with a few adjustments in the script of the trailerstop and step)–

    The “problem” I have now “but the trailerstep is calculated in TF candle and I want it dynamic with the price action.

    With other words : the step is done after ending the candle ( in wich timeframe it was scripted)

     

    Kind regards

    Marco

     

    Marco

    ps i cannot send email any more to Market@….

    regards

    Marco

    #193100 quote
    Nicolas
    Keymaster
    Master

    In order to interact during a candle, you have to use multi timeframe.

    Look at those examples:

    https://www.prorealcode.com/topic/move-sl-during-current-candle/#post-79130 (most stoploss to breakeven during candle).

    https://www.prorealcode.com/topic/ouverture-immediate-position/#post-81939 (trigger an order during candlestick).

    https://www.prorealcode.com/topic/how-to-open-and-close-in-1-bar/#post-146272 (open / close an order during the same bar).

    #193105 quote
    marinusvrij
    Participant
    New

    Thanks Nicoals,

     

    i will try them all and see what suits best.

     

    With thanks

    Marco

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

Traielrstop/step with Stoploss


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 14 replies,
has 2 voices, and was last updated by marinusvrij
3 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/29/2022
Status: Active
Attachments: No files
Logo Logo
Loading...