automated trading - code1


/ Published in: C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. [LegacyColorValue = true];
  2. [IntrabarOrderGeneration = false];
  3.  
  4. // Range expansion template for TradeStation with RSI conditions
  5.  
  6.  
  7. Variables:
  8. maxexposure(1000),
  9. type(2),
  10. sharetotrade(1),
  11. Length(55),
  12. pct(2),
  13. FastAvg(0),
  14. MedAvg(0),
  15. SlowAvg(0),
  16. totalup(0),
  17. totaldown(0),
  18. totalflat(0),
  19. upi(0),
  20. downi(0),
  21. flati(0),
  22. upd(0),
  23. downd(0),
  24. flatd(0),
  25. upw(0),
  26. downw(0),
  27. flatw(0),
  28. Tim1(0),
  29. Tim2 (0) ,
  30. ShareOrPosition(0) ,
  31. ProfitTargetAmt (0),
  32. StopLossAmt(0) ,
  33. BreakevenFloorAmt(0) ,
  34. DollarTrailingAmt(0) ,
  35. PctTrailingFloorAmt (0) ,
  36. PctTrailingPct(0) ,
  37. ExitOnClose(false) ,nshares(0),
  38. peak(0),valley(0),trend(0),SIMController(1);
  39.  
  40.  
  41.  
  42. Tim1 =1230 ;
  43. Tim2 =1230 ;
  44. ShareOrPosition= 1 ;
  45. ProfitTargetAmt =12;
  46.  
  47. BreakevenFloorAmt= 0 ;
  48. DollarTrailingAmt =0 ;
  49. PctTrailingFloorAmt =10 ;
  50. PctTrailingPct= 20 ;
  51. ExitOnClose= true ;
  52.  
  53.  
  54. if type=1 then nshares=maxexposure/average(close,10);
  55. if type=2 then nshares=sharetotrade;
  56.  
  57.  
  58. FastAvg = AverageFC( c, 5 ) ;
  59. MedAvg = AverageFC( c, 15 ) ;
  60. SlowAvg = AverageFC( c, 30 ) ;
  61.  
  62.  
  63.  
  64.  
  65. Condition1=Range<Average(Range, Length*pct);
  66.  
  67. If Time >=Tim1 and Time <=Tim2 then begin;
  68. IF MarketPosition<>1 and
  69. TradesToday(date)<1
  70. and Condition1 then
  71. Buy Nshares shares Next Bar at Highest(High,Length)+1 point Stop;
  72. //1 point == 1 tick
  73.  
  74.  
  75. IF MarketPosition<>-1 and
  76. TradesToday(date)<1
  77. and Condition1 then
  78. Sell Short Nshares shares Next Bar at Lowest(Low,Length)-1 point Stop;
  79.  
  80.  
  81. end;
  82.  
  83.  
  84. if ShareOrPosition = 1 then
  85. SetStopShare
  86. else
  87. SetStopPosition ;
  88.  
  89. if ProfitTargetAmt > 0 then
  90. SetProfitTarget( ProfitTargetAmt ) ;
  91.  
  92. if (Rsi(c,10)< 70 and Rsi(c,10)> 30)
  93. then begin
  94. SetStopLoss(250);
  95. end
  96. else if (Rsi(c,10)> 70 )or (Rsi(c,10)< 30 and Rsi(c,10)< Rsi(c,10)[1])
  97. and barssinceentry> 1 then SetStopLoss(1600) ;
  98.  
  99.  
  100. if BreakevenFloorAmt > 0 then
  101. SetBreakeven( BreakevenFloorAmt ) ;
  102. if DollarTrailingAmt > 0 then
  103. SetDollarTrailing( DollarTrailingAmt ) ;
  104. if PctTrailingFloorAmt > 0 and PctTrailingPct > 0 then
  105. SetPercentTrailing( PctTrailingFloorAmt, PctTrailingPct ) ;
  106. if ExitOnClose = true then
  107. SetExitOnClose ;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.