how to sell at a certain price

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #60898 quote
    Alberto Lucchese
    Participant
    Average

    Hello everyone,

    I’m new to probuilder and to this forum. Perhaps this question is so basic that maybe is the reason i didnt found any post about this.

    I’m trying to create a very simple strategy; If todays open is below yesterday high, then buy if price rallies 70 percent of the previous day’s range above the open. Selling should be triggered when price increases yesterday range from the buy point.

    For the buy I use an STOP with the price i want the buy order to be triggered, however the order is also conditioned to the fact that the rally should occur during today….also for selling it, I’m not really sure how to the refer to the “price” as it (something like “IF price > x then SELL…..)

    Can somebody help me understand how it would work?

     

    Thanks in advance!

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    c1 = (open < close[1])
    rallyup=0.7
    addtoopen=range[1]*rallyup+open
    
    IF c1 THEN
    BUY 1 SHARES AT addtoopen STOP
    ENDIF
    c2=???
    if c2 then
    sell 1 share at market
    endif
    #60905 quote
    Vonasi
    Moderator
    Master

    Your STOP order will be cancelled at the close of each candle if no position is opened so if you are using this on a daily chart you will have no problems. If however you apply it on a smaller time frame then you will need to ensure that a new order is placed at the close of each candle if a position has not been opened.

    As for the SELL use:

    IF close > x THEN
    Sell at Market
    ENDIF

    This will close the position at the end of a candle if the price is greater than x.

    An alternative is to sell at a specific price by using a LIMIT order.

    SELL at x LIMIT
    #60921 quote
    Alberto Lucchese
    Participant
    Average

    Thanks a lot for your quick reply!

    The idea is to use daily candles, For selling i want the condition to be: “sell at certain price”, so if I use SELL LIMIT, will this order be ketp until is filled?  the sell price is based on the range of the candle previous to the BUY-day, so I haven find a way to keep this value until the day of sell comes (maybe it will be at 2 to 5 days) and then update it with the new value when a new BUY is triggered. Thing is, according to what i read, the logic we design by programming is repeated over an over, and a variable will be calculated on each loop, so how do i keep the value of the original range and how to updated once is not longer valid. I notice there is a “once” statement but it seems that once the value is set it cannot be changed, so in this case is more like “passing” the value to the next loop but being able to update it.

     

    Thanks again!

    #60930 quote
    Vonasi
    Moderator
    Master

    Sorry for the delay in this reply but I had to go to bed!

    If you use SELL AT x LIMIT then the instruction will be cancelled at the close of each bar so you will need to ensure that the instruction is repeated if you are still ONMARKET at the close of each bar. Maybe a better solution for you is to use SET TARGET PPROFIT  x  at the end of your code. Calculate the number of pips between your TRADEPRICE (or POSITIONPRICE) and the price you want to exit at with profit and set this as value x. This places a market take profit order that stays on the market until the position is closed or the value of x changes when a new order is placed and the old one cancelled. Supposedly you can set the value at zero to cancel the order altogether but that appears not to work at the moment so I would advise against using it until PRT have fixed that issue.

    #61021 quote
    Alberto Lucchese
    Participant
    Average

    I really appreciate your help. Thanks a lot!

    #61886 quote
    soulintact
    Participant
    Senior

    Good evening!

    Does anyone know the expression for: selling price>=purchase price that I can add to my other Exit conditions as below? Preferable being able to specify minimum % difference. I only buy long. THANKS!!

    Present enter and exit conditions:
    //Enter conditions
    if not onmarket and CBuy THEN
    BUY 50 CONTRACTS AT MARKET
    //Exit conditions
    ELSIF onmarket and CSell THEN
    SELL AT MARKET
    endif
    SET STOP %LOSS 5
    #61892 quote
    Vonasi
    Moderator
    Master

    They prefer it on here if you use the ‘Insert PRT code’ button when posting code to make it more readable. You don’t need to use ELSEIF. You could use:

    Percentage = 3 // Set to your required percentage level
    
    if not onmarket and CBuy THEN
    BUY 50 CONTRACTS AT MARKET
    
    //Exit conditions
    IF onmarket and CSell and Close > TradePrice * (1+(Percentage/100)) THEN
    SELL AT MARKET
    endif
    
    SET STOP %LOSS 5
    robertogozzi and soulintact thanked this post
    #61952 quote
    soulintact
    Participant
    Senior

    Excellent, thank you very much Vonasi.

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

how to sell at a certain price


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by soulintact
8 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/29/2018
Status: Active
Attachments: No files
Logo Logo
Loading...