Help Double SL and Target with reversal exit

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #156664 quote
    Tanou
    Participant
    Senior

    Hello everyone 🙂 ,

     

    I come to you because I am lost and I spend almost the entire day trying to sort out this problem.

     

    The problem comes from the tp/sl and reversal of the strategy.

     

    I’d like that if the condition “l1” is ok that it buys at market with a sl that is this condition:

    If xHigh crosses under (OpenPrice-x) then

    and that it gets a 10 tp. BUT then I’d like that if the results of this trade is negative that it immediatly opens a trade in the other way with the SL condition:

    If xLow crosses over(OpenPrice+x) then

    and a TP of the amount of the losses of the previous trade.

     

    If someone could help me it would be amazing…!

     

    Thanks! 😀

     

     

    Just to help you, here is the base of the code.. 😉

    DEFPARAM CumulateOrders = false
    DEFPARAM Preloadbars = 50000
    
    //HORAIRES DE TRADING
    Ctime = time >= 153000 and time < 220000
    //--------------------------------------
    
    //Nouveau OpenPrice et OpenDay a 15:30
    IF OPENTIME = (153000) then
    OpenPrice = Open
    OpenD = OpenDay
    ENDIF
    //------------------------------------
    
    //Représentation graphique Heikin-Ashi
    once xOpen = open
    Price = (open + close + low + high)/4
    if barindex > 0 then
    xOpen  = (xOpen + Price[1]) / 2
    endif
    xLow     = min(low,min(Price,xOpen))
    xHigh    = max(high,max(Price,xOpen))
    GreenHA    = Price > xOpen
    RedHA      = Price < xOpen
    //------------------------------------
    
    
    x=20 //Taille de la zone autour de l'ouverture pour activation/Désactivation
    
    //Remise à 0 des variables
    If OpenD<>OpenD[1] then
    l = 0
    s = 0
    Endif
    
    // STRATEGIE ---------------------------------------------------------------------------------
    
    // Conditions Short
    If s=0 and l=0and ctime then
    If xHigh=xOpen and xHigh<(OpenPrice-x) then
    s1 = 1
    Else
    s1 = 0
    Endif
    Endif
    
    
    //Conditions Long
    If l=0 and s=0 and ctime then
    If xLow=xOpen and xLow>(OpenPrice+x) then
    l1 = 1
    Else
    l1=0
    Endif
    Endif
    
    //-------------------------------------------------------------------------------------------
    
    //POSITION LONGUE
    IF l1 THEN
    Buy 1 contract at market
    l1 = 0
    l = 1
    a = 1
    ENDIF
    
    
    IF LONGONMARKET THEN
    SET TARGET PROFIT (10)
    If xHigh crosses under (OpenPrice-x) then
    Sell at market
    s1 = 1
    endif
    ENDIF
    
    If SHORTONMARKET and s1 then
    Sellshort 1 contract at market
    s1=0
    Endif
    
    //POSITION LONGUE
    //IF l1 THEN
    //Buy 1 contract at market
    //l1 = 0
    //l = 1
    //posl1 = tradeindex
    //ENDIF
    //
    //if Posl1>0 then
    //Set target pprofit 10
    //If xHigh crosses under (OpenPrice-x) then
    //sell at market
    //posl1 = 0
    //If positionperf(1)>0 then
    //graph positionperf(1)
    //Sellshort 1 contract at market
    //Posl2 = tradeindex
    //endif
    //Endif
    //Endif
    //
    //If posl2>0 then
    //Exitshort at (OpenPrice+x) stop
    //Set target pprofit 30
    //Posl2 = 0
    //Endif
    
    ////POSITION COURTE
    //IF s1 THEN
    //Sellshort 1 contract at market
    //s1 = 0
    //s = 1
    //poss1 = 1
    //ENDIF
    //
    //
    //
    //
    //if poss1>0 then
    //Set target pprofit 10
    //If xLow crosses over (OpenPrice+x) then
    //Exitshort at market
    //poss1 = 0
    //If positionperf(1)>0 then
    //Buy 1 contract at market
    //poss2 = tradeindex
    //Endif
    //Endif
    //Endif
    //
    //If poss2>0 then
    //sell at (OpenPrice-x) stop
    //Set target pprofit 20
    //poss2 = 0
    //endif
    //
    #156670 quote
    Tanou
    Participant
    Senior

    I turned it in all the way that I can but I still have some problems :'(

    #156671 quote
    Tanou
    Participant
    Senior

    @Robertogozzi, @Nicolas , If you come by do not hesitate if you find something… I would be very grateful…

    #156689 quote
    Nicolas
    Keymaster
    Master

    How and when do you check that the order is turning negative please?

    #156699 quote
    Tanou
    Participant
    Senior

    Hello Nicolas,  Happy new year andvery glad to see you here 😀 ,

     

    Maybe I should told it differently:

    I’d like the system to take long or short with this condition:

    // Conditions Short
    If xHigh=xOpen and xHigh<(OpenPrice-x) then
     
    //Conditions Long
    If xLow=xOpen and xLow>(OpenPrice+x) then
    

    This order would have a Take Profit of 10 and the Stop Loss would be :

    //In the case of a Long
    If xHigh crosses under (OpenPrice-x) then
    
    //In the case of a Short
    If xLow crosses over (OpenPrice+x) then

    Then if the results of this first closed trade is negative that it immediatly opens a trade in the opposite direction (short if it was long / long if it was short) with the (same) SL condition:

     

    The idea of this code is to get a ruban of 20 points above and under the opening of the US market at 15:30 to 22:00. When a full heikin ashi with a “flat ass” exits of the band it should buy or sell (depend if it exits by the top or the bottom). If the trade get 10 points it closed the position and waits for the next day. However, if it had a losses (by exiting the band in the other side) it should immediatly take another trade in the opposite direction of the first one with a take profit equals to the loss of the previous trade.

    With this program I should have only one trade (if it is positive) or two trades (if the first one is a loss ) a day

    Hope it make more sense…

    Thanks so much!

    #156790 quote
    Tanou
    Participant
    Senior

    @Nicolas, have you any ideas? :/

    #156858 quote
    Nicolas
    Keymaster
    Master

    Well, so based on these conditions, open the new orders:

    //In the case of a Long
    If xHigh crosses under (OpenPrice-x) then
     sellshort at market 
    endif 
    //In the case of a Short
    If xLow crosses over (OpenPrice+x) then  
     buy at market 
    endif
    #158291 quote
    JC_Bywan
    Moderator
    Master

    Topic moved from french forum to english forum as you chose English language in the starting post. Please read posting rules in big yellow box at bottom of the page, thank you.

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

Help Double SL and Target with reversal exit


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Tanou @tanou Participant
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by JC_Bywan
5 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/06/2021
Status: Active
Attachments: No files
Logo Logo
Loading...