Add a second order

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #32561 quote
    FredrikFredrik
    Participant
    New

    Hi guys,

    kind of new to this platform and to algo trading so wanted to catch some help here.

    I would like to accomplish the following,

    If a trade is profitable, move the stop loss to break even and open up a second order in the same direction with new stop loss and profit target

    Thanks!

    Code:

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Indicators
    indicator1 = Stochastic[14,3](close)
    indicator2 = Average[5](indicator1)
    indicator3 = RSI[6](close)
    
    // Conditions to enter long positions
    c1 = (indicator1 CROSSES OVER indicator2)
    c2 = (indicator3 <= 30)
    
    IF c1 AND c2 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    c3 = (indicator1 CROSSES UNDER indicator2)
    
    IF c3 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    c4 = (indicator1 CROSSES UNDER indicator2)
    c5 = (indicator3 >= 70)
    
    IF c4 AND c5 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    c6 = (indicator1 CROSSES OVER indicator2)
    
    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS 8
    SET TARGET pPROFIT 15
    
    #32620 quote
    DespairDespair
    Blocked
    Master

    Hi,

    Didnt really go through your code but shouldnt in the first line cumulateorders=true if you want to add orders on profitable trades?

    #32698 quote
    NicolasNicolas
    Keymaster
    Legend

    Despair is right. You can find a complete breakeven function code in this blog article: https://www.prorealcode.com/blog/learning/breakeven-code-automated-trading-strategy/

    #34882 quote
    FredrikFredrik
    Participant
    New

    Hi guys, that’s true, Just copy/pasted my current one.

    Ill give it a shoot with Nicolas link.

    Thanks!

Viewing 4 posts - 1 through 4 (of 4 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

Add a second order


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Fredrik @fredrik Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/19/2017
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...