Need help with FX trail!

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #73693 quote
    bezieh
    Participant
    Average

    Hey guys!

    I got this code for trailing, and it works as it should in index markets, but for forex, it has no affect, it doesn’t work, no matter whatever values you put in it.
    Can someone please help me with this problem? I’d really appreciate it!

    Heres the FULL code!

    //trailing stop 1
    trailingstop1 = 70
    bottomTrailingStopValue1 = 30
    TopTrailingStopValue1 = 70
    
    //trailing stop 2
    //trailingstop2 = 10
    //bottomTrailingStopValue2 = 71
    //TopTrailingStopValue2 = 150"
    
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE1 = 0
    priceexit1 = 0
    endif
    
    a = close-tradeprice(1) > bottomTrailingStopValue1*pointsize
    b = close-tradeprice(1) < TopTrailingStopValue1*pointsize
    
    //case LONG order
    if longonmarket then
    MAXPRICE1 = MAX(MAXPRICE1,close) //saving the MFE of the current trade
    if a and b then
    if MAXPRICE1-tradeprice(1)>=trailingstop1*pointsize then //if the MFE is higher than the trailingstop then
    priceexit1 = MAXPRICE1-trailingstop1*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    endif
    
    //exit on trailing stop price levels
    if onmarket and priceexit1>0 then
    EXITSHORT AT priceexit1 STOP
    SELL AT priceexit1 STOP
    endif
    
    //resetting variables when no trades are on market
    //if not onmarket then
    //MAXPRICE2 = 0
    //priceexit2 = 0
    //endif
    
    //a2 = close-tradeprice(1) > bottomTrailingStopValue2*pointsize
    //b2 = close-tradeprice(1) < TopTrailingStopValue2*pointsize
    
    //case LONG order
    //if longonmarket then
    //MAXPRICE2 = MAX(MAXPRICE2,close) //saving the MFE of the current trade
    //if a2 and b2 then
    //if MAXPRICE2-tradeprice(1)>=trailingstop2*pointsize then //if the MFE is higher than the trailingstop then
    //priceexit2 = MAXPRICE2-trailingstop2*pointsize //set the exit price at the MFE - trailing stop price level
    //endif
    //endif
    //endif
    
    //exit on trailing stop price levels
    //if onmarket and priceexit2>0 then
    //EXITSHORT AT priceexit2 STOP
    //SELL AT priceexit2 STOP
    //endif
    #73695 quote
    Vonasi
    Moderator
    Master

    This is a ProOrder question rather than a General Trading Discussion topic so I have moved it to that forum.

    Also please use the ‘Insert PRT Code’ button when putting code in your post. I have tidied up your post for you 🙂

    #73701 quote
    GraHal
    Participant
    Master

    Try using pipvalue or pointvalue (instead of pointsize) and let us know how you get on … better, worse or same!? 🙂

    #73705 quote
    bezieh
    Participant
    Average

    Same, doesnt work unfortunately

    #73711 quote
    GraHal
    Participant
    Master

    Is there any code you are not showing above?

    FX does not have volume with IG, that was the first thing I looked for. You are not using volume or an indicator that needs volume are you?

    #73714 quote
    bezieh
    Participant
    Average

    just tested it with a simple buy over bollinger cross, and realised it doesnt work..

    #73715 quote
    robertogozzi
    Moderator
    Master

    Value in line 2 is too big, since it is = TopTrailingStopValue1, thus line 24 bwill never be true.

    Try any value between 31 and 69.

    #73716 quote
    bezieh
    Participant
    Average

    “It doesn’t work, no matter whatever values you put in it”

    #73717 quote
    bezieh
    Participant
    Average

    Works for index though..

    #73718 quote
    robertogozzi
    Moderator
    Master

    I have tried this either on Dax h1 and Eur/Usd h1, and it always worked with a value of trailingstop1 = 40:

    DEFPARAM CumulateOrders = False
    trailingstop1 = 40
    bottomTrailingStopValue1 = 30
    TopTrailingStopValue1 = 70
    if not onmarket then
    MAXPRICE1  = 0
    priceexit1 = 0
    endif
    a = close-tradeprice(1) > bottomTrailingStopValue1*pointsize
    b = close-tradeprice(1) < TopTrailingStopValue1*pointsize
    if longonmarket then
    MAXPRICE1 = MAX(MAXPRICE1,close) //saving the MFE of the current trade
    if a and b then
    if MAXPRICE1-tradeprice(1)>=trailingstop1*pointsize then //if the MFE is higher than the trailingstop then
    priceexit1 = MAXPRICE1-trailingstop1*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
    endif
    if onmarket and priceexit1>0 then
    EXITSHORT AT priceexit1 STOP
    SELL AT priceexit1 STOP
    endif
    IF close CROSSES OVER average[20,0](close) THEN
    BUY AT MARKET
    SET TARGET pPROFIT 250
    SET STOP   pLOSS   200
    ENDIF
    graph a
    graph b
    graph MAXPRICE1
    graph priceexit1
    graph MAXPRICE1-tradeprice

    did you use GRAPH?

    x-4.jpg x-4.jpg
    #73722 quote
    GraHal
    Participant
    Master

    Roberto version code above works for me also on Dax h1 and Eur/Usd h1.

    For interest, equity curve on the Dow over 10k bars attached.

    Bez-2.jpg Bez-2.jpg Bez-3.jpg Bez-3.jpg Bez-2-1.jpg Bez-2-1.jpg
    #73827 quote
    bezieh
    Participant
    Average

    but one the one i posted, u can have bottomtrail twice, on the one u sent, its bottomtrail once only. i want two different trail stops, can u add it for me on the one that works? 🙂

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

Need help with FX trail!


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
bezieh @bezieh Participant
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by bezieh
7 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/19/2018
Status: Active
Attachments: 4 files
Logo Logo
Loading...