Conversion of Mean Reversion Strats with Adaptive Buy order from Amibroker

Forums ProRealTime English forum ProBuilder support Conversion of Mean Reversion Strats with Adaptive Buy order from Amibroker

Viewing 1 post (of 1 total)
  • #174399

    Hi,

    I came across this interesting mean reversion strategy with adaptive buy order, so basically if a new high within a specified lookback is made, the algo will put a buy limit order based on lowest of  that candle – 2*ATR,  and the order limit is only good for a specified number of period only.

    More info in: https://www.youtube.com/watch?v=rKGXIopVeQ0

     

    The Amibroker code below.  Will appreciate if anyone can help to convert to codes for pro order in PRT.  Thank you in advance.

     

    /// Systematic market structure trading strategy 

    /// Long-only US equties swing trading version 

    /// As presented in 2 videos by Critical Trading on YouTube https://youtu.be/QKCDt2QnmeM & https://youtu.be/rKGXIopVeQ0 /// Source: Critical-Trading.com 

    /// This code may be freely shared & amended 

    /// Risk disclaimer – for Study purposes only, NOT an actual investment advice – refer to risk diclaimer at https://www.critical-trading.com/privacy-policy 

    /// Backtester settings 

     max_positions = 10;  

     margin_used = 50; /// 50 = 50% margin (standard margin when trading US stocks) OR 100 = no margin   SetOption(“InitialEquity”,10000);  

     SetOption(“MaxOpenPositions”,max_positions);  

     SetPositionSize(IIf(margin_used==50,200/max_positions,100/max_positions),spsPercentOfEquity);  

     SetOption(“ActivateStopsImmediately”,True); 

     SetOption(“accountmargin”,margin_used);  

     SetOption(“AllowPositionShrinking”, True);  

     SetOption(“AllowSameBarExit”, True);  

     SetOption(“FuturesMode”, False);  

     SetOption(“UsePrevBarEquityForPosSizing”,True);  

     SetTradeDelays( 1, 0, 0, 0);  

     SetBacktestMode( backtestRegular);  

    //// VIX  lter  

     SetForeign(“^VIX”); /// need to have VIX data & ensure the ticker here is correct 

     VIX lter = PercentRank(C,100) <= 85;  

     RestorePriceArrays(); 

    //// Variables – highest high  

     days = (21*3);  

     ndayhigh = HHV(H,days); 

     H_breakout = H > Ref(ndayhigh,-1); 

     H_breakout_count = BarsSince(H_breakout) < 10; 

    //// Variables – ATR 

     days_ATR = 20; 

     ATRvar = ATR(days_ATR)*2; 

    //// Adaptive buy level loop 

     Limit_buy = Null; 

     for( i = 1; i < BarCount; i++ ) 

     { 

     if( H_breakout[i] )  

     {  

     Limit_buy[i] = Low[ i ] – ATRvar[i]; 

     } 

     if( NOT H_breakout[i] AND H_breakout_count [i] ) 

     { 

     Limit_buy[ i ] = Limit_buy[i-1]; 

     }  

     if( L[i] < Limit_buy[ i – 1 ]) 

     { 

     Limit_buy[ i ] = Null; 

     } 

     } 

    //// Buy rule & buy price 

     Buy = H_breakout_count AND L < Ref(Limit_buy,-1) AND C < O AND VIX lter; 

     BuyPrice = Open; 

    /// Variable stop-loss adjusted for market’s volatility 

     SLatentry = ValueWhen(Buy,Ref(ATRvar,-1)); 

    //// Sell rule and price 

     Sell = C > Ref(HHV(C,2),-1); /// basic exit rule used here as presented in the video 

     SellPrice = close; 

    //// (stocks only) Ranking system – used to rank when multiple signals generated, swing trading only 

     HV = StDev(ROC(C,1),252)*sqrt( 252 ); 

     PositionScore = 1 / Hv; 

    //// Stop-loss – based on ATR  

     ApplyStop(stopTypeLoss,stopModePoint,SLatentry,1);

Viewing 1 post (of 1 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login