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
Forex Tester 追踪止损和SMA组合策略演示
最新推荐文章于 2025-07-09 12:42:19 发布
本文介绍了一个包含止损跟踪、简单移动平均线(SMA)等特性的交易策略实现案例。该策略支持在特定时间段内进行交易,并允许用户自定义止损跟踪触发条件及步长。

最低0.47元/天 解锁文章
913

被折叠的 条评论
为什么被折叠?



