Cant get Tradeindex Tradeprice and Countofposition to work

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5835 quote
    simon_json
    Participant
    Average

    Hi,

    I cant get this to work, I opens one order per bar:

    defparam preloadbars =4000
    
    // Conditions to enter long positions
    indicator1 = close
    indicator2 = TriangularAverage[4000](close)
    c1 = (indicator1 > indicator2)
    c2 = (indicator1 < indicator2)
    
    IF c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    IF c2 THEN
    sellshort 1 CONTRACT AT MARKET
    ENDIF
    
    // Counts the number of open shares or lots.
    
    MAXSHARES = COUNTOFPOSITION <= 3
    
    //let's add another order while price continue to get higher (more than 10 points)than the last order taken with a condition of 5 bars elapsed since then
    IF TRADEINDEX(1)>n AND Close-TRADEPRICE(1)>10 AND LongOnMarket AND MAXSHARES THEN
    BUY 1 SHARES AT MARKET
    ENDIF
    
    
    //let's add another order while price continue to get lower (more than 10 points) than the last order taken with a condition of 5 bars elapsed since then
    IF TRADEINDEX(1)>n AND TRADEPRICE(1)-Close>10 AND ShortOnMarket AND MAXSHARES THEN
    SELLSHORT 1 SHARES AT MARKET
    ENDIF
    
    
    //trailing stop for the whole orders
    SET STOP pTRAILING 15
    

     

    Please help.

    #5847 quote
    Nicolas
    Keymaster
    Master

    Hi,

    Where is defined your “n” variable?

    What is your problem exactly? You mentioned that you opened an order per bar, which is correct at first view of your code. Because, while c1 or c2 is true you open a trade and they are always true obviously! 🙂

    #5852 quote
    Adolfo
    Participant
    Senior
    IF NOT ONMARKET THEN
     IF c1 THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    IF c2 THEN
    sellshort 1 CONTRACT AT MARKET
    ENDIF
    ENDIF
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Cant get Tradeindex Tradeprice and Countofposition to work


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
simon_json @simon_json Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by Adolfo
9 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/22/2016
Status: Active
Attachments: No files
Logo Logo
Loading...