Chandelier Exits

Discussion in 'Technical Analysis' started by brownsfan019, Sep 13, 2007.

  1. This code includes the Parabolic and YoYo exits as well. I'd take it out, but don't have time right now, so you'll have to do that part...Hope that helps!

    I'm splitting it into 2 posts due to ET character restriction...

    //***************************************************************************************
    // LeBeau Stops Indicator (!G_LeBeau_Stops) *
    // ©JRG 2004, 2005, v8.1i, 20 Jul 2005 *
    //***************************************************************************************
    // NOTES: Implements Chuck LeBeau's family of stop loss techniques as briefed at *
    // TradeStation World 2004 *
    // Sends setings to compatible indicator for visual plotting using Global *
    // Variables *
    // Set Strategy MaxBarsBack = 150 -- set indicator same *
    // v8.0d -- Use GV error to set LeBeau defaults *
    // v8.1 -- Integrate 8.1 keywords -- update intrabar default on *
    // v8.1a - not applicable to indicator *
    // v8.1b - change GV setup to use AppID *
    // v8.1c - make for intrabar execution ONLY, change AvgRange to AvgRange *
    // change profit target tighten to 0.6 vs 0.5 (for Chan) *
    // v8.1d - tie parabolic initial stop to AvgEntryPrice *
    // v8.1e - prevent retracement (loosening) of Chandelier Stop *
    // v8.1f - use MIT stop for Chandelier and YoYo *
    // 050425 v8.1g - workaround for PT Boolean issue *
    // 050503 v8.1h - fix profit target multiplier error *
    // 050720 v8.1i - update Parabolic stop intrabar *
    //***************************************************************************************

    //***** Set-up *****
    INPUTS: Show_All_Stops ( False ),
    Commentary_On ( False ) ;

    VARIABLES: Chandelier_AvgRange ( 3 ), // inputs from strategy
    YoYo_AvgRange ( 2 ),
    Parabolic_AF ( 0 ),
    Acceleration_Factor ( 0.02 ),
    Parabolic_AF_Limit ( 0 ),
    AvgRange_Length ( 21 ),
    Average_Range ( 0 ),
    Market_Position ( 0 ),
    IntrabarPersist Trade_High ( 0 ),
    IntrabarPersist Trade_Low ( 0 ),
    IntrabarPersist YoYo_Amount ( 0 ), // YoYo stop amount
    YoYo_Price ( 0 ), // pin price to last bar close
    IntrabarPersist Chandelier_Stop ( 0 ),
    IntrabarPersist YoYo_Stop ( 0 ),
    Parabolic_Stop ( 0 ),
    Profit_AvgRange ( 0 ),
    PT_Average_Range ( 0 ),
    PT_Range_Length ( 21 ),
    Profit_Amount ( 0 ),
    Profit_Switch_Fac ( 1 ),
    EntryBar_Stop ( 0 ),
    IntrabarPersist Profit_Switch ( False ),
    GV_Name ( NumToStr( AbsValue( GetAppInfo( aiAppID ) ), 0 ) ), // 19 = aiWindowID
    Avg_Entry_Price ( 0 ),
    New_Entry ( False ) ;

    //***** Housekeeping *****
    if CurrentBar = 2 then // get Inputs from Strategy
    begin
    Chandelier_AvgRange = GVGetNamedDouble( GV_Name + "Chandelier_AvgRange", 3 ) ; // get strategy settings from global memory
    YoYo_AvgRange = GVGetNamedDouble( GV_Name + "YoYo_AvgRange", 2 ) ;
    Parabolic_AF = GVGetNamedDouble( GV_Name + "Parabolic_AF", 0.02 ) ;
    AvgRange_Length = GVGetNamedDouble( GV_Name + "LeBeau_AvgRange_Length", 21 ) ;
    Parabolic_AF_Limit = GVGetNamedDouble( GV_Name + "Parabolic_AF_Limit", 10 ) ; // set limit 10x factor
    Profit_AvgRange = GVGetNamedDouble( GV_Name + "Profit_AvgRange", 4 ) ;
    Profit_Switch_Fac = GVGetNamedDouble( GV_Name + "Profit_Switch_Factor", 1 ) ;
    PT_Range_Length = GVGetNamedDouble( GV_Name + "LePT_Range_Length", AvgRange_Length ) ;
    end ; // housekeeping

    //***** Compute Stops *****
    Market_Position = I_MarketPosition ; // in order to access historical bar market positions
    if BarStatus(1) = 2 then // calc only once per bar
    begin
    Average_Range = AvgRange( AvgRange_Length ) ;
    Avg_Entry_Price = I_AvgEntryPrice ;
    New_Entry = Avg_Entry_Price[1] <> Avg_Entry_Price ;
    PT_Average_Range = AvgRange( PT_Range_Length ) ;
    Profit_Amount = Round( Profit_AvgRange * PT_Average_Range, 2 ) ;
    YoYo_Amount = YoYo_AvgRange * Average_Range ;
    end ; // calc once
    if Market_Position[1] <> 0 then
    YoYo_Price = Close[1]
    else
    YoYo_Price = Open ;

    if Market_Position <> 0 then // eval market position on current bar
    begin

    //*** Long Position ***
    if Market_Position = 1 then
    begin
    if Market_Position[1] <> 1 or // eval market position on prior bar and reset variables if
    New_Entry then
    begin
    Profit_Switch = False ; // reset profit switch
    Trade_High = High ; // reset trade high
    end // reset
    else if High > Trade_High then // find new high
    Trade_High = High ;

    //* Chandelier Stop *
    if Profit_Switch or // if switch = true
    Trade_high >= I_AvgEntryPrice + ( Profit_Amount * Profit_Switch_Fac ) then
    begin
    Profit_Switch = True ;
    Chandelier_Stop = Round( Trade_High - ( Chandelier_AvgRange * Average_Range * Profit_Switch_Fac ), 2 ) ; // tighten stop
    end // tighten Chandelier stop when profit point exceeded
    else Chandelier_Stop = Round( Trade_High - ( Chandelier_AvgRange * Average_Range ), 2 ) ; // normal stop
    if Market_Position[1] = 1 and
    New_Entry = False and
    Chandelier_Stop < Chandelier_Stop[1] then
    Chandelier_Stop = Chandelier_Stop[1] ; // prevent retracement

    //* YoYo Stop *
    YoYo_Stop = Round( YoYo_Price - YoYo_Amount, 2 ) ;

    //* Parabolic Stop *
    if Market_Position[1] <> 1 or
    New_Entry then
    begin
    Parabolic_Stop = Chandelier_Stop ; // initial setting
    // Round( I_AvgEntryPrice - ( Chandelier_AvgRange * Average_Range ), 2 ) ; // tie to entry price
    Acceleration_Factor = Parabolic_AF ;
    end // eval market postion on prior bar
    else begin
    {if BarStatus(1) = 2 then
    begin}
    if Trade_High > Trade_High[1] and
    Acceleration_Factor < Parabolic_AF_Limit then
    Acceleration_Factor = Acceleration_Factor + MinList( Parabolic_AF, Parabolic_AF_Limit - Acceleration_Factor ) ;
    Parabolic_Stop = Parabolic_Stop + Acceleration_Factor * ( Trade_High - Parabolic_Stop ) ;
    if Parabolic_Stop > Low then // force stop <= low of last bar
    Parabolic_Stop = Low ;
    {end ;} // update only at end of bar
    end ; // long parabolic stop

    end // long market postion
     
  2. Here's the rest!


    //*** Short Position ***
    else begin // short market position
    if Market_Position[1] <> -1 or // eval market position on prior bar
    New_Entry then
    begin
    Profit_Switch = False ; // reset profit switch
    Trade_Low = Low ; // reset trade low
    end
    else if Low < Trade_Low then // find new low
    Trade_Low = Low ;

    //* Chandelier Stop *
    if Profit_Switch or // if switch = true
    Trade_Low <= I_AvgEntryPrice - ( Profit_Amount * Profit_Switch_Fac ) then
    begin
    Profit_Switch = True ;
    Chandelier_Stop = Round( Trade_Low + ( Chandelier_AvgRange * Average_Range * Profit_Switch_Fac ), 2 ) ; // tighten stop
    end // tighten Chandelier stop when profit point exceeded
    else Chandelier_Stop = Round( Trade_Low + ( Chandelier_AvgRange * Average_Range ), 2 ) ; // normal stop
    if Market_Position[1] = -1 and
    New_Entry = False and
    Chandelier_Stop > Chandelier_Stop[1] then
    Chandelier_Stop = Chandelier_Stop[1] ; // prevent retracement

    //* YoYo Stop *
    YoYo_Stop = Round( YoYo_Price + YoYo_Amount, 2 ) ;

    //* Parabolic Stop *
    if Market_Position[1] <> -1 OR
    New_Entry then
    begin
    Parabolic_Stop = Chandelier_Stop ;
    // Round( I_AvgEntryPrice + ( Chandelier_AvgRange * Average_Range ), 2 ) ; // tie to entry price

    Acceleration_Factor = Parabolic_AF ;
    end // eval market postion on prior bar
    else begin
    {if BarStatus(1) = 2 then
    begin}
    Parabolic_Stop = Parabolic_Stop + Acceleration_Factor * ( Trade_Low - Parabolic_Stop ) ;
    if Trade_Low < Trade_Low[1] and
    Acceleration_Factor < Parabolic_AF_Limit then
    Acceleration_Factor = Acceleration_Factor + MinList( Parabolic_AF, Parabolic_AF_Limit - Acceleration_Factor ) ;
    if Parabolic_Stop < High then
    Parabolic_Stop = High ;
    {end ;} // run once per bar
    end ; // short parabolic stop
    end ; // short market position
    end ; // in position

    //***** Plots *****
    if Market_Position[1] <> 0 or
    Market_Position <> 0 then
    begin
    if Show_All_Stops then
    begin
    Plot2( Parabolic_Stop, "Parabolic", Red ) ;
    Plot3( YoYo_Stop, "YoYo", Cyan ) ;
    Plot4( Chandelier_Stop, "Chandelier", White ) ;
    end // show all stops
    else begin // plot only closest stop
    if Market_Position = 1 or
    Market_Position[1] = 1 then
    begin
    if Chandelier_Stop > YoYo_Stop and
    Chandelier_Stop > Parabolic_Stop then
    Plot4( Chandelier_Stop, "Chandelier", White )
    else if YoYo_Stop > Parabolic_Stop then
    Plot3( YoYo_Stop, "YoYo", Cyan )
    else Plot2( Parabolic_Stop, "Parabolic", Red ) ;
    end ; // closest long stop
    if Market_Position = -1 or
    Market_Position[1] = -1 then
    begin
    if Chandelier_Stop < YoYo_Stop and
    Chandelier_Stop < Parabolic_Stop then
    Plot4( Chandelier_Stop, "Chandelier", White )
    else if YoYo_Stop < Parabolic_Stop then
    Plot3( YoYo_Stop, "YoYo", Cyan )
    else Plot2( Parabolic_Stop, "Parabolic", Red ) ;
    end ; // closest short stop
    end ; // only closest stop
    end ; // plots

    //***** Commentary *****
    if Commentary_On and
    AtCommentaryBar then
    Commentary(
    ( Date - ( Year( Date ) * 10000 ) ):0:0, Time:5:0,
    " -- BarNumber = ", CurrentBar:5:0, NewLine,
    "High = ", High, NewLine,
    "Low = ", Low, NewLine,
    "Open = ", Open, NewLine,
    "Close = ", Close, NewLine,
    "AvgRange Length = ", AvgRange_Length:0:0, NewLine,
    "AvgRange =", Average_Range:0:2, NewLine,
    "Chandelier AvgRange Multiplier = ", Chandelier_AvgRange:0:2, NewLine,
    "YoYo AvgRange Multiplier = ", YoYo_AvgRange:0:2, NewLine,
    "Parabolic Acceleration Factor = ", Parabolic_AF:0:3, NewLine,
    "Parabolic AF Limit = ", Parabolic_AF_Limit:0:2, NewLine,
    "Acceleration Factor = ", Acceleration_Factor:0:3, NewLine,
    "Profit Point AvgRange Multiplier = ", Profit_AvgRange:0:2, NewLine,
    "Profit Switch = ", Profit_Switch, Newline,
    "Market Position = ", Market_Position:0:0, NewLine,
    "Trade High = ", Trade_High:0:2, NewLine,
    "Trade Low = ", Trade_Low:0:2, NewLine,
    "Profit Amount = ", Profit_Amount:0:2, NewLine,
    "Chandelier Stop = ", Chandelier_Stop:0:2, NewLine,
    "YoYo Stop = ", YoYo_Stop:0:2, NewLine,
    "Parabolic Stop = ", Parabolic_Stop:0:2, NewLine
    ) ;
     
  3. Thanks TS