Strategy get stucks with ProBacktest with both long and short orders

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #63518 quote
    maximus78
    Participant
    Senior

    Good Morning guys,

    I need some help for the following simple strategy.

    Basically if i use the strategies in separated long and short versions, probacktest works fine, but if I use them together in this way probacktests start to calculate and gets stuck.

    Could someone help me and show me if I make some mistakes?

    Thanks a lot in advance.

    Max

    defparam cumulateorders=false
    
    // LONG STRATEGY
    
    barlimit =10
    c1=low[2]>low[1] and low[0]>low[1] and average[10](close)>average[24](close)
    
    if not longonmarket and c1 then
    entrylong=highest[1](high)+2*pointsize
    myindex=barindex
    SLlong=entrylong-(lowest[2](low)-2*pointsize)
    endif
    
    if barindex>=myindex + barlimit then
    entrylong =0
    endif
    
    if entrylong>0 and not longonmarket then
    BUY 1 shares at entrylong stop
    set stop loss SLlong trailing SLlong
    endif
    
    //-----------------------------------------------
    // SHORT STRATEGY
    
    barlimit =10
    c2=high[2]<high[1] and high[0]<high[1] and average[10](close)<average[24](close)
    
    if not shortonmarket and c2 then
    entryshort=lowest[1](low)-2*pointsize
    myindex=barindex
    SLshort=(highest[2](high)+2*pointsize)-entryshort
    endif
    
    if barindex>=myindex + barlimit then
    entryshort =0
    endif
    
    if entryshort>0 and not shortonmarket then
    sellshort 1 shares at entryshort stop
    set stop loss SLshort trailing SLshort
    endif
    
    graph entrylong as "entry long"
    graph entryshort as "entry short"
    graph entrylong-SLlong as "stop loss long"
    graph entryshort+SLshort as "stop loss short"
    #63520 quote
    Nicolas
    Keymaster
    Master

    You should name your variable differently for short and long side of the strategy. For example ‘myindex’ is used in both sides and could generate problem when you compare it with barindex at lines 14 and 35. This is just what first come in mind when reading your code.

    Of course as you already know it, you can have together long and short orders in the same strategy, one cancels other (also known as OCO).

    #63588 quote
    maximus78
    Participant
    Senior

    Hi Nicolas, I’ve changed the name of the variables in “mylongindex” and “myshortindex” as you suggested but it doesn’t work the same.

    I’ve also tried with “if not onmarket” instead of ” if not longonmarket” and “if not shortonmarket” but the system doesn’t work either.

    Have you some other ideas?

    Thanks

    Max

    #63597 quote
    robertogozzi
    Moderator
    Master

    I tested your code on Eur/Usd, h1, and it didn’t get stuck, as you can see from the screenshot.

    I only modified the names as suggested by Nicolas and commented out all GRAPH instructions.

    x-2.jpg x-2.jpg My-System.itf
    #63664 quote
    maximus78
    Participant
    Senior

    Hi Roberto, I’ve tried and it works only as soon as i shut and restart the platform, but when i relaunch the system it gets stuck.

    It always works with you ? Have you tried to launch it several times?

    Thanks

    Max

    #63680 quote
    robertogozzi
    Moderator
    Master

    Yes, it works anytime I launch it.

    #63836 quote
    maximus78
    Participant
    Senior

    Thanks Roberto, yes probably it’s my internet connection, but it has happened also on the pc where I work.

    Very strange it’s the first time that a system gets stuck.

    Now with the forex market closed it works everytime i launch it.

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

Strategy get stucks with ProBacktest with both long and short orders


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
maximus78 @maximus78 Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/22/2018
Status: Active
Attachments: 2 files
Logo Logo
Loading...