Reducing tradesize after Xpoints from entry

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #115181 quote
    Benson3
    Participant
    New

    Hi All,

    I am trying to code a reduction of the tradesize by half when being long/short and the current high/low reaches 20(before 15:00hr) or 40 (after 15:00hr) points. The remaining half will stay in until price closes below/above the lowest/highest point of the last 12 candlesticks. If the required points aren’t reached, but it does close on or above 10 points I want the stop loss to move to break even.

    Additionally, I always want to exit when price closes below/above the lowest/highest point of the last 12 candlesticks or at a loss of 15 points. Whichever is sooner.

    So far, I have come up with this, but it’s a mess:

    AM = time < 150000
    PM = time >= 1500000
    
    // Condiciones de salida de posiciones largas
    c3 = (close < lowest[12](low[1]))
    c17 = High >= (TradePrice + 20)
    c18 = High >= (Tradeprice + 40)
    c21 = close >= (tradeprice + 10)
    
    IF LongOnMarket Then
    Set Stop ploss 15 
    Endif
    IF LongOnMarket Then
    If c21 then
    Set Stop ploss tradeprice
    Endif
    If (AM AND c17) OR (PM AND c18) Then
    Sell CountOfLongShares/2 contracts at market
    Elsif c3 THEN
    SELL AT MARKET
    Endif
    Endif
    
    // Condiciones de salida de posiciones cortas
    c6 = (close > highest[12](high[1]))
    c19 = low <= (TradePrice - 20)
    c20 = low <= (Tradeprice - 40)
    c22 = close <= (tradeprice - 10)
    
    IF ShortOnMarket Then
    Set Stop ploss 15
    Endif
    IF ShortOnMarket Then
    If c22 then
    Set Stop ploss tradeprice
    Endif
     If (AM AND c19) OR (PM AND c20) Then
    Buy CountOfShortShares/2 contracts at market
    Elsif c6 THEN
    EXITSHORT AT MARKET
    Endif
    Endif
    

    I would appreciate some help.

    Thanks

    #115182 quote
    Vonasi
    Moderator
    Master

    Are you aware that currently it is not possible to partially close a position using ProOrder when live trading? It is possible to test with partial closure when running a back test but you cannot put that strategy live in either demo or real trading.

    #115197 quote
    Benson3
    Participant
    New

    Oh, that’s unfortunate. I have removed that part from the code and replaced it with just a profit target. However, it still doesn’t always do what I want it to do. That is exiting when price closes above or below the highest or lowest price of the last 12 candlesticks and moving the stop loss to break even after closing 10 points or higher from the entry price. Do you have any tips?

    // Condiciones de salida de posiciones largas
    c3 = (close < lowest[12](low[1]))
    c21 = close >= (tradeprice + 10)
    
    IF LongOnMarket Then
    If c21 then
    Set Stop ploss tradeprice
    Elsif c3 THEN
    SELL AT MARKET
    Endif
    Endif
    
    // Condiciones de salida de posiciones cortas
    c6 = (close > highest[12](high[1]))
    c22 = close <= (tradeprice - 10)
    
    IF ShortOnMarket Then
    If c22 then
    Set Stop ploss tradeprice
    Elsif c6 THEN
    EXITSHORT AT MARKET
    Endif
    Endif
    
    SET TARGET PPROFIT 50
    #115200 quote
    Vonasi
    Moderator
    Master

    SET STOP PLOSS requires a distance and not a price.

    Try this (not tested):

    // Condiciones de salida de posiciones largas
    c3 = (close < lowest[12](low[1]))
    c21 = close >= (tradeprice + 10)
    
    IF LongOnMarket Then
    If c21 or c3 then
    sell at market
    Endif
    
    // Condiciones de salida de posiciones cortas
    c6 = (close > highest[12](high[1]))
    c22 = close <= (tradeprice - 10)
    
    IF ShortOnMarket Then
    If c22 or c6 then
    EXITSHORT AT MARKET
    Endif
    
    SET TARGET PPROFIT 50
    #115223 quote
    Benson3
    Participant
    New

    This immediately exits my position, I just want to move the stop loss to break even. However, on your advice that set stop ploss requires a distance I changed tradeprice with just 0.1 that seems to work. It doesn’t work with 0 for some reason though. Anyway, thanks for your help.

    #115243 quote
    Vonasi
    Moderator
    Master

    SET STOP LOSS 0 cancels the stop order.

    When trying to code break even stop losses you have to be aware of how close to price your broker will let you place the stop – and this can change at times of high volatility. So if you are only a few pips in profit and try to move your stop to break even then it is likely that your broker will reject the order – if your strategy tries too many candles in a row then they will stop the strategy and either close the trade or orphan it depending on your settings.

    #115264 quote
    Benson3
    Participant
    New

    Ok, I’ll keep that in mind. Thank you

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

Reducing tradesize after Xpoints from entry


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Benson3 @benson3 Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by Benson3
6 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/18/2019
Status: Active
Attachments: No files
Logo Logo
Loading...