Orders are closing as soon as they are opened

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #78255 quote
    simeong
    Participant
    Average

    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!

    Your right I do apologise as I compared indicator 1 against indicator 1- when it should of been indicator 2. However I fixed this issue. So just to confirm the error is on the automated coding level and not at the indicator level ?

     

    Further I am using the 10 minute time frame. As you can see on the attachments

     

    Even when using the simplified creation tool(code below) I get the same error of orders closing as soon they they are placed.

    // 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
    indicator2, indicator1 = CALL aSpec
    c1 = (indicator1 >= indicator2)
    
    IF c1 AND timeEnterBefore AND timeEnterAfter THEN
    SELLSHORT 4 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator4, indicator3 = CALL aSpec
    c2 = (indicator3 CROSSES UNDER indicator4)
    
    IF c2 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pTRAILING 14

    Thanks again for all the input.

    Regards,

    Simeon

    10-min-2.png 10-min-2.png 10-min-1.png 10-min-1.png
    #78264 quote
    robertogozzi
    Moderator
    Master

    It seems to be working perfectly, always exiting due to the TRAILING stop. I embedded the indicator in the strategy (but this shouldn’t affect results):

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    currentHigh=High[0]
    previousHigh=High[1]
    currentClose=close[0]
    diffCurrentVSPreviousHigh=previousHigh-currentClose
    IF currentHigh>previousHigh THEN
       risingHigh=12
    else
       risingHigh=2
    ENDIF
    //return risingHigh,diffCurrentVSPreviousHigh
    noEntryBeforeTime = 143000
    timeEnterBefore = time >= noEntryBeforeTime
    noEntryAfterTime = 210000
    timeEnterAfter = time < noEntryAfterTime
    indicator2 = diffCurrentVSPreviousHigh
    indicator1 = risingHigh
    c1 = (indicator1 >= indicator2)
    c2 = (indicator1 CROSSES UNDER indicator2)
    IF c1 AND timeEnterBefore AND timeEnterAfter THEN
       SELLSHORT 4 PERPOINT AT MARKET
    ENDIF
    IF c2 and shortonmarket THEN
       EXITSHORT AT MARKET
    ENDIF
    SET STOP pLOSS 20 pTRAILING 14
    simeong thanked this post
    x-8.jpg x-8.jpg
    #78275 quote
    simeong
    Participant
    Average

    Hi Roberto,

    I cant thank you enough. Its great to know that my code works.

    When I did go through the losers , It seems the issue is still somewhat present as can be seen in the attachment below(I am not sure how clear it is so I have also typed them out below).

    Considering that the code works from a technical standpoint. Is this just a byproduct of the code(sometimes it will close orders as soon as they are opened) ?

    1 August OPEN: 20:50 CLOSE:20:50

    2 August OPEN: 14:50 CLOSE:14:50

    2 August OPEN: 15:00 CLOSE:15:00

    2 August OPEN: 17:40 CLOSE:17:40

    2 August OPEN: 17:50 CLOSE:17:50

    2 August OPEN:18:40 CLOSE:18:40

     

    Regards,

    Simone

     

    P.S the 2nd attachment showing a chart on  IG shows the corresponding price for the 2 August 17:40 close out. As I believe the order shouldn’t of closed as on the following 3 candles the current high is lower than the previous high.

    codeworks.png codeworks.png relevant-chart.png relevant-chart.png
    #78280 quote
    robertogozzi
    Moderator
    Master

    It works perfectly, I rarely experienced 0-bar trades, some are those you posted, but all of then are closed due to trailing stop.

    #78289 quote
    simeong
    Participant
    Average

    Hi Roberto,

    You are right. When I take away the ptrailing the orders don’t seem to close straight away.

    But as a trader it is very very rare for a stop to be hit in a second. ptrailing is points correct(because i set ‘ptrailing’ at 20 pips away from buy price) ?

    Anyway I thought it best to remove the ptrailing and find another solution as stops/limits seems to do more harm than good.

    Regards,

    #78290 quote
    robertogozzi
    Moderator
    Master

    But as a trader it is very very rare for a stop to be hit in a second. ptrailing is points correct(because i set ‘ptrailing’ at 20 pips away from buy price) ?

    Yes, right.

    • $Trailing  = sets trailing stop in units of your currency
    • Trailing    = sets trailing stop as a difference in price (say 0.0015) away from the price
    • pTrailing  = sets trailing stop as a number of pips (say 15) away from the price
    #78296 quote
    Nicolas
    Keymaster
    Master

    Topic moved to ProOrder forum.

    FYI, trailing stop are not allowed for limited risk accounts, if your live or demo account is a limited risk one, the backtest behavior should reflect this limitation.

Viewing 7 posts - 16 through 22 (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...