automated trading - code2


/ 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.  
  5. // Tradestation Range expansion and other conditions V2
  6.  
  7. Variables:
  8. maxexposure(1000),
  9. type(2),
  10. sharetotrade(1),
  11. Length(55),
  12. pct(12),
  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);
  39.  
  40.  
  41. Tim1 =1230 ;
  42. Tim2 =1240 ;
  43. ShareOrPosition= 1 ;
  44. ProfitTargetAmt =12;
  45.  
  46. BreakevenFloorAmt= 0 ;
  47. DollarTrailingAmt =0 ;
  48. PctTrailingFloorAmt =1;
  49. PctTrailingPct= 5 ;
  50. ExitOnClose= true ;
  51.  
  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. Condition1=Range<Average(Range, Length*pct);
  64.  
  65. If Time >=Tim1 and Time <=Tim2 then begin;
  66. IF MarketPosition<>1 and
  67. TradesToday(date)<1
  68. and Condition1 {and other conditions} then
  69. Buy Nshares shares Next Bar at Highest(High,Length)+1 point Stop;
  70.  
  71.  
  72. IF MarketPosition<>-1 and
  73. TradesToday(date)<1
  74. and Condition1 then
  75. Sell Short Nshares shares Next Bar at Lowest(Low,Length)-1 point Stop;
  76.  
  77.  
  78. end;
  79.  
  80.  
  81.  
  82. if ShareOrPosition = 1 then
  83. SetStopShare
  84. else
  85. SetStopPosition ;
  86.  
  87. if ProfitTargetAmt > 0 then
  88. SetProfitTarget( ProfitTargetAmt ) ;
  89.  
  90. if (Rsi(c,10)< 70 and Rsi(c,10)> 30)
  91. then begin
  92. SetStopLoss(250);
  93. end
  94. else if (Rsi(c,10)> 70 )or (Rsi(c,10)< 30 and Rsi(c,10)< Rsi(c,10)[1])
  95. and barssinceentry> 1 then SetStopLoss( 600) ;
  96.  
  97.  
  98. if BreakevenFloorAmt > 0 then
  99. SetBreakeven( BreakevenFloorAmt ) ;
  100. if DollarTrailingAmt > 0 then
  101. SetDollarTrailing( DollarTrailingAmt ) ;
  102. if PctTrailingFloorAmt > 0 and PctTrailingPct > 0 then
  103. SetPercentTrailing( PctTrailingFloorAmt, PctTrailingPct ) ;
  104. if ExitOnClose = true then
  105. SetExitOnClose ;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.