Orders are closing as soon as they are opened

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #78183 quote
    simeong
    Participant
    Average

    Hi,

    Recently I have noticed when I have been doing back test that my orders are being closed as soon as they are opened(within miniseconds). I was wondering if anyone else has faced this same issue ?

    I also experienced this issue when I tried to run the automated trading on an IG demo account. So as you can imagine I am very concerned about running a live test untill I find a fix for this issue.

    backtest-shut-out.png backtest-shut-out.png
    #78198 quote
    robertogozzi
    Moderator
    Master

    To be able to replicate the trades you should post:

    1. code
    2. instrument
    3. TF
    #78199 quote
    Vonasi
    Moderator
    Master

    What time frame are you trading on? 1 second?

    This topic may need to be moved to the ProOrder forum rather than be in the Platform Support forum as I suspect it is a strategy issue rather than a platform issue.

    #78225 quote
    simeong
    Participant
    Average

    Hi Roberto,

    sorry for that. I thought maybe they was an update or something as the code was working fine previously. Please find attached the code that I am using on the autotrade stystem.

     

    // code for brackets
    
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    // Cancel all pending orders and close all positions at the "FLATAFTER" time
    DEFPARAM FLATAFTER = 204000
    
    // Setting Up Time Framework
    noEntryBeforeTime = 143000
    timeEnterBefore = time >= noEntryBeforeTime
    
    noEntryAfterTime = 2040000
    timeEnterAfter = time < noEntryAfterTime
    
    // Conditions to enter short positions
    ignored, indicator2, indicator1 = CALL "Algo for dojo visualStudio"
    c1 = (indicator1 >= indicator2)
    ignored, indicator3 = CALL clamp
    c2 = (indicator3 = -30)
    
    IF (c1 and c2)  AND timeEnterBefore AND timeEnterAfter THEN
    SELLSHORT 4 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    ignored, indicator5, indicator4 = CALL "Algo for dojo visualStudio"
    c3 = (indicator4 CROSSES UNDER indicator5)
    ignored, indicator6 = CALL clamp
    c4 = (indicator6 = 30)
    
    
    IF c3 and c4  THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS 20 
    SET STOP pTRAILING 14
    
    
    
    
    
    #78226 quote
    simeong
    Participant
    Average

    Hi Vonasi,

    Thanks for getting back to me. Just wondering if you have ever come across an issue like this before ?

    I am using a 10 minute timeframe. Both on the chart and on the automated system.

    The system is being used in conjunction with IG.

     

    Kind Regards,

    Simone

    #78227 quote
    GraHal
    Participant
    Master

    my orders are being closed as soon as they are opened(within miniseconds)

    I’ve had above Issue before, but I can’t recall what caused it (it was a coding issue though) it will probably come to me as I go about my activities today.

    I’ll let you know.

    #78228 quote
    robertogozzi
    Moderator
    Master

    Sorry, I don’t have the code to replicate those indicators, if you post them then you should also specify TF and instrument used.

    Try replacing line 32 with

    IF c3 and c4  AND ShortOnMarket THEN

    but that’s just guessing!

    simeong thanked this post
    #78234 quote
    Vonasi
    Moderator
    Master

    Yes I think line 32 is the problem because if at the time of entry c1, c2, c3 and c4 conditions are all met then it will place a sellshort order and an exitshort order at the same time. You need to make the conditions return a 1 or 0 and graph them to see what they are doing at each entry.

    simeong thanked this post
    #78244 quote
    simeong
    Participant
    Average

    Hi Grahal,

    Thanks for reaching out.

    I really hope you do as I am really stumped.

    Kind Regards,

    #78245 quote
    robertogozzi
    Moderator
    Master

    Yes I think line 32 is the problem because if at the time of entry c1, c2, c3 and c4 conditions are all met then it will place a sellshort order and an exitshort order at the same time. You need to make the conditions return a 1 or 0 and graph them to see what they are doing at each entry.

    Still it’s odd, since ProOrder needs a full bar to be able to detect an ONMARKET status, thus line 33 should not be executed, unless ProOrder does not test the ONMARKET status but sends the order to the broker, instead, or he uses a 1-second TF!

    #78246 quote
    simeong
    Participant
    Average

    Hi Roberto & Vonasi,

    Thanks for taking the time to go through the code. I appreciate all the suggestions

    I have simplified the code and started from scratch in an attempt locate the issue.

    So please find attached the new simplified code that is throwing up the same issue of closing before it opens. However it should be noted that it is doing it less often than before.

    Looking forward to your suggestions,

     

    Regards

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Prevents the system from creating new orders to enter the market or increase position size before the specified time
    noEntryBeforeTime = 143000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 210000
    timeEnterAfter = time < noEntryAfterTime
    
    // Conditions to enter short positions
    ignored, indicator1 = CALL airlineSpec
    c1 = (indicator1 >= indicator1)
    
    IF c1 AND timeEnterBefore AND timeEnterAfter THEN
    SELLSHORT 4 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    ignored, indicator2 = CALL airlineSpec
    c2 = (indicator2 CROSSES UNDER indicator2)
    
    IF c2 and shortonmarket THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS 20 pTRAILING 14
    currentHigh=High[0]
    previousHigh=High[1]
    currentClose=close[0]
    
    
    
    //Bearish sign
    diffCurrentVSPreviousHigh=previousHigh-currentClose
    
    
    IF currentHigh>previousHigh THEN
    risingHigh=12
    else
    risingHigh=2
    ENDIF
    
    
    
    
    
    
    return risingHigh,diffCurrentVSPreviousHigh
    
    #78247 quote
    robertogozzi
    Moderator
    Master

    Line 14 will always be true and line 22 will always be false.

    Please post the correct lines!

    #78250 quote
    robertogozzi
    Moderator
    Master

    Line 29 is not allowed (despite being documented), you cannot combine two kind of SL at the same time and, if you separate them on two lines the second line will overwrite the previous one!

    #78251 quote
    Vonasi
    Moderator
    Master

    Still it’s odd, since ProOrder needs a full bar to be able to detect an ONMARKET status, thus line 33 should not be executed, unless ProOrder does not test the ONMARKET status but sends the order to the broker, instead, or he uses a 1-second TF!

    …..going back to that first code – there is no check for ONMARKET status to be met for line 33 so if the exit conditions c3 and c4 are met then an exit order will be sent at the same time as a buy order.

    From that first code:

    IF c3 and c4  THEN
    EXITSHORT AT MARKET
    ENDIF
    #78252 quote
    robertogozzi
    Moderator
    Master

    EXITSHORT should NOT be interpreted as a BUY order, but the EXIT of a SHORT trade. If there’s no SHORT trade open then EXITSHORT should be ignored, isn’t it?

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

Orders are closing as soon as they are opened


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
simeong @simeong Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/14/2018
Status: Active
Attachments: 6 files
Logo Logo
Loading...