%Stop @ -2%

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #98379 quote
    Inertia
    Participant
    Master

    Hi all !

    I’d like to create a %Stop @ -2% (like today for instance) but from the “Dopen”.

    Why? Cause most of the time, the instrument bounce back a bit from the specific % amount of distribution…

    It should be something like the following but I have trouble replacing the (0) by the correct value…

    Any help please ?

    Thank you 😉

    // Conditions pour fermer une position en vente à découvert
    c1 = (DOpen(0) < 0)
    
    IF c1 THEN
    EXITSHORT AT MARKET
    ENDIF
    2-1.jpg 2-1.jpg
    #98382 quote
    robertogozzi
    Moderator
    Master

    Replace line 1 with:

    c1 = close <= (DOpen(0) * 0.98)
    Inertia thanked this post
    #98401 quote
    Inertia
    Participant
    Master

    Thank you Robertogozzi !

    It works fine until 0.99% but then it goes blank from 1.0, 1.1 onwards…

    #98402 quote
    robertogozzi
    Moderator
    Master

    From 1.0  onwards C1 will be false and there will be no exit due to stop loss.

    I think you also added some target profit.

    I am not sure I could understand what you really meant.

    Inertia thanked this post
    #98406 quote
    Inertia
    Participant
    Master

    Hi Robertogozzi,

    Thank you for your time !

    Your are right, it should mostly have a second “%TP” from the “Dopen” this time !

    Not a %stop cause it’s a short position :/ ! My mistake…

    So the strategy should then have “technically” two %Target Profit with and IF somewhere in the middle I suppose…like and OCO order.

    • (1) SET TARGET %PROFIT 1 like the code
    • AND
    • (2) If the TP (1) is not triggered then (2) … c1 = close <= (DOpen(0) * 2%)

    Is it clearer Roberto?

    Good night and thank you for your help.

    IF (c1) AND (c2) AND (c3) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    SELLSHORT positionsize CONTRACT AT MARKET
    ENDIF
    
    c4 = close <= (DOpen(0) * 0.8)
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    //trailing stop
    trailingstop = (close*0.0045)/pointsize
    if not onmarket then
    MINPRICE = close
    priceexit = 0
    endif
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close)
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then
    priceexit = MINPRICE+trailingstop*pointsize
    endif
    endif
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
    
    SET STOP %LOSS 0.5
    SET TARGET %PROFIT 1
    #98407 quote
    Vonasi
    Moderator
    Master

    In your code this is a 20% gain on a short:

    c4 = close <= (DOpen(0) * 0.8)
    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF

    2% would be 0.98 as Robertogozzi already said.

    This condition whether 2% or 20% will never be hit if you also have SET TARGET %PROFIT 1 in your code – which you do have.

    Inertia thanked this post
    #98408 quote
    Inertia
    Participant
    Master

    Ok, now I got it !

    Big thanks Vonasi and Robertogozzi !

    FYI for you, It gives even better results…

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

%Stop @ -2%


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Inertia @inertia Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Inertia
6 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/13/2019
Status: Active
Attachments: 1 files
Logo Logo
Loading...