Trailing buy order

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #9861 quote
    absent1980
    Participant
    Average

    Hi everyone,

    Just wondered if you could advise on few things.

    1. How to code trailing BUY orders based on a price difference from a previous order?
    2. How to code current remaining account balance or percentage from it?

    Thanks.

    #9867 quote
    Nicolas
    Keymaster
    Master

    Hello,

    You can try these codes for trailing stop functions:

    http://www.prorealcode.com/blog/learning/trailing-stop-max-favorable-execution-mfe/

    http://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/

    To retrieve the current balance of your account, you need first to set a variable with the balance amount at the launch of the algorithm, because it is not possible to get it with code. Then just add the strategy profit to it and you’ll get the current balance amount:

    initialbalance = 9500 //set it one time at script launch
    currentbalance = initialbalance + STRATEGYPROFIT
    #9979 quote
    absent1980
    Participant
    Average

    Thank you, much appreciated.

    #9995 quote
    absent1980
    Participant
    Average

    I looked at some examples of cumulative orders but not entirely sure how to translate them into a buying order such as:

    Buying 1st order at price x, 2nd order at price x + variable, 3d order at the price of a previous order + variable

    There are examples for shares but there is no equivalent for spreadbetting where position expressed as £pp

    Example:

    DEFPARAM CumulateOrders = True
    If CountOfPosition < 2 THEN
     Buy 1 shares at 2 Limit
     Buy 1 shares at 3 Limit
    Endif
    #9999 quote
    Nicolas
    Keymaster
    Master

    You can find example of adding positions in the TRADEPRICE instruction page :

    http://www.prorealcode.com/documentation/tradeprice/

    #10004 quote
    absent1980
    Participant
    Average

    Tried suggested code but system constantly adds positions at stated interval, how to limit them to 3 ?

    IF c1 THEN
    BUY Positionsize PERPOINT AT MARKET
    ENDIF
    If CountOfPosition < 2 then
    ENDIF
    IF BARINDEX-TRADEINDEX(1)>increment AND Close-TRADEPRICE(1)>increment*2 AND LongOnMarket THEN
    BUY positionsize perpoint at market
    ENDIF

    Thank you.

    #10005 quote
    Nicolas
    Keymaster
    Master

    Your ENDIF at line 5 should be at the end of the code otherwise your count of position test is doing nothing.

    #10006 quote
    absent1980
    Participant
    Average

    Done that. Still buying/selling orders continuously until exit. I need to limit them to 3 or 4 max. Any ideas? Thanks

    #10008 quote
    absent1980
    Participant
    Average

    Seems to be working now. Thank you for your advice.

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

Trailing buy order


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
absent1980 @absent1980 Participant
Summary

This topic contains 8 replies,
has 2 voices, and was last updated by absent1980
9 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/26/2016
Status: Active
Attachments: No files
Logo Logo
Loading...