Strategy templates

Moderator: admin

Strategy templates

Postby Apprentice » Mon Nov 22, 2010 8:06 am

Simple Strategy Template.lua
(7.62 KiB) Downloaded 1156 times


MCP Strategy Template.lua
Multi Instrument Strategy Template
(13.33 KiB) Downloaded 2448 times



End of Turn_Live Execution Strategy Template.lua
(17.68 KiB) Downloaded 3488 times

End of Turn_Live Execution Strategy Template Old.lua
(30.55 KiB) Downloaded 1227 times


Entry Order Strategy.lua
(11.89 KiB) Downloaded 2588 times


Tick Based Strategys.
Tick Based Strategy.lua
(18.82 KiB) Downloaded 2366 times


Simple Strategy Templetes
Strategy Template.lua
(18.79 KiB) Downloaded 3267 times


Highly adaptable Strategy Templetes


Simple Signal Template
Simple Signal Template.lua
(3.34 KiB) Downloaded 2620 times


MTF Strategy
MTF Strategy Template.lua
(17.93 KiB) Downloaded 2942 times


Time Close Strategy.lua
This strategy closes all positions, Open and/or Entry , for the chosen currency pair, at entered time
(15.42 KiB) Downloaded 2359 times

Delete orders.lua
(2.9 KiB) Downloaded 2303 times


MTF MCP Signal
MTF MCP Signal Template.lua
(10.23 KiB) Downloaded 2228 times


create_orders_OM_test.lua
(14.59 KiB) Downloaded 2129 times


Close ALL Strategy.lua
(9.62 KiB) Downloaded 2068 times

Strategy will automatically close ALL open positions and cancel all pending orders when the target P/L in PIPs is reached.
Two Instrument Strategy Template.lua
(28 KiB) Downloaded 1930 times

Close All Positions Afterwards.lua
(18.98 KiB) Downloaded 1879 times

Close Selected Positions Afterwards.lua
(18.67 KiB) Downloaded 1806 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Strategy Template

Postby maximekaribi » Sun Jan 15, 2012 1:59 pm

hello
how i can add my strategie into this template?
my strategie dont have ¨^allow strategie to trade¨^how i can bactest it?
thanks a lot
maxime
maximekaribi
 
Posts: 3
Joined: Mon Sep 19, 2011 2:43 am

Re: Strategy Template

Postby sunshine » Mon Jan 16, 2012 4:23 am

The template is intended for creating your own strategy. You should modify it for your needs. The template includes common code which can be used in all strategies. Please search for "AllowTrade" in the template to see how this parameter is implemented.
sunshine
 


Re: Strategy templates

Postby Daveatt » Wed Mar 20, 2019 4:39 am

Hi Apprentice

Hope all is well

Do you confirm the Two Instrument Strategy Template.lua is working with index (GER30, US30, ..). Seems to work for forex but not for index
I'm very interested as I'm trying to add another source of index data into my own strategy so I'd like to replicate an already working solution

Thanks a lot
David
Daveatt
 
Posts: 62
Joined: Mon Jan 30, 2017 10:00 am

Re: Strategy templates

Postby Apprentice » Thu Mar 21, 2019 4:00 pm

It should work with any instrument.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Strategy templates

Postby Apprentice » Sun Feb 02, 2020 7:38 am

strategy_simple.lua
(13.28 KiB) Downloaded 707 times

strategy_medium.lua
(21.51 KiB) Downloaded 424 times


strategy_simple_adaptable.lua
(20.15 KiB) Downloaded 556 times

Example of the simplest possible strategy.

Code: Select all
Features:

Timeframe to trade
Live/End of bar execution
Stop/limit
Close on opposite
Alerts: message, sound, email
Parameters
Price type
What price stream to use: bid or ask. This stream will be used as a source for the indicators.

Timeframe
What timeframe to use for the indicator source.

Allow strategy to trade
You can enable/disable trading using this parameter. You will get alerts only when trading is disabled.

Execution type
Strategy can check conditions on every tick (Live) or when the bar has closed. Live method will give you a faster reaction time but gives more false signals.

Account to trade on
Your account

Trade amount in lots
Defines the size of the opened positions. Defined in lots. The size of the lot depends on your account and symbol you trade. So, "1" can open "1 000 USD" position or "100 000 USD" positions depending on the type of your account.

Set stop
Whether to set the stop for the opened trades. Used with "Stop, pips" parameter

Stop, pips
Distance to the stop order in pips.

Trailing stop order
Whether to use trailing for the stop order. Used with "Trailing in pips" parameter

Trailing in pips
Trailing stop in pips. Use "1" for dynamic trailing or >= 10 for the fixed trailing step.

Setp limit
Whether to set the limit for the opened trades. Used with "Limit, pips" parameter.

Limit, pips
Distance to the limit order in pips.

Close on opposite
When set to true the strategy will close opposite trades when the signal detected.
For example: if the strategy detects "long/buy" signal and then it will look for short trades and close them.

Custom ID
Custom identification for the trades. Used to work with a set of trades only.
For example: if you set custom ID, the signal is detected and the Close on opposite feature is turned on then the strategy will ignore trades with Custom ID other that specified. This way you can run several strategies on the same instrument along each other and they to dot touch trades from another strategies (if every strategy will use it's own unique custom ID).

Alerts parameters
Convert the sate to
This option allows you to select timezone to use in the messages. The strategy will format dates in the messages in that selected timezone.

Show Alert
The strategy will show you a dialog with the alert when this option enabled.

Play sound
The strategy will play a sound on alert. Used with "Sound file" and "Recurrent sound" parameters.

Sound file
Sound file to play when the alert detected.

Recurrent sound
The strategy will play the sound in a loop when this option enabled.

Send email
The strategy will send you an email when this option enabled. Used with "Email" parameter.

Email
Email to send the alert to.


strategy_advanced.lua
(30.49 KiB) Downloaded 721 times

strategy_advanced_plus.lua
(34.03 KiB) Downloaded 712 times


Code: Select all
You will need to copy-paste code for \strategies\custom\snippets\*.lua file at the end of the file. You can find these snippets on github: https://github.com/sibvic/fxts2-templates

Strategy template which includes all supported features so far. It's the most complex template.

Features set:

Multi-position entry (plus only)
Signal reversal
Heikin-Ashi as a source (plus only)
Entry/exit timeframes
Close on opposite
Position cap
Amount types: lots, % of equity, Risk % of equity
Stop: no, pips, high/low, ATR (plus only)
Close position on daily profit (plus only)
Trading time
Mandatory closing
Alerts (including Telegram and Discord) (plus only)
DDE alerts export (plus only)
Order execution on other platforms (plus only)
Description of template parameters

You can setup the template by changing variables in "CUSTOMIZATION SECTION" and "USER DEFINED SECTION".

STRATEGY_NAME
Strategy name.

STRATEGY_VERSION
Strategy version.

PositionsCount
Number of positions to open with individual set of stop/limit parameters.

IncludeTradingTime
Trading time parameters. You can turn it off if you never use it.

UseOwnPositionsOnly
Whether to take into account positions created only by this strategy or take into account positions created by other strategies and by the user as well. If set to false the strategy may close positions created by the user and other strategies.

DISABLE_ATR_STOP_LIMIT
Disables ATR stop and limit.

DISABLE_LIMIT_TRAILING
Disabled limit trailing.

USE_CUSTOM_TIMEFRAMES
Enables custom timeframes like "m2".

ENFORCE_entry_execution_type, ENFORCE_exit_execution_type
Allows to set entry/exit execution type and hide the related parameters.

EXIT_TIMEFRAME_IN_PARAMS
Allows to hide separamet exit timeframe. When set to true the exit rules will use the same timeframe as entry rules.

DISABLE_EXIT
Allows to disable exit logic in the strategy.

DISABLE_HA_SOURCE
Allows to disable HA source in the strategy.

DDEAlertsSupport
Support of alerts export using DDE (like Excel). Set it to true/false

HISTORY_PRELOAD_BARS
History preload count

RequestBidAsk
Whether to request both prices: bid and ask

ENFORCE_POSITION_CAP
When set to true the parameters will close hidden and the features will be enabled and limited to 1 position only.

CustomTimeframeDefined
Set it to true when you define your own timeframe and is_bid parameters.

function CreateParameters()
Add your parameters in this function

function CreateStopParameters(params, id)
Creates custom stop parameters. You can delete this function if you don't need custom stop logic. You can return false to use default stop logic and parameters.

function CreateLimitParameters(params, id)
Creates custom limit parameters. You can delete this function if you don't need custom limit logic. You can return false to use default limit logic and parameters.

function CreateIndicators(source)
Create your indicators in this function.

function UpdateIndicators()
Update your indicators in this function.

function CreateCustomActions()
In this method you can add trading actions. There is two kind of actions: user-customizable and fixed ones. Add your actions to EntryActions or ExitActions. EntryActions will create entry orders and ExitActions will create exit orders.

User-customizable action
User-customizable action is an action which can be selected in the parameters. You can add it by calling AddAction in the CreateParameters function and CreateAction in this function.

Usage:

local action1, isEntry1 = CreateAction(1);
action1.Data = nil;
action1.IsPass = function (source, period, periodFromLast, data)
    return false; -- TODO: implement
end
if isEntry1 then
    EntryActions[#EntryActions + 1] = action1;
else
    ExitActions[#ExitActions + 1] = action1;
end
Fixed actions
Usage:

local exitLongAction = {};
exitLongAction.ActOnSwitch = false;
exitLongAction.IsPass = function (source, period, periodFromLast, data)
    return false; -- TODO: implement
end

local exitShortAction = {};
exitShortAction.ActOnSwitch = false;
exitShortAction.IsPass = function (source, period, periodFromLast, data)
    return false; -- TODO: implement
end

local enterLongAction = {};
enterLongAction.ActOnSwitch = true;
enterLongAction.GetLog = function (source, period, periodFromLast, data)
    return "";
end
enterLongAction.IsPass = function (source, period, periodFromLast, data)
    return false; -- TODO: implement
end

local enterShortAction = {};
enterShortAction.ActOnSwitch = true;
enterShortAction.GetLog = function (source, period, periodFromLast, data)
    return "";
end
enterShortAction.IsPass = function (source, period, periodFromLast, data)
    return false; -- TODO: implement
end

if instance.parameters.Direction == "direct" then
    exitLongAction.Execute = CloseLong;
    exitShortAction.Execute = CloseShort;
    enterLongAction.Execute = GoLong;
    enterShortAction.Execute = GoShort;
    enterLongAction.ExecuteData = CreateBuyPositions();
    enterShortAction.ExecuteData = CreateSellPositions();
else
    exitLongAction.Execute = CloseShort;
    exitShortAction.Execute = CloseLong;
    enterLongAction.Execute = GoShort;
    enterShortAction.Execute = GoLong;
    enterLongAction.ExecuteData = CreateSellPositions();
    enterShortAction.ExecuteData = CreateBuyPositions();
end
ExitActions[#ExitActions + 1] = exitLongAction;
ExitActions[#ExitActions + 1] = exitShortAction;
EntryActions[#EntryActions + 1] = enterLongAction;
EntryActions[#EntryActions + 1] = enterShortAction;
Trading section
Type of Signal / Trade
"Direct" option uses an ordinary logic. "Reverse" option will use long logic to open short trades and vice versa.

Price Type
What price to use for the indicator calculations: bid or ask.

Use HA as source
When set to true the HA bars will be used for indicators calculation instead of ordinary candles.

Entry Time frame/Exit Time frame
Timeframes used for the calculation of entry/exit indicators.

Entry Execution Type/Exit Execution Type
Whether to check entry/exit conditions when the bar closes or at every tick.

Allow strategy to trade
When set to false the strategy will show alerts only and will not trade.

Account to trade on
Account.

Allow side
Allows trades in both/long only/short only directions.

Custom ID
Custom identification for the trades. Used to work with a set of trades only.
For example: if you set custom ID, the signal is detected and the Close on the opposite feature is turned on then the strategy will ignore trades with Custom ID other than specified. This way you can run several strategies on the same instrument along with each other and they to dot touch trades from other strategies (if every strategy will use its own unique custom ID).

Close on Opposite
When set to true the strategy will close opposite trades when the signal detected.
For example: if the strategy detects "long/buy" signal and then it will look for short trades and close them.

Position cap, Max # of open/buy/sell positions
It allows limiting the number of trades at the same time. You can limit the number of trades by side and/or by the total number.
For example, you can limit the number of trade to 5 but not more than 3 in each direction. This way you can get 3-2 or 2-3 long-short trades but not 4-1.

Position
Trade amount, Amount type
These two parameters difens size of the position. There are three types:

In Lots. Defines the size of the opened positions. Defined in lots. The size of the lot depends on your account and symbol you trade. So, "1" can open "1 000 USD" position or "100 000 USD" positions depending on the type of your account.
% of equity. Calculates the size of the position in order to use % of your equity.
Risk % of equity. Calculates the size of the position in order to lose % of your equity if the stop gets hit. This option requires the stop to be specified.
Stop parameters
Stop order, Stop value, ATR Stop Multiplicator
Defines the type of stop

No stop. No stop order will be created.
In pips. The stop order will be created in "Stop value" pips from the opened price.
ATR. ATR value will be calculated using "Stop value" as a period and "ATR Stop Multiplicator" as a multiplicator. The calculated value will be used as pips value for the stop.
High/low. The highest/lowest rate will be found in "Stop value" bars back and used as a stop.
Trailing stop order
Whether to use trailing for the stop order. Used with "Trailing in pips" parameter

Trailing in pips
Trailing stop in pips. Use "1" for dynamic trailing or >= 10 for the fixed trailing step.

Close positions on daily profit, Day profit limit, $
Allows closing all positions when the profit for that day reaches the specified amount in account currency.

Limit parameters
Limit order, Limit value, ATR Limit Multiplier
Defines the type of limit

No limit. No limit order will be created.
In pips. The limit order will be created in "Limit value" pips from the opened price.
ATR. ATR value will be calculated using "Limit value" as a period and "ATR Limit Multiplicator" as a multiplicator. The calculated value will be used as pips value for the Limit.
Multiplicator of stop. Uses "Limit value" as a multiplicator of stop distance to calculate the limit distance. "Limit value" = 2 will set the limit 2 times as far as the stop.
High/low. The highest/lowest rate will be found in "Limit value" bars back and used as a limit.
Trailing limit, Trailing limit trigger in pips, Trailing limit step in pips
Defines trailing for the limit

Off. No trailing will be performed.
Favorable. The trailing will be started after "Trailing limit trigger in pips" in profit. This option will move the limit when the price goes in a favorable direction. The limit will be hit in case of fast movement only.
Unfavorable. The trailing will be started after "Trailing limit trigger in pips" in profit. This option will move the limit in the direction of the loss when the prices go in an unfavorable direction.
Breakeven parameters
Use breakeven
Enables/disable the breakeven feature.

Breakeven activation value, in pips
The level of profit when the breakeven action will be executed.

Breakeven to, in pips
The level where the stop should be moved on breakeven activation.

Trailing after breakeven
Breakeven may set the trailing on activation. This allows you to create a trade without the stop trailing but start trailing when the stop will be moved on the breakeven level. Or you can leave it unchanged.

Partial close on breakeven, Partial close amount %
You can partially close the position when the breakeven will be activated.

Time parameters
Convert the date to
Defines the timezone of the dates/times.

Start/Stop time for trading
Defines the time range when the trading allowed.

Use mandatory closing, Mandatory closing time, Valid interval for operation in seconds
Allows closing of all trades at the specified time. The strategy will attempt to close these positions after the specified time but not longer that "Valid internal". This option uses a timer to check, but in case of connectivity issues, it can jump over the specified time without execution. That's why we need the "Valid interval" parameter.

Alert parameters
Convert the date to
This option allows you to select timezone to use in the messages. The strategy will format dates in the messages in that selected timezone.

Show Alert
The strategy will show you a dialog with the alert when this option enabled.

Play sound
The strategy will play a sound on alert. Used with "Sound file" and "Recurrent sound" parameters.

Sound file
Sound file to play when the alert detected.

Recurrent sound
The strategy will play the sound in a loop when this option enabled.

Send email
The strategy will send you an email when this option enabled. Used with "Email" parameter.

Email
Email to send the alert to.

Print into log
The strategy can print the alerts into the FXTS2 log window.

DDE Export, Service name, DDE Topic
Allows exporting alerts using DDE. This way you can get alerts into your Excel file.

Telegram/Discord/Other platforms parameters
Send advanced alert, advanced alert key
Allows sending alerts into the Telegram, Discord and other platforms. More Information

Trade coping
Send command to another platform, Platform key
Allows sending order execution commands to other platforms. More Information

Add log info to signals, Log file (csv)
Allows debugging of the strategy. When enabled all actions of the strategy will be logged into the CSV file.


strategy_simple_MTF_MI.lua
(16.07 KiB) Downloaded 665 times


strategy_simple_OCO.lua
(16.7 KiB) Downloaded 487 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Indicator Development

Who is online

Users browsing this forum: Bing [Bot] and 6 guests