Doesn't take long positions?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #97456 quote
    umebonumebon
    Participant
    Average

    Whats wrong with this code, it only takes short positions and not long. I want to run it on EUR/USD 1 h

    I can’t see whats wrong but I am learning….

    DEFPARAM CumulateOrders = False
    
    // Define start and closing time
    DEFPARAM FlatBefore = 080000
    DEFPARAM FlatAfter = 210000
    
    // Conditions and indicators for the system
    //MA = Average[30](close) // Simple moving average
    X = 4 // Number of contracts
    cond1 = ((High[0]-Low[0])/2) > Supertrend[3,10] // Conditions for long positions
    cond2 = ((High[0]-Low[0])/2) < Supertrend[3,10] // Conditions for short positions
    
    // Long positions
    IF (cond1) THEN
    BUY X CONTRACTS AT MARKET
    ENDIF
    
    IF LONGONMARKET AND (cond2) THEN
    SELL AT MARKET
    ENDIF
    
    // Short positions
    IF (cond2) THEN
    SELLSHORT X CONTRACTS AT MARKET
    ENDIF
    
    IF SHORTONMARKET AND cond1 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pTrailing 4
    
    #97460 quote
    GraHalGraHal
    Participant
    Legend

    cond1 is never going to be > ST

    cond2 is always going to be < ST

    I often hesitate to help with code (as I’m great either! 🙂 ) but substitute values in your cond 1 and 2 and you will see.  E.g. high  11230 high – 11210 low / 2 = 10 so it is always going to be lower than ST and never higher … unless you get the biggest spike ever seen? 🙂

    cond1 = ((High[0]-Low[0])/2) > Supertrend[3,10] // Conditions for long positions
    cond2 = ((High[0]-Low[0])/2) < Supertrend[3,10] // Conditions for short positions

    If you use Close > Supertrend etc then it will work.

    #97461 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    I suggest to modify lines 10-11 as follows (though this won’t affect performance, it’s just makes code easier to read:

    cond1 = (range/2) > Supertrend[3,10] // Conditions for long positions
    cond2 = (range/2) < Supertrend[3,10] // Conditions for short positions
    

    I think if you switch the order in which trades are opened, Short ones first, the results would be only short trades.

    You are comparing half the range with ST, I can’t imagine what your goal is.

    After line 32 add these lines, then check those values in the variable window of ProBackTest each candle:

    graph Range

    graph Range/2

    graph Supertrend[3,10]

    #97462 quote
    umebonumebon
    Participant
    Average

    Tnx for the respons, Im am trying too learn the program and how I can program.

    #97468 quote
    GraHalGraHal
    Participant
    Legend

    Im am trying too learn the program and how I can program.

    No probs, keep on asking no matter how daft it seems … I will probably learn something also! 🙂

    umebon thanked this post
    #97469 quote
    umebonumebon
    Participant
    Average

    I am trying too program an easy program for the 1 h EUR/USD but i don’t really get it too work. But i am learning every day…

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Doesn't take long positions?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
umebon @umebon Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by umebonumebon
7 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/01/2019
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...