Trailing stoploss problems

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #222267 quote
    Albaran
    Participant
    Average

    Hi there,

    I’ve been tinkering on this bit of code for several days and cannot figure out how to eliminate several behaviors:

    1. It sometimes places a negative stoploss. It should only start to place a stoploss when the position is breakeven yet at times it will place a stoploss at a loss…
    2. It sometimes does, sometimes does not increase the trailing stoploss. Obviously, it should always increase whenever possible
    If not onmarket then
    sellshort 1 contract at market
    endif
    
    minsteps = 5
    shortbreakeven = positionprice - minsteps
    Fullshortexit = positionprice - 10
    
    If shortonmarket and Close[1] > shortbreakeven and Close <= shortbreakeven then
    ShortStopSignal = 1
    Elsif not shortonmarket then
    ShortStopSignal = 0
    Endif
    
    If ShortStopSignal[1] = 0 and ShortStopSignal = 1 then
    ShortProfitTime = BarIndex
    elsif not shortonmarket then
    ShortProfitTime = 0
    Endif
    
    // Short Profit Stoploss management :
    If ShortProfitTime <> 0 and close > Fullshortexit and close < positionprice then
    ShortStopProfit = PositionPrice - 1
    Elsif ShortProfitTime <> 0 and close <= Fullshortexit and abs(Close - PositionPrice)/MinSteps < 4 then
    ShortStopProfit = Close + MinSteps
    Elsif ShortProfitTime <> 0 and close <= Fullshortexit and abs(Close - PositionPrice)/MinSteps >= 4 then
    ShortStopProfit = close + 2*MinSteps
    elsif ShortProfitTime = 0 then
    ShortStopProfit = 0
    Endif
    
    If ShortProfitTime <> 0 then
    MyShortStopProfit = lowest[Max(1,BarIndex - ShortProfitTime)](ShortStopProfit)
    Endif
    
    if onmarket then
    sell at MyshortStopProfit stop
    endif
    

    Thanks for the help, I’m really confused about what it is I’m not getting…

    #222275 quote
    bertrandpinoy
    Participant
    Veteran

    I have submitted your problem to I.A, hereinafter the answer:

    Incorrect calculations: Calculations for shortbreakeven, Fullshortexitet stop-loss conditions seem to correspond to arbitrary price levels ( minsteps, positionprice). These values should be based on the actual performance of the position.

    Initializing Variables: There is no ShortStopProfit, which can cause problems.

    Fuzzy logic: The logic to determine when to place a stop-loss or increase it seems complex and possibly subject to

    Exit conditions:

    Using BarIndex: Using BarIndexpor to measure profit time can be prone to errors as it depends on the number of bars you have loaded and the frequency of your data.

    Management of Short Positions: The code seems mainly intended for the management of short positions. Make sure this fits your trading strategy.

    To correct these problems, it may be necessary to rethink the logic of position management and adapt the

    #222284 quote
    JS
    Participant
    Senior

    Hi,

    To check if your logic is correct, use:

    GraphOnPrice ShortBreakEven

    GraphOnPrice FullShortExit

    GraphOnPrice PositionPrice

    Graph ShortStopSignal

    Etc.

    Scherm­afbeelding-2023-10-11-om-16.02.30.png Scherm­afbeelding-2023-10-11-om-16.02.30.png
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Trailing stoploss problems


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Albaran @albaran Participant
Summary

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

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