Advertisement
Maurizio-Ciullo

Bot Utente QTA VIX-Mean-Reversion-RSI-BB-ATR-4H

Jun 13th, 2023
1,795
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Bot Utente QTA VIX-Mean-Reversion-RSI-BB-ATR-4H
  2.  
  3. Inputs:
  4.     BB_Length(40),
  5.     BB_NumDevsUp(2),
  6.     BB_NumDevsDn(-2),
  7.     RSI_Length(5),
  8.     RSI_Threshold(30),
  9.     RSI_ThresholdShort(70),
  10.     AtrMult_TP(4.5),
  11.     AtrMult_SL(6),
  12.     AtrMult_TP_Short(6),
  13.     AtrMult_SL_Short(1.5),
  14.     ATRLength(7),
  15.     AllowLong(true),
  16.     AllowShortSelling(False);  
  17.  
  18. variables:
  19.     var0( 0 ),
  20.     var1( 0 ),
  21.     var2( 0 ),
  22.     var3( 0 ),
  23.     RSI_Value(0),
  24.     con1(0),
  25.     ATR(0),
  26.     Limit_price(0),
  27.     Stop_price(0),
  28.     con2(0),
  29.     TP_Short(0),
  30.     SL_Short(0);
  31.    
  32. var0 = Average( Close, BB_Length ) ;
  33. var1 = StandardDev( Close, BB_Length, 1 ) ;
  34. var3 = var0 + BB_NumDevsUp * var1 ; // Upper Band
  35. var2 = var0 + BB_NumDevsDn * var1 ; // Lower Band
  36. Value1 = BarsSinceEntry(0);
  37.  
  38. //---------------------------------------------------------------------------------------------------------------------------------------------------------------------
  39.  
  40. RSI_Value = RSI( Close, RSI_Length ) ;
  41. ATR = AvgTrueRange( ATRLength ) ;
  42.  
  43. if AllowLong then begin
  44.     if close crosses below var2 and RSI_Value < RSI_Threshold  then  
  45.         con1 = 1 ;
  46.  
  47.  
  48. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
  49.  
  50.     if con1 = 1 and Marketposition= 0 then begin
  51.         Buy next bar at market;
  52.     end;
  53.    
  54.    
  55.         Limit_price = High[Value1] + (AtrMult_TP * ATR);
  56.         Stop_price = Low[Value1] - (AtrMult_SL * ATR);
  57.         sell ("TP") next bar at limit_price limit;
  58.         sell ("SL") next bar at  stop_price stop;
  59.     con1 = 0;
  60. End;
  61.  
  62. //------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  63. //Short Side
  64.  
  65. if AllowShortSelling then begin
  66.     if Close crosses above var3 and RSI_Value >= RSI_ThresholdShort then begin
  67.         con2 = 1;
  68.     end;
  69.  
  70.     if con2 = 1 and Marketposition = 0 then begin
  71.         SellShort("Short") next bar at market;
  72.     end;
  73.    
  74.     TP_Short = Low[Value1] - (AtrMult_TP_Short * ATR);
  75.     SL_Short = High[Value1] + (AtrMult_SL_Short * ATR);
  76.     BuyToCover("SL Short") next bar at SL_Short stop;
  77.     BuyToCover("TP Short") next bar at TP_Short limit;
  78.      
  79.    
  80.     con2 = 0;
  81. end;
  82.  
  83.  
Advertisement
Comments
  • hemal9022
    1 year
    # text 0.12 KB | 0 0
    1. i got all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement