Stoploss fixing

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #135627 quote
    Philstrading
    Participant
    Senior

    Hi guys and Gals

    I’m a newby of course, so I’ve written a few programs that backtest well and I’m developing my coding approaches. So this code I’ve grasped today for setting the stoploss once it reaches a certain level. The code is developed from scratch and self-explanatory in the coding, but I could do with a push with one or two things.

    The way this behaves is it floats with price, so if it closes above a pip movement threshold it changes the stoploss, and if moving back below the threshold again it jumps back to the initial stoploss, so back again if it closes >= the threshold “newstoptrigger” . Bit unusual I hear you say, but what it does in the program is it retains the stop and snaps off volatile moves back which would normally be the sign of a turnaround of trade, at least thats what I tink it does. So testing back to Jan 2019 (I’ll go further of course) but testing to Jan 19 it gives an extra £1500 or so which equates to about 188 pips give or take, as it halves the stoploss on 50% of the losses without losing good trades.

    I was looking at this to move to a break even aftera certain amount of move for psychological wellbeing really, but that just keeps most of the losses or worsens it by cutting off good trades unless you move the stop significantly into the trade. So it works for my trend capture trade wihtout losing the good trades and nipping off the volatile pullbacks against the trade, and I’ve atached a picture with the graph and graphonprice.

    However, what I haven’t quite managed to do yet is stop the price after its moved to retain it at the new stoploss if I were to want to keep it there, and whilst I dont think I do for this strategy, I could do with a little help with a means of retaining the stoploss at the set amount in the code labelled “newstoplevel” incase it improves things in other strategies or this one even, though for this one I would anticipate some lost good trades, but any help greatly appreciated…

    Want to hold the “newstoplevel” once hit…..

     

    stopamount=60 //stopamount
    targetamount=125 //target
    newstoplevel=30// value to work out stop level tradeprice + or -
    newstoptrigger=10 //pips moved to trigger new stop level
    If longonmarket and (close-tradeprice)>=newstoptrigger then
    Mystoplevel=(tradeprice-newstoplevel)//sets the vlaue if price gone to or beyond 60 pips
    Elsif longonmarket then
    Mystoplevel=(tradeprice-stopamount)//set the value to level to calculate 60 pips
    //Below setting stoploss for shorts//
    Elsif shortonmarket and (tradeprice-close)>=newstoptrigger then
    Mystoplevel=(tradeprice+newstoplevel)
    Elsif shortonmarket then
    Mystoplevel=(tradeprice+stopamount)
    endif
    If longonmarket then
    Mystoploss=tradeprice-mystoplevel ///changing to pips
    Elsif shortonmarket then
    Mystoploss=Mystoplevel-tradeprice//changing to pips
    Endif
    set Stop Loss Mystoploss
    SET TARGET pPROFIT targetamount
    Graphonprice Mystoplevel as "Mystoplevel"
    Graph Mystoploss
    If not onmarket then
    Mystoploss=stopamount
    Endif
    stop-levels.jpg stop-levels.jpg
    #145457 quote
    robertogozzi
    Moderator
    Master

    Sorry my late reply.

    I can’t understand what you really want to lock, can you make an example, please?

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

Stoploss fixing


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
5 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/11/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...