Set Stop Loss from HI or Lo in breakout strategy

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #71675 quote
    PastaPestoPastaPesto
    Participant
    Veteran

    Hi all,

    I am currently working an a Breakout strategy. It all seams to work fine but I am struggeling with the Stop loss and Take profit. I want the take profit to be set from my “HI” or “LO” in the breakout range instead of from the price that I get when the order is set.

    The reason for this is that when there is a slippage, the order price will be different from the HI or LO. I still want to have the same profit target.

    // --- settings
    rangestart =  092500 //start of premarket schedule
    rangeend = 093500 //end of premarket schedule
    closeat = 115500 //time schedule to close all pending & atmarket orders
    takeprofit = 5 //takeprofit in points
    stoploss = 5 //stoploss in points
    n = 1 //amount of lots/contracts/shares to open for each new order
    // --- end of settings
    
    ONCE LO = CLOSE*1000
    
    if time>=closeat then
    sell at market
    exitshort at market
    endif
    
    if intradaybarindex=0 then
    hi=0
    lo=close*1000
    endif
    
    if time>=rangestart and time<rangeend then
    hi=max(high,hi)
    lo=min(low,lo)
    trade = 0
    ENDIF
    
    IF trade = 0 and time>=rangeend THEN
    if hi>0 then
    BUY n SHARES at HI STOP
    endif
    if lo>0 then
    SELLSHORT n SHARES at lo STOP
    ENDIF
    endif
    
    if onmarket then
    trade=1
    endif
    
    SET STOP pLOSS stoploss
    SET TARGET pPROFIT takeprofit
    

    Regards

    #71693 quote
    NicolasNicolas
    Keymaster
    Legend

    Remove your lines 41 and 42 and replace them with the ones below: (not tested)

    if longonmarket then 
     sell at hi+takeprofit*pointsize stop
     sell at hi-stoploss*pointsize limit 
    endif
    if shortonmarket then 
     exitshort at lo-takeprofit*pointsize stop
     exitshort at lo+stoploss*pointsize limit
    endif
    PastaPesto thanked this post
    #72199 quote
    PastaPestoPastaPesto
    Participant
    Veteran

    Thanks Nicolas!

    That worked great. I used your code (only changed takeprofit to limit and stoploss to stop entry order) and it worked perfectly.

    Thanks!

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

Set Stop Loss from HI or Lo in breakout strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
PastaPesto @pastapesto Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/30/2018
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...