Trailing Loss + Breakeven

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

    Hello everyone, hope you are well! 🙂

     

    I have a problem that I can’t figure out…

     

    Bellow is the code I’d like to use to get my SL. I’d like it to follow the trade if it become positive otherwise, I’d like that if the price crosses the SSpanB it stops. (I tried only for the long for now)

     

    Can you help me a bit? 😀

     

    Thanks!

    PointsToKeep = 10 //
    startBreakeven = 6 //Pas en dessous de 6
    
    once breakeven = 1//1 on - 0 off
    
    //reset the breakevenLevel when no trade are on market
    if breakeven>0 then
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
    // --- BUY SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven THEN
    //calculate the breakevenLevel
    breakevenLevel = price - PointsToKeep
    Elsif LONGONMARKET and price crosses under SSpanB THEN
    EXITSHORT at market
    ENDIF
    
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    // --- end of BUY SIDE ---
    
    IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven THEN
    
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)-PointsToKeep
    ENDIF
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    EXITSHORT AT breakevenLevel STOP
    ENDIF
    endif
    #154249 quote
    robertogozzi
    Moderator
    Master

    To exit from a Long trade you have to use SELL (not EXITSHORT).

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

Trailing Loss + Breakeven


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
Tanou @tanou Participant
Summary

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

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 12/18/2020
Status: Active
Attachments: No files
Logo Logo
Loading...