How to change stop loss to break even

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #105555 quote
    PerePere
    Participant
    Veteran

    I put normally a stop loss on my ProOrders. How can I change it’s value to zero after 2 or 3 candles (if I’m doing profit>x)?

    I tried following:

    sl=100
    IF LONGONMARKET AND (BARINDEX-TRADEINDEX)>1 AND close>TRADEPRICE THEN
    sl=0
    ENDIF
    SET STOP pLOSS sl

     

    but it goes again to 100 if close<TRADEPRICE on the next candles.

    After switching from 100 to 0 I want to remain it there.

    #105559 quote
    VonasiVonasi
    Moderator
    Master

    Pere – Please use the ‘Insert PRT Code’ button when posting code. i tidied it up for you. 🙂

    #105560 quote
    VonasiVonasi
    Moderator
    Master

    The problem is that if a trade moves back into a loss then the conditions are not met so the stop loss returns.

    What you have coded is not a break even code but one that removes the stoploss completely. Use the search box to search for ‘BreakEven’ and there are plenty of topics with example code available.

    This should fix your code but perhaps it is not what you actually want:

    if not onmarket and (your entry conditions) then
    buy 1 contract at market
    sl=100
    endif
    
    IF LONGONMARKET AND (BARINDEX-TRADEINDEX)>1 AND close>TRADEPRICE THEN
    sl=0
    ENDIF
    
    SET STOP pLOSS sl
    #105565 quote
    PerePere
    Participant
    Veteran

    Thank you Vonasi. I was just preparing the question, but just in this moment I had a power outage of one hour, and I don’t know how the question was posted, but it was.

    #105570 quote
    PerePere
    Participant
    Veteran

    Thank you @Vonasi. Problem is solved with the instructions found on

    https://www.prorealcode.com/blog/learning/breakeven-code-automated-trading-strategy/

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

How to change stop loss to break even


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Pere @petrus Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by PerePere
7 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/26/2019
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...