Breakeven or SL to entry code

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5806 quote
    davidp13
    Participant
    Average

    Hi. Is it possible to write code that sets your open positions SL to entry/breakeven once the trade has move positively into your direction with a certain number of points?

    Thanks

    #5809 quote
    zilliq
    Participant
    Master

    Hi David,

    Yes you can but the problem is that you probably stop very very often because you have generally à retracement before the impulsion in the good direction.

    See on Google the concept of maximum adverse excursion

    Have a nice day

    Zilliq (in holidays)

    #5812 quote
    Nicolas
    Keymaster
    Master

    Hi David, yes it’s possible with PROBACKTEST specific instructions.

    Here is a complete example on how to achieve your breakeven functionnality:

    If current buy order is in gain of 30 points, order will be closed at entry price + 5 points.

    defparam cumulateorders = false
    
    c1 = close>close[1]
    
    if c1 then
     BUY 1 LOT AT MARKET
     SET STOP PLOSS 50
    endif
    
    IF NOT ONMARKET THEN
     newSL=0
    ENDIF
    
    IF LONGONMARKET AND close-tradeprice(1)>=30*pipsize THEN
     newSL = tradeprice(1)+5*pipsize
    ENDIF
    
    IF newSL>0 THEN
     SELL AT newSL STOP
    ENDIF
    Bel thanked this post
    #7941 quote
    GunnerNic
    Participant
    New

    Hi Nicolas, is it possible to bring the SL to BE + 5 but keep the trade going and not exit it at that point?

    Would it be something like this then:

    // Stops and targets
    SET STOP PLOSS 50
    newSL = 0
    
    IF LONGONMARKET AND close-tradeprice(1)>=30*pipsize 
    THEN newSL = tradeprice(1)+5*pipsize 
    ENDIF 
    
    IF newSL>0 THEN 
    SET STOP PLOSS newSL
    ENDIF
    

    Tx

    Steve

    #8875 quote
    davidp13
    Participant
    Average

    Hi Nicholas,

    Three question on the above:

    1. Will GunnerNic’ code work?
    2. Your first code set will deactivate the SELL AT newSL STOP once the preceding IF statement is not true anymore, correct? So when close-tradeprice(1)>=30*pipsize is not true will the exit not work anymore until it becomes true again?
    3. Why do you use the (1) after tradeprice? What does it do?

    Thanks

    #8876 quote
    Nicolas
    Keymaster
    Master

    Hi David, didn’t see the Gunnernic reply before, so here is the answers for your 3 questions:

    1/ Gunnernic’ code will not work because PLOSS needs point information and not price one

    2/ Once this conditional statement is true one time, newSL will take its value. Since we do not use “else”, newSL will keep its value until a new one will be affected to it.

    3/ (1) is the previous number of the order we want to look at

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

Breakeven or SL to entry code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
davidp13 @davidp13 Participant
Summary

This topic contains 5 replies,
has 4 voices, and was last updated by Nicolas
9 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/22/2016
Status: Active
Attachments: No files
Logo Logo
Loading...