Advertisement
Maurizio-Ciullo

Indicatore-Base-Men-Reverting-Trend-Following-Unger

Aug 11th, 2022 (edited)
1,188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.                                     // Indicatore-Base-Men-Reverting-Trend-Following-Unger //
  3.                        
  4.  
  5. // Solitamente il test dovrebbe essere fatto su timeframe giornaliero per leggere la natura del sottostante.
  6. // Cambiando timeframe il test verrà eseguito sul timeframe scelto tranne per il Daily Mean Reverting Cross che rimane agganciato al timeframe daily.
  7. // Questo test potrebbe essere confrontato con 2 indicatori:
  8. // Da notare che su pinescript nell'intraday timeframes il Mean Reverting Cross ritorna valori diversi se confrontato con l'intraday session data di tradestation.
  9. // 1) Augmented Dickey–Fuller (ADF) mean reversion test
  10. // 2) Hurst Exponent - Detrended Fluctuation Analysis", "BA??HE (DFA)
  11.  
  12.  
  13. //inputs
  14. inputs:
  15.     on_off_trend_activate (true),
  16.     in_solo_long_trend (false),
  17.     in_solo_short_trend (false),
  18.  
  19.     on_off_break_intra_day_activate(false), // Da usare solo intraday highd(0);
  20.     in_solo_long_break_intra_day(false),    // Da usare solo intraday highd(0);
  21.     in_solo_short_break_intra_day(false),   // Da usare solo intraday highd(0);
  22.  
  23.     on_off_reverse_activate (false),
  24.     in_solo_long_reverse (false),
  25.     in_solo_short_reverse (false),
  26.    
  27.     on_off_reverse_cross_activate (false),
  28.     in_solo_long_reverse_cross (false),
  29.     in_solo_short_reverse_cross (false);
  30.  
  31.  
  32.        
  33.                                               // Inizio Test Daily Trend Following //
  34.  
  35. // Long e Short Trend
  36. if in_solo_long_trend = false and  in_solo_short_trend = false and on_off_trend_activate then begin
  37.     Buy ("En Long Trend") Next Bar high stop;
  38.     Sellshort ("En Short Trend") Next Bar low stop;
  39. end;
  40.  
  41.  
  42. // Solo Long Trend  
  43. if in_solo_long_trend = true and in_solo_short_trend = false and on_off_trend_activate then begin
  44.     Buy("Ent Solo Long Trend") Next Bar high stop;
  45.     Sell("Ex Solo Long Trend") Next Bar low stop;
  46. end;
  47.  
  48.  
  49. // Solo Short Trend  
  50. if in_solo_short_trend = true and in_solo_long_trend = false and on_off_trend_activate then begin
  51.     Sellshort("En Solo Short Trend") Next Bar low stop;
  52.     Buytocover("Ex Solo Short Trend")Next Bar high stop;
  53. end;
  54.  
  55.  
  56.                                                 // Fine Test Daily Trend Following //
  57.  
  58.  
  59.                                                 // Inizio Test Intraday Break Intra Day //
  60.                                                
  61. // Long e Short Break Intra Day
  62. if in_solo_long_break_intra_day = false and in_solo_short_break_intra_day = false and on_off_break_intra_day_activate = true then begin
  63.     Buy("En Long BreakIntraD") next bar at highd(0) stop;
  64.     Sellshort("En Short BreakIntraD") next bar at lowd(0) stop;
  65. end;
  66.  
  67.  
  68. // Solo Long Break Intra Day   
  69. if in_solo_long_break_intra_day = true and in_solo_short_break_intra_day = false and on_off_break_intra_day_activate = true then begin
  70.     Buy("ENSL BreakIntraD") next bar at highd(0) stop;
  71.     Sell("EXSL BreakIntraD") next bar at lowd(0) stop;
  72. end;   
  73.  
  74.  
  75. // Solo Short Break Intra Day  
  76. if in_solo_short_break_intra_day = true and in_solo_long_break_intra_day = false and on_off_break_intra_day_activate = true then begin
  77.     Sellshort("ENSS BreakIntraD") next bar at lowd(0) stop;
  78.     Buytocover("EXSS BreakIntraD") next bar at highd(0) stop;
  79. end;
  80.    
  81.                                                 // Fine Test Intraday Break Intra Day //
  82.  
  83.  
  84.                                                // Inizio Test Daily Mean Reverting //
  85.  
  86. // Long e Short Reverse
  87. if in_solo_long_reverse = false and  in_solo_short_reverse = false and on_off_reverse_activate then begin
  88.     Buy("En Long Rev") Next Bar low limit;
  89.     Sellshort("Ex Short Rev") Next Bar high limit;
  90. end;
  91.  
  92.  
  93. // Solo Long Reverse  
  94. if in_solo_long_reverse = true and in_solo_short_reverse = false and on_off_reverse_activate then begin
  95.     Buy("En Solo Long Rev") Next Bar low limit;
  96.     Sell("Ex Solo Long Rev") Next Bar high limit;
  97. end;
  98.  
  99.  
  100. // Solo Short Reverse
  101. if in_solo_short_reverse = true and in_solo_long_reverse = false and on_off_reverse_activate then begin
  102.     Sellshort("En Solo Short Rev") Next Bar high limit;
  103.     Buytocover("Ex Solo Short Rev") Next Bar low limit;
  104. end;
  105.    
  106.                                                 // Fine Test Daily Mean Reverting //
  107.                                                
  108.                                                
  109.                                                 // Inizio Test Daily Mean Reverting Cross //
  110.  
  111. // Long e Short Reverse Cross
  112. if in_solo_long_reverse_cross = false and in_solo_short_reverse_cross = false and on_off_reverse_cross_activate then begin
  113.     if Close Cross Over LowSession(1,1) then Buy ("En Long Rev Cr") Next bar at market;
  114.     if Close Cross Below HighSession(1,1) then Sellshort("En Short Rev Cr") Next bar at market;
  115. end;
  116.  
  117.  
  118. // Solo Long Reverse Cross
  119. if in_solo_long_reverse_cross = true and in_solo_short_reverse_cross = false and on_off_reverse_cross_activate then begin
  120.     if Close Cross Over LowSession(1,1) then Buy("En Solo Long Rev Cr") Next bar at market;
  121.     if Close Cross Below HighSession(1,1) then Sell("Ex Solo Long Rev Cr") Next Bar high stop;
  122. end;
  123.        
  124.  
  125. // Solo Short Reverse Cross
  126. if in_solo_short_reverse_cross = true and in_solo_long_reverse_cross = false and on_off_reverse_cross_activate then begin
  127.     if Close Cross Below HighSession(1,1) then Sellshort("En Solo Short Rev Cr") Next bar at market;
  128.     if Close Cross Over LowSession(1,1) then Buytocover("Ex Solo Short Rev Cr") Next bar low stop;
  129. end;
  130.    
  131.    
  132.                                                 // Fine Test Daily Mean Reverting Cross //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement