NexusFi: Find Your Edge


Home Menu

 





trailing stop à la LeBeau


Discussion in EasyLanguage Programming

Updated
    1. trending_up 9,787 views
    2. thumb_up 9 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

trailing stop la LeBeau

(login for full post details)
  #1 (permalink)
 kiasom 
Stockholm
 
Experience: Intermediate
Platform: MC
Trading: fx
Posts: 16 since Apr 2010
Thanks Given: 139
Thanks Received: 23

This is a package of trailing stops by Chuck LeBeau.
It's a HH/LL stop (called a Chandelier' stop), a Parabolic stop, and a so called Yo-yo stop. They work together, all of the stops are applied at once and the closest one to the price becomes the dominant/active one.
Below is code for a Stops Strategy, and in the next post an indicator that plots what the signal is doing.

Set Strategy MaxBarsBack = 150 -- set indicator same *

If you use Range or Renko Bars - The Chandelier Stop turns into a conventional Trailing Stop.
The indicator will not show the stops unless the chart is in a trade position.
The indicator has the option of displaying all of the stop plots or just the plot closest
to the price - using the True/False "Show_All_Stops" switch in the indicator format.

 
Code
//***************************************************************************************
// LeBeau Stops Strategy (!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.                                                *
//            Includes protective stop on entry bar equal to YoYo stop.                    *
//            Allows negative numbers for optimization -- converts to absolute for        *
//                strategy execution.  ex = from -10 to -5, step 1.                        *
//            Sends strategy INPUT setings to compatible indicator for visual plotting    * 
//                using "native" Global Variables.  GlobalVariable.dll must be installed    *
//                in the "TradeStation/Program" folder.                                    *
{Set Strategy MaxBarsBack = 150 -- set indicator same                        *
All of the stops are applied at once -- 
The closest one to the price (tightest) becomes the dominant/active one.    
If you use Range or Renko Bars - The Chandelier Stop turns into a conventional Trailing Stop.
The indicator will not show the stops unless the chart is in a trade position.
The indicator has the option of displaying all of the stop plots or just the plot closest 
to the price - using the True/False "Show_All_Stops" switch in the indicator format. 
CurrentBar=2 is used to make sure the strategy is fully loaded before the GV is retrieved.
}

    [IntrabarOrderGeneration = True]

    INPUTS:    Chandelier_AvgRange        (2.5),
            YoYo_AvgRange            (2),
            Times_Touched            (10),        // MIT only if Chandelier and YoYo
            Parabolic_Accel_Factor    (.05),        // equity default -- for futures use 0.01 +-
            AvgRange_Length            (21),
            Profit_AvgRange            (1),
            Profit_Switch_Factor    (0.6),
             Commentary_On              ( False ) ;                                

 VARIABLES:                 aChandelier_AvgRange( AbsValue( Chandelier_AvgRange ) ),    //----------------------------------|
                            aYoYo_AvgRange        ( AbsValue( YoYo_AvgRange ) ),            //                                    |
                            Parabolic_AF        ( AbsValue( Parabolic_Accel_Factor ) ),    // convert inputs to absolute value    |
                            aAvgRange_Length    ( AbsValue( AvgRange_Length) ),            //                                    |
                            aProfit_AvgRange    ( AbsValue( Profit_AvgRange ) ),        //----------------------------------|
                            Acceleration_Factor    ( Parabolic_AF ),
                            Parabolic_AF_Limit    ( Parabolic_AF * 10 ),    // set limit 10x factor
                            Average_Range        ( 0 ),
                            Market_Position        ( 0 ),
            IntrabarPersist Trade_High            ( 0 ),        // highest high of current trade
            IntrabarPersist    Trade_Low            ( 0 ),        // lowest low of current trade
                            YoYo_Amount            ( 0 ),        // YoYo stop amount
                            YoYo_Price            ( 0 ),        // pin price to last bar close
            IntrabarPersist Chandelier_Stop        ( 0 ),        //--------------|
            IntrabarPersist YoYo_Stop            ( 0 ),        // stop prices    |
                            Parabolic_Stop        ( 0 ),        //--------------|
                            Profit_Amount        ( 0 ),
            IntrabarPersist    Profit_Switch        ( False ),    // point at which Chandalier Stop tightens
                            Not_Optimizing        ( True ),
                            GV_Name                ( NumToStr( AbsValue( GetAppInfo( aiAppID ) ), 0 ) ),
                            PT_On                ( False ),    // get from PT_MIT strategy
            IntrabarPersist Chandelier_Touched    ( 0 ),
            IntrabarPersist YoYo_Touched        ( 0 ),
            IntrabarPersist Bar_Number            ( 0 ),
                            PT_Range_Mult        ( aProfit_AvgRange ),
                            PT_Range_Length        ( aAvgRange_Length ),
                            PT_Average_Range    ( 0 ),
                            Avg_Entry_Price        ( 0 ),
                            aProfit_Switch_Fac     ( AbsValue( Profit_Switch_Factor ) ),
                            New_Entry            ( False ) ;

//***** Housekeeping *****
    if CurrentBar = 1 then
        Not_Optimizing = GetAppInfo( aiOptimizing ) <> 1 ;
//------------------------------------------------------------------------------------------|
//    This code gets the PT_MIT strategy settings to calculate the PT settings of the LeBeau    |
//        Stops.  If no PT_MIT present, then uses local LeBeau settings.                      |    
//------------------------------------------------------------------------------------------|
    if CurrentBar = 2 then
        begin
            PT_Range_Mult = GVGetNamedDouble( GV_Name + "PT_Range_Mult", aProfit_AvgRange ) ;
            PT_Range_Length = GVGetNamedDouble( GV_Name + "PT_Range_Length", aAvgRange_Length ) ;
            if Not_Optimizing then
                begin
                    Value1 = GVSetNamedDouble( GV_Name + "Chandelier_AvgRange", aChandelier_AvgRange ) ;
                    Value2 = GVSetNamedDouble( GV_Name + "YoYo_AvgRange", aYoYo_AvgRange ) ;
                    Value3 = GVSetNamedDouble( GV_Name + "Parabolic_AF", Parabolic_AF ) ;
                    Value4 = GVSetNamedDouble( GV_Name + "LeBeau_AvgRange_Length", aAvgRange_Length ) ;                    
                    Value6 = GVSetNamedDouble( GV_Name + "Parabolic_AF_Limit",Parabolic_AF_Limit ) ; 
                    Value5 = GVSetNamedDouble( GV_Name + "Profit_AvgRange", PT_Range_Mult ) ;
                    Value7 = GVSetNamedDouble( GV_Name + "LePT_Range_Length", PT_Range_length ) ;
                    Value8 = GVSetNamedDouble( GV_Name + "Profit_Switch_Factor", aProfit_Switch_Fac ) ;
                end ;    // not optimizing
        end ;    // 2nd bar housekeeping

//***** Compute Stops *****
    Market_Position = MarketPosition ;        // in order to access historical bar market position
    if BarStatus(1) = 2 then                // calc only once per bar
        begin
            Average_Range = AvgRange( aAvgRange_Length ) ;
            Avg_Entry_Price = AvgEntryPrice ;
            New_Entry = Avg_Entry_Price[1] <> Avg_Entry_Price ;
            PT_Average_Range = AvgRange( PT_Range_Length ) ;
            Profit_Amount = roundInst( PT_Range_Mult * PT_Average_Range) ;
            YoYo_Amount = aYoYo_AvgRange * Average_Range ;
        end            // calc once
    else if Bar_Number <> CurrentBar then        // calc on first tick of new bar formation
        begin
            Bar_Number = CurrentBar ;
            if Not_Optimizing and
                GetAppInfo( aiRealTimeCalc ) = 1 then
                begin
                    Chandelier_Touched = 0 ;
                    YoYo_Touched = 0 ;
                end        // reset at end of bar if not optimizing
            else begin
                    Chandelier_Touched = Times_Touched ;
                    YoYo_Touched = Times_Touched ;
                end ;    // if optimizing, set to limit
        end ;    // reset touched each new bar

    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
                        New_Entry then        // eval market position on prior bar and reset variables if 
                        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 >= AvgEntryPrice + ( Profit_Amount * aProfit_Switch_Fac ) then
                            begin
                                Profit_Switch = True ;
                                Chandelier_Stop = roundInst( Trade_High - ( aChandelier_AvgRange * Average_Range * aProfit_Switch_Fac )) ;// tighten stop
                            end        // tighten Chandelier stop when profit point exceeded
                    else Chandelier_Stop = roundInst( Trade_High - ( aChandelier_AvgRange * Average_Range )) ;// 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
                    if Close <= Chandelier_Stop then 
                        Chandelier_Touched = Chandelier_Touched + 1 ;

        //* YoYo Stop *
                    YoYo_Stop = roundInst( YoYo_Price - YoYo_Amount) ;
                    if Close <= YoYo_Stop then 
                        YoYo_Touched = YoYo_Touched + 1 ;

        //* Parabolic Stop *
                    if Market_Position[1] <> 1 or
                        New_Entry then
                            begin
                                Parabolic_Stop = Chandelier_Stop ;        // initial setting
//                                    roundInst( AvgEntryPrice - ( aChandelier_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

    //*** Short Position ***
            else begin        // short market position
                if Market_Position[1] <> -1 or
                    New_Entry then        // eval market position on prior bar
                        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 <= AvgEntryPrice - ( Profit_Amount * aProfit_Switch_Fac ) then
                        begin
                            Profit_Switch = True ; 
                            Chandelier_Stop = roundInst( Trade_Low + ( aChandelier_AvgRange * Average_Range * aProfit_Switch_Fac )) ;// tighten stop
                        end        // tighten Chandelier stop when profit point exceeded
                else Chandelier_Stop = roundInst( Trade_Low + ( aChandelier_AvgRange * Average_Range )) ;    // 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
                if Close >= Chandelier_Stop then
                    Chandelier_Touched = Chandelier_Touched + 1 ;

        //* YoYo Stop *
                YoYo_Stop = roundInst( YoYo_Price + YoYo_Amount) ;
                if Close >= YoYo_Stop then 
                    YoYo_Touched = YoYo_Touched + 1 ;

        //* Parabolic Stop *
                if Market_Position[1] <> -1 or
                    New_Entry then
                        begin
                            Parabolic_Stop = Chandelier_Stop ;
//                                roundInst( AvgEntryPrice + ( aChandelier_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[1] then
                                    Parabolic_Stop = High[1] ;
                            {end ;}    // only once per bar
                        end ;        // short parabolic stop
                end ;         // short market position 
                
//***** Exits *****
            if Market_Position = 1 then
                begin
                      if Chandelier_Touched >= Times_Touched then
                        Sell ( "LX_Cdlr" ) currentshares shares next bar at Chandelier_Stop STOP ;
                    if YoYo_Touched >= Times_Touched then
                         Sell( "LX_YoYo" ) currentshares shares next bar at YoYo_Stop STOP ;
                    Sell ( "LX_Pblc" ) currentshares shares next bar at Parabolic_Stop STOP ;
                end        // long stops
            else begin
                      if Chandelier_Touched >= Times_Touched then
                        BuyToCover ( "SXCdlr" ) currentshares shares next bar at Chandelier_Stop STOP ;
                    if YoYo_Touched >= Times_Touched then                    
                        BuyToCover ( "SXYoYo" ) currentshares shares next bar at YoYo_Stop STOP ;
                    BuyToCover ( "SXPblc" ) currentshares shares next bar at Parabolic_Stop STOP ;
                end ;        // short stops
        end ;         // set stops -- MarketPostion <> 0

//***** 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,
                "PT_On = ",                                 PT_On,                         NewLine,
                "AvgRange Length = ",                         aAvgRange_Length:0:0,         NewLine,
                "AvgRange = ",                                 Average_Range:0:2,             NewLine,
                "Chandelier AvgRange Multip lier = ",         aChandelier_AvgRange:0:2,     NewLine,
                "YoYo AvgRange Multiplier =",                 aYoYo_AvgRange:0:2,         NewLine,
                "Times Touched = ",                            Times_Touched: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 = ",         PT_Range_Mult: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
                ) ;

// ***** Print 2 Log 4 Debug *****
 Variables: IntrabarPersist    Count( 0 );

    if BarStatus(1) = 2 then 
        Count = 0 ;
    
    if Not_Optimizing and
        LBOC and
        ( Chandelier_Touched <> 0 or 
        YoYo_Touched <> 0 ) and
        Market_Position <> 0 then
            begin
                Count = Count + 1 ;
                Print(
                    Count:0:0, "  ",
                    "Bar # ", CurrentBar:0:0, "  ",
                    TimeToString( ComputerDateTime ), 
                    "  Setting = ",    Times_Touched:0:0, 
                    "  Cdlr = ", Chandelier_Touched:0:0,
                    "  YoYo = ", YoYo_Touched:0:0, "  ",
                    Close
                    ) ;
            end ;
I found this on the TS forum, hope it's ok to repost here?

Started this thread Reply With Quote
The following 5 users say Thank You to kiasom for this post:

Can you help answer these questions
from other members on NexusFi?
Trader Dale [email protected] or Scammer Dale
Trading Reviews and Vendors
Request for MACD with option to use different MAs for fa …
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ISO Equity Curve Indicator
NinjaTrader
Volume profile TradeStation
EasyLanguage Programming
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
GFIs1 1 DAX trade per day journal
28 thanks
Supertradersams Thread Journal on NQ/MNQ
26 thanks
Tao te Trade: way of the WLD
24 thanks
Just another trading journal: PA, Wyckoff & Trends
12 thanks
1% Risk Journal
11 thanks

(login for full post details)
  #3 (permalink)
 kiasom 
Stockholm
 
Experience: Intermediate
Platform: MC
Trading: fx
Posts: 16 since Apr 2010
Thanks Given: 139
Thanks Received: 23


Here's the indicator, that plots what the signal reacts on:

 
Code
// 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                        *
All of the stops are applied at once --
the closest one to the price (tightest) becomes the dominant/active one.    
if you use Range or Renko Bars - The Chandelier Stop turns into a conventional Trailing Stop.
The indicator will not show the stops unless the chart is in a trade position.
The indicator has the option of displaying all of the stop plots or just the plot closest
to the price - using the True/False "Show_All_Stops" switch in the indicator format.
CurrentBar=2 is used to make sure the strategy is fully loaded before the GV is retrieved.
}
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 = roundInst( Profit_AvgRange * PT_Average_Range) ;
            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 = roundInst(Trade_High-(Chandelier_AvgRange*Average_Range*Profit_Switch_Fac)) ; // tighten stop
                            end        // tighten Chandelier stop when profit point exceeded
                    else Chandelier_Stop = roundInst(Trade_High -(Chandelier_AvgRange*Average_Range)) ; // 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 = roundInst( YoYo_Price - YoYo_Amount) ;

        //* Parabolic Stop *
                    if Market_Position[1] <> 1 or
                        New_Entry then
                            begin
                                Parabolic_Stop = Chandelier_Stop ;        // initial setting
//                                    roundInst( 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

    //*** 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 = roundInst(Trade_Low+(Chandelier_AvgRange*Average_Range*Profit_Switch_Fac)) ;// tighten stop
                        end        // tighten Chandelier stop when profit point exceeded
                else Chandelier_Stop = roundInst(Trade_Low+(Chandelier_AvgRange * Average_Range )) ;            // 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 = roundInst(YoYo_Price+ YoYo_Amount) ;

        //* Parabolic Stop *
                if Market_Position[1] <> -1 OR
                    New_Entry then
                        begin
                            Parabolic_Stop = Chandelier_Stop ;
//                                    roundInst( 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

Started this thread Reply With Quote
The following 2 users say Thank You to kiasom for this post:
(login for full post details)
  #4 (permalink)
 kiasom 
Stockholm
 
Experience: Intermediate
Platform: MC
Trading: fx
Posts: 16 since Apr 2010
Thanks Given: 139
Thanks Received: 23

Here's one more variant, with just the Chandelier TS.
This is more professionally coded, with the signal drawing the plots as well (no need for a separate indicator).

 
Code
IF BARTYPE < 2 or bartype=5 THEN BEGIN //Intraday Data1 Only, or point bars

     
inputs: 
    CSFactor( 3 ), 
    CSLength( 20 ); 
 
variables: 
    MP( 0 ), 
    HH( 0 ), 
    LL( 0 ), 
    LeBeauStopHH( 0 ), 
    LeBeauStopLL( 0 ), 
    LBSHlast( 0 ), 
    LBSLlast( 0 ), 
    TL_LBCS( -1 ) ; 
 
{ Demo/Test Entry }  
if CurrentBar = 200 then Buy next bar at market ;  
//if CurrentBar = 200 then SellShort next bar at market ;  
 
MP = MarketPosition ; 
 
if MP[1] = 1 then 
    begin 
    { Display LeBeau Stop HH } 
    TL_LBCS = TL_New( D[1], T[1], LBSHlast, D, T, LeBeauStopHH ) ; 
    TL_SetColor( TL_LBCS, Magenta ) ; 
    TL_SetStyle( TL_LBCS, 3 ) ; 
    end 
 
else if MP[1] = -1 then 
    begin 
    { Display LeBeau Stop LL } 
    TL_LBCS = TL_New( D[1], T[1], LBSLlast, D, T, LeBeauStopLL ) ; //draws from bar to bar
    TL_SetColor( TL_LBCS, Yellow ) ; 
    TL_SetStyle( TL_LBCS, 3 ) ; 
    end ; 
 
if MP = 1 then 
    begin 
 
    { Demo LeBeau Chandelier Long Stop } 
    if MP[1] = 1 then 
        HH = MaxList( HH, High ) 
    else 
        HH = High ; 
    LBSHlast = LeBeauStopHH ; 
    LeBeauStopHH = HH - CSFactor * XAverage( Range, CSLength ) ; 
    if MP[1] <> 1 then LBSHlast = LeBeauStopHH ; 
 
    { LeBeau Stops - Reverse Long to Short } 
    SellShort ( "SX" ) next bar at LeBeauStopHH stop ; 
 
    end 
 
else if MP = -1 then 
    begin 
 
    { Demo LeBeau Chandelier Short Stop } 
    if MP[1] = -1 then 
        LL = MinList( LL, Low ) 
    else 
        LL = Low ; 
    LBSLlast = LeBeauStopLL ; 
    LeBeauStopLL = LL + CSFactor * XAverage( Range, CSLength ) ; 
    if MP[1] <> -1 then LBSLlast = LeBeauStopLL ; 
 
    { LeBeau Stops - Reverse Short to Long } 
    Buy ( "LX" ) next bar at LeBeauStopLL stop ; 
     
    end ; 
 
END ;

Started this thread Reply With Quote
The following 2 users say Thank You to kiasom for this post:
(login for full post details)
  #5 (permalink)
 Sam7768 
Dallas, Texas, USA
 
Experience: Beginner
Platform: NT 6.5 & Tradestation
Trading: Equities & ES
Posts: 47 since Sep 2010
Thanks Given: 21
Thanks Received: 9

Hello Kaisom,

Thanks much for the indicator & Strategy. when I tried to compile the codes, both the indicator & strategy are getting stuck at

"GVSetNamedDouble" as unknown identifier.

What could be the issue? Pl advice.

Reply With Quote





Last Updated on May 13, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts