Forex Tester 追踪止损和SMA组合策略演示

本文介绍了一个包含止损跟踪、简单移动平均线(SMA)等特性的交易策略实现案例。该策略支持在特定时间段内进行交易,并允许用户自定义止损跟踪触发条件及步长。
library TrailingPeriodsSMA;
//TrailingStop and SMA strategy with the ability to trade in trading periods (days, month, years) and daily times frames (hours, minutes).
//Trailing Stop and Trailing Step are optional.
//Trailing Step option "Yes" means that the user can declare a TrailingStep.
//Trailing Step option "No" means that the TrailingStep is automatically set at Bidgain (Bid minus PreviousBid).
//SMA option exist for buying an order and selling an existing order.

uses
  SysUtils,
  StrategyInterfaceUnit,
  DateUtils,
  Windows,
  Math;

var
  //Trading variables
  SymbolName: PAnsiChar = nil;
  lot: double = 1;
  StopLoss: integer = 3000;
  TakeProfit: integer = 10000;
  TrailingTrigger:integer = 5;
  TrailingStep:integer = 5;
  Timeframe: integer;
  OrderHandle: integer;

  //Variables for Time Periods
  BeginYear:Integer = 2002;
  BeginMonth:Integer = 1;
  BeginDay:Integer = 1;
  EndYear:Integer = 2015;
  EndMonth:Integer = 12;
  EndDay:Integer = 31;

  //Variables for daily time frames
  StartHour:Integer = 12;
  StartMinute:Integer = 0;
  StartSecond:Integer = 0;
  StartMillisecond:Integer = 0;
  StopHour:Integer = 16;
  StopMinute:Integer = 0;
  StopSecond:Integer = 0;
  StopMillisecond:Integer = 0;

  //TS procedure variables
  StopLossNew, StopLossCurrent, StopLossOriginal, StopLossTotal:Double;
  BidPrevious, BidGain:Double;
  TrailingValue:Double;
  TrailingBoolean, TStepBoolean:Boolean;

  //Variable for Popup Windows
  Mmagic:Integer;
  Ccomment:string;
  Hhour, Mminute, Ssecond, Mmillisecond:Integer;
  PreHhour, PreMminute, PreSsecond, PreMmillisecond:Integer;
  vBoolean:Boolean;
  tsBoolean:Boolean;

  //SMA variables
  BuySMABoolean:Boolean;
  SellSMABoolean:Boolean;
  period1:Integer = 5;
  period2:Integer = 10;

  //Misc variables
  j:Integer = 0;
  x:Integer = 0;

{-----Init strategy---------------------------------------------------------}
procedure InitStrategy; stdcall;
begin
  // set strategy name and description
  StrategyShortName('TrailingStop, Periods and SMAs');
  StrategyDescription('Trailing Stop and SMA Strategy for Trading within specified Periods');

  // register parameters
  AddSeparator('Trade settings');
  RegOption('Symbol', ot_Currency, SymbolName);
  ReplaceStr(SymbolName, 'USDJPY');
  RegOption('Lot', lot, 2, 0.01, 10);
  RegOption('Take Profit', TakeProfit, 1, 100000);
  RegOption('Stop Loss', StopLoss, 1, 100000);
  RegOption('Trailing Stop option (if No the below 3 are not used)',TrailingBoolean);
  Reg
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tmlige

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值