Scaling out using multiple strategies

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #145546 quote
    Vonasi
    Moderator
    Master

    I was playing with a strategy that seemed to work quite well with scaling out of position but IG do not allow us to auto trade and partially close positions so I got to thinking of how we could do it. I came up with the following code idea.

    In this example we would run six strategies – at the same time each would open just one position . Then each would close its position at a different take profit level. In this example at any profit over 0%, 1%, 2%, 3%, 4% and 5%. Each strategy would know by counting the variable ‘om’ (onmarket) whether other strategies still have an open position. We also have a condition based exit that closes all positions and an emergency exit if there is a big market drop.

    We need to rem out the sell orders in each strategy to leave just one sell order and so create six strategies with exits at different levels.

    This is an example for a long only strategy and it can also only sell at the bar closing price – however we could get out very close to each % level if we use MTF to trade on a faster time frame which would make it pretty similar to if we were selling at limit orders.

    I thought I would post the idea here just in case it is of any use to anyone.

    The strategy below is set up to exit at 2% profit. Obviously it is not a complete strategy – add your own entry and exit conditions.

    defparam cumulateorders = false
    
    if (your long entry condition) and om = 0 then 
    buy 1 contract at market
    pp = close //stored position price of our 1 position
    om = 6 
    endif
    
    //store more accurate position price after first bar on market
    if positionprice <> positionprice[1] then
    pp = positionprice
    endif
    
    //exit all trades if exit condition true
    if (your short exit condition) then
    sell at market
    om = 0 //not on market
    endif
    
    //exit with any profit strategy
    if om = 6 and close > pp * 1.0 then
    //sell 1 contract at market
    om = om-1 //one position closed
    endif
    
    //exit with 1% profit strategy
    if om = 5 and close > pp * 1.01 then
    //sell 1 contract at market
    om = om-1 //one position closed
    endif
    
    //exit with 2% profit strategy
    if om = 4 and close > pp * 1.02 then
    sell 1 contract at market
    om = om-1 //one position closed
    endif
    
    //exit with 3% profit strategy
    if om = 3 and close > pp * 1.03 then
    //sell 1 contract at market
    om = om-1 //one position closed
    endif
    
    //exit with 4% profit strategy
    if om = 2 and close > pp * 1.04 then
    //sell 1 contract at market
    om = om-1 //one position closed
    endif
    
    //exit with 5% profit strategy
    if om = 1 and close > pp * 1.05 then
    //sell 1 contract at market
    om = om-1 //one position closed
    endif
    
    //Emergency exit at 10% drop from position price 
    if om <> 0 and close < pp * 0.90 then
    sell at market
    om = 0 //not on market
    endif
    
    graph om
    Monochrome, eckaw, Francesco and 5 others thanked this post
    #145623 quote
    GraHal
    Participant
    Master

    Link to above added as Log 242 here …

    Snippet Link Library

    Vonasi thanked this post
    #207446 quote
    LucasBest
    Participant
    Average

    Hello,

    is it possible to do the same with SET TARGET PRICE x, with partial close of the position ?

    Thanks

    #207456 quote
    robertogozzi
    Moderator
    Master

    SET TARGET PRICE x will affect all open positions, not single ones.

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

Scaling out using multiple strategies


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 3 replies,
has 4 voices, and was last updated by robertogozzi
3 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/27/2020
Status: Active
Attachments: No files
Logo Logo
Loading...