[FAQ] Autotrade / Backtest / Optimization
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
[FAQ] Autotrade / Backtest / Optimization
1) Autotrade / Backtest / Optimization FAQ
START HERE:
The Wiki is a very useful resource
Click this first>>> Category:Backtesting: https://www.multicharts.com/trading-sof ... acktesting
Click this next>>> Category:FAQ: https://www.multicharts.com/trading-sof ... tegory:FAQ
Relevant articles in Wiki: General/Overview
- Getting Started with AutoTrading
- How Scripts Work
-->How Signals are Calculated
- Order Execution Priority
- Auto Trading
- Understanding Automated Trade Execution
- Comparison of Synchronous and Asynchronous Mode
Relevant articles in Wiki: Fundamentals
- Backtesting vs Live Trading
- Understanding Backtesting
- Why is Data Playback strategy performance different from Backtesting results?
- Intra-bar Price Movement Assumptions
- MaxBarsBack
Relevant articles in Wiki: Intermediate level readings
- Precise Backtesting
- Understanding Precise Backtesting
- Using Precise Backtesting
- Bar Magnifier
- Intra-Bar Order Generation, Bar Magnifier on Non-Standard Chart Types
Relevant articles in Wiki: Additional readings
- How to make indicator and signal calculation results the same
- Trades vs Orders With PosTrade Keywords
- Trading from Multiple Charts on One Instrument
- Manual Trading and Automated Trading on the Same Instrument at a Time
- Realtime-History Matching
Relevant articles in Wiki: Portfolio
- Understanding Portfolio Backtesting
- Backtesting a Portfolio
- Portfolio Optimization
- Additional info on Portfolio: FAQ - Portfolio Trader / Portfolio Backtester
-------------------------------------------------------
Has this post been helpful to you?
START HERE:
The Wiki is a very useful resource
Click this first>>> Category:Backtesting: https://www.multicharts.com/trading-sof ... acktesting
Click this next>>> Category:FAQ: https://www.multicharts.com/trading-sof ... tegory:FAQ
Relevant articles in Wiki: General/Overview
- Getting Started with AutoTrading
- How Scripts Work
-->How Signals are Calculated
- Order Execution Priority
- Auto Trading
- Understanding Automated Trade Execution
- Comparison of Synchronous and Asynchronous Mode
Relevant articles in Wiki: Fundamentals
- Backtesting vs Live Trading
- Understanding Backtesting
- Why is Data Playback strategy performance different from Backtesting results?
- Intra-bar Price Movement Assumptions
- MaxBarsBack
Relevant articles in Wiki: Intermediate level readings
- Precise Backtesting
- Understanding Precise Backtesting
- Using Precise Backtesting
- Bar Magnifier
- Intra-Bar Order Generation, Bar Magnifier on Non-Standard Chart Types
Relevant articles in Wiki: Additional readings
- How to make indicator and signal calculation results the same
- Trades vs Orders With PosTrade Keywords
- Trading from Multiple Charts on One Instrument
- Manual Trading and Automated Trading on the Same Instrument at a Time
- Realtime-History Matching
Relevant articles in Wiki: Portfolio
- Understanding Portfolio Backtesting
- Backtesting a Portfolio
- Portfolio Optimization
- Additional info on Portfolio: FAQ - Portfolio Trader / Portfolio Backtester
-------------------------------------------------------
Has this post been helpful to you?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
2) Autotrade -- Before You Start
[FAQ] Before You Start
Before you jump head first into coding a strategy...
1. Understand that Autotrading is NOT Unattended Trading. NO amount of automation can prepare you for the unknown and/or the unexpected.
2. Build intelligence into your code -- your strategy should always check for your positions at the broker; that's where your money is.
3. Start with an indicator;
especially if you are new to programming,
Instead of jumping head first into coding a Strategy/Signal, start by coding an indicator first:
Wherever you think you have a BUY or SELL signal, make a PLOT on the chart to indicate your trigger point.
Can you see the plot?
Ask yourself this question: is my logic triggering the right signal at the right place? at the right time?
If not, why not? (See next post for debugging)
eg. If your logic isYou can begin your coding process by plotting a large dot at the SMAvalue,
so that you can see that this event can actually take place,
and that C was able to cross above this value to trigger a BUY order.
eg.
When you have verified all the variables are valid,
and your logic works (as shown by the plots on the chart),
you may then convert the indicator into a strategy.
If you skip this step, you will invariably find yourself starting again, back here, where you should have started your coding process in the first place.
.
Before you jump head first into coding a strategy...
1. Understand that Autotrading is NOT Unattended Trading. NO amount of automation can prepare you for the unknown and/or the unexpected.
2. Build intelligence into your code -- your strategy should always check for your positions at the broker; that's where your money is.
3. Start with an indicator;
especially if you are new to programming,
Instead of jumping head first into coding a Strategy/Signal, start by coding an indicator first:
Wherever you think you have a BUY or SELL signal, make a PLOT on the chart to indicate your trigger point.
Can you see the plot?
Ask yourself this question: is my logic triggering the right signal at the right place? at the right time?
If not, why not? (See next post for debugging)
eg. If your logic is
Code: Select all
If close cross above SMAvalue then BUY...
so that you can see that this event can actually take place,
and that C was able to cross above this value to trigger a BUY order.
eg.
Code: Select all
If close cross above SMAvalue then PLOT1( SMAvalue, "Buy.Signal" ); // set PLOT as a point
and your logic works (as shown by the plots on the chart),
you may then convert the indicator into a strategy.
If you skip this step, you will invariably find yourself starting again, back here, where you should have started your coding process in the first place.
.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
3) Autotrade FAQ
[FAQ] Learn to Debug
1. Know Your Data -- GIGO -- Before you start your debug, make sure you have clean data.
2. Know Your Variables -- Get rid of your generic variable names. ie. value1, var1, condition1, etc., and replace them with meaningful names.
Who can tell what this is about??? Who wants to debug this mess??? Variable names are free. You should use names that reflect the operation of your logic.
Otherwise you will be wasting time going back and forth trying to figure out what the variables are used for.
eg. Which variable name makes more sense?
You will appreciate them 3 months later when you try to revise your code.
4. Know Your Values -- Pepper your code with PRINT when debugging
You should add PRINT statements at all the pertinent junctions of your logic.
Every time you have an operation that changes the value of a variable,
you should splice a PRINT statement in there, so that you can verify the results of the operation is as expected.
5. Know Your BEGIN/END
6. Know Your Limitations -- See post #1 of this thread.
------------------------------------------
Has this post been helpful to you?
1. Know Your Data -- GIGO -- Before you start your debug, make sure you have clean data.
2. Know Your Variables -- Get rid of your generic variable names. ie. value1, var1, condition1, etc., and replace them with meaningful names.
Who can tell what this is about??? Who wants to debug this mess???
Code: Select all
value5 = ((value1+value4)/(value2*value3));
Otherwise you will be wasting time going back and forth trying to figure out what the variables are used for.
eg. Which variable name makes more sense?
3. Know Your Logic -- Add lots of comments to your code.
value4 = Average( Close, 20 );
Avg20 = Average( Close, 20 );
You will appreciate them 3 months later when you try to revise your code.
4. Know Your Values -- Pepper your code with PRINT when debugging
You should add PRINT statements at all the pertinent junctions of your logic.
Every time you have an operation that changes the value of a variable,
you should splice a PRINT statement in there, so that you can verify the results of the operation is as expected.
5. Know Your BEGIN/END
Code: Select all
If Up.Trend = true then
BEGIN
//
// your code
//
END; <-- Indent your codes so that you can visually match an END for each BEGIN
------------------------------------------
Has this post been helpful to you?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
4) IntrabarOrderGeneration (IOG) in Backtesting
[FAQ] IntrabarOrderGeneration (IOG) in Backtesting
viewtopic.php?f=1&t=10352&p=50828&hilit ... ion#p50828
Additional Readings:
How Signals are Calculated
Non-Standard Chart Types
Intra-Bar Order Generation, Bar Magnifier on Non-Standard Chart Types
Why is Data Playback strategy performance different from Backtesting results?
https://www.multicharts.com/trading-sof ... results%3F
---------------------------------------
Has this post been helpful to you?
Hi Henry
I enabled [IntrabarOrderGeneration = true]; but back test still shows exit at close of 3 min bar even i put in tick data.
Source:
Enabling IOG does not make your strategy to be calculated on the tick data in backtesting. Enabling IOG makes the script to be calculated four times on OHLC (of main data series bar).
If you want your strategy to be calculated on 1 tick data you need to enable Bar Magnifier.
Here is how the calculation will be performed for MC 8.0 beta 3 and higher:
Scenario A: Calculation on historical data. Regular mode. No IOG. No Bar Magnifier.
The script is calculated on the bar close. It is considered that all prices were within the bar (Price movement assumption is used). Order filled on any price within the NEXT bar.
Scenario B: Calculation on historical data. IOG enabled. No Bar Magnifier.
The script is calculated four times on OHLC. MultiCharts considers that there were only OHLC values->order is filled only on OHLC prices.
Scenario C: Calculation on historical data. IOG and Bar Magnifier enabled.
The script is calculated on the Open value of the main data series, then OHLC of each bar of the detailed data series selected in bar magnifier (Price movement assumption is used), then on the Close of the main data series. Order is filled only on these O-OHLC-C values.
Scenario D: Calculation on historical data. No IOG. Bar Magnifier enabled.
The script is calculated 1 time on main data series close. MultiCharts considers that there were only OHLC values of the detailed data series->order is filled only on OHLC prices.
viewtopic.php?f=1&t=10352&p=50828&hilit ... ion#p50828
Additional Readings:
How Signals are Calculated
Non-Standard Chart Types
Intra-Bar Order Generation, Bar Magnifier on Non-Standard Chart Types
Why is Data Playback strategy performance different from Backtesting results?
https://www.multicharts.com/trading-sof ... results%3F
---------------------------------------
Has this post been helpful to you?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
5) Built-In Stops / Profit Targets / OCO Orders
[FAQ] Built-In Stops / Profit Targets / OCO Orders
The following are EasyLanguage OCO keywords.
They are also called Global Exits.
Global Exits are meant to cover the entire strategy.
DO NOT use these keywords if you want individual conditional exits, You have to code those exit logics using BUYTOCOVER or SELL keywords.
To avoid logical errors, DO NOT place these keywords inside a condition:
SetBreakEven
SetBreakEven pt
SetDollarTrailing
SetExitOnClose
SetPercentTrailing
SetPercentTrailing pt
SetProfitTarget
SetProfitTarget pt
SetStopContract
SetStopLoss
SetStopLoss pt
SetStopPosition
SetStopShare
SetTrailingStop pt
These exit instructions are part of the Strategy Engine.
The orders are posted to broker AUTOMATICALLY when and only when there is an open position.
If the position is closed,
the remaining unfilled target and stop orders will be withdrawn automatically*.
* automatic means you do not need to code a logic to withdraw the orders,
they will be cancelled by MultiCharts' Strategy Engine automatically as soon as the position is closed.
The bracket/OCO order should be coded this way:
note:
Global Exit orders are executed intra-bar as soon as the condition is met,
regardless whether IntrabarOrderGeneration (IOG) is enabled.
* You can find usage examples in Wiki.
(NEW) [Q&A] Understanding Complex OCO scenario
viewtopic.php?f=1&t=48001
for more info on Built-in Stops, see
EasyLanguage Essentials Programmers Guide
Built-in Stops.......... pg. 90
EasyLanguage Reference Guide
Understanding Built-in Stops.......... pg. 132
Order types supported by various brokers:
https://www.multicharts.com/brokers/
https://www.multicharts.com/trading-sof ... rder_Types
https://www.multicharts.com/trading-sof ... r_Profiles
.
---------------------------------------
Has this post been helpful to you?
Answer:Questions:
-- Why is my SetStopLoss not executed?
-- How to code an OCO order?
-- How do I remove a stop loss order once a position is closed?
Here's my sample code. Why doesn't it work?Code: Select all
If Marketposition <> 0 and BuyCondition = True then Begin Buy ("B") next bar at Market; SetStopLoss ( 100 ) ; SetProfitTarget( 200 ); End ;
The following are EasyLanguage OCO keywords.
They are also called Global Exits.
Global Exits are meant to cover the entire strategy.
DO NOT use these keywords if you want individual conditional exits, You have to code those exit logics using BUYTOCOVER or SELL keywords.
To avoid logical errors, DO NOT place these keywords inside a condition:
SetBreakEven
SetBreakEven pt
SetDollarTrailing
SetExitOnClose
SetPercentTrailing
SetPercentTrailing pt
SetProfitTarget
SetProfitTarget pt
SetStopContract
SetStopLoss
SetStopLoss pt
SetStopPosition
SetStopShare
SetTrailingStop pt
These exit instructions are part of the Strategy Engine.
The orders are posted to broker AUTOMATICALLY when and only when there is an open position.
If the position is closed,
the remaining unfilled target and stop orders will be withdrawn automatically*.
* automatic means you do not need to code a logic to withdraw the orders,
they will be cancelled by MultiCharts' Strategy Engine automatically as soon as the position is closed.
The bracket/OCO order should be coded this way:
Code: Select all
If BuyCondition = true then
Begin
Buy ("B") next bar at Market;
End ;
SetStopLoss ( 100 ) ;
SetProfitTarget( 200 );
note:
Global Exit orders are executed intra-bar as soon as the condition is met,
regardless whether IntrabarOrderGeneration (IOG) is enabled.
* You can find usage examples in Wiki.
(NEW) [Q&A] Understanding Complex OCO scenario
viewtopic.php?f=1&t=48001
for more info on Built-in Stops, see
EasyLanguage Essentials Programmers Guide
Built-in Stops.......... pg. 90
EasyLanguage Reference Guide
Understanding Built-in Stops.......... pg. 132
Order types supported by various brokers:
https://www.multicharts.com/brokers/
https://www.multicharts.com/trading-sof ... rder_Types
https://www.multicharts.com/trading-sof ... r_Profiles
.
---------------------------------------
Has this post been helpful to you?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
6) SetExitOnClose
[FAQ] SetExitOnClose
Answer: from EasyLanguage® Functions & Reserved Words Reference
ps. Most brokers require the last order be submitted 3 minutes before closing time. Please check with your broker and make sure you are giving your order sufficient time to reach the exchange floor.
If you want to exit all positions before end of day, you have to code the exit manually.
eg. For a 5 min bar chart, and the closing time is 1600, you can try something like this:
or, use your computer clock (note: this will not work in backtest)
.
ps. Look up the keywords:
LastBarOnChart
IntraBarOrderGeneration
---------------------------------------
Has this post been helpful to you?
Question:
Why doesn't my SetExitOnClose work?
Answer: from EasyLanguage® Functions & Reserved Words Reference
ie. SetExitOnClose is for backtest only, not for real trades.
SetExitOnClose is a built-in stop reserved word used to place an order to exit all shares or contracts in all positions on the close of the last bar of the trading session on an intra-day chart.
For historical simulations, SetExitOnClose generates a market order on the bar close event of the last intra-day bar for each day in the chart.
When used in an automated strategy placing real-world orders, SetExitOnClose generates
a limit order into the post market trading session, (if one exists), otherwise a market order is generated for the open of the next regular session day.
Note
When automating a strategy, you will not want to use SetExitOnClose as a way to make sure that all of your positions are closed prior to the regular session end time. To do this, you will need to generate a closing order prior to the last bar in the chart.
ps. Most brokers require the last order be submitted 3 minutes before closing time. Please check with your broker and make sure you are giving your order sufficient time to reach the exchange floor.
If you want to exit all positions before end of day, you have to code the exit manually.
eg. For a 5 min bar chart, and the closing time is 1600, you can try something like this:
Code: Select all
input:
Last.Order.Time(1555);
if Time >= Last.Order.Time then
begin
SELL ...
BUYTOCOVER ...
end;
Code: Select all
input:
Last.Order.Time(1555);
if CurrentTime >= Last.Order.Time then
begin
SELL ...
BUYTOCOVER ...
end;
ps. Look up the keywords:
LastBarOnChart
IntraBarOrderGeneration
---------------------------------------
Has this post been helpful to you?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
7) This Bar on Close
[FAQ] This Bar on Close
BUY/SELL this bar on close ...is for backtest only.
Please read the explanation in:
EasyLanguage Essentials Programmers Guide
Strategy Order Syntax.... pg 80
---------------------------------------
Has this post been helpful to you?
Answer:Hi,
I have some problems with the order „sell this bar on close“ on a DayChart.
It tries to close the position after the market is close and it varies from 9 sec to 4 min after the market closed. Of course all the Market orders to sell are rejected.
BUY/SELL this bar on close ...is for backtest only.
Please read the explanation in:
EasyLanguage Essentials Programmers Guide
Strategy Order Syntax.... pg 80
you can google for a free copy of this ebook.
Order Actions
This Bar on Close: Market order on the close of this bar, generally used for historical backtesting purposes only. This will not generate a market on close order.
---------------------------------------
Has this post been helpful to you?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
8) Multiple Broker Accounts
[FAQ] Multiple Broker Accounts
Additional information:
Multiple IB Accounts
viewtopic.php?f=16&t=9858
The Wiki is a useful resource:
How To Connect Multiple Interactive Brokers Profiles
https://www.multicharts.com/trading-sof ... s_Profiles
---------------------------------------
Has this post been helpful to you?
Question:
I have 3 futures broker accounts. Can MC send orders to each broker for the same strategy or do I have to have 3 different workspaces?
In MultiCharts a strategy on chart can place orders only for 1 account a time. Other words, 1 chart = 1 account.
If you have 3 accounts under 1 login (1 broker profile, 3 accounts) you will need 3 separate chart windows trading individually on each of the accounts (specified in broker plug-in configuration).
If this is Financial Advisor (FA) or Family and Friends account from IB or PAMM account from FXCM, all orders can be sent from 1 chart to master account and then they are allocated to subaccounts on broker end.
Additional information:
Multiple IB Accounts
viewtopic.php?f=16&t=9858
The Wiki is a useful resource:
How To Connect Multiple Interactive Brokers Profiles
https://www.multicharts.com/trading-sof ... s_Profiles
---------------------------------------
Has this post been helpful to you?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
9) Autotrade Lost Connection
[FAQ] Autotrade Lost Connection
[new]
How to make a No Realtime Data Alert
viewtopic.php?f=16&t=11715
[FAQ] Setting Up Email Alert
post #13
viewtopic.php?f=16&t=6845
[FAQ] SMS Alert (Text message)
viewtopic.php?f=16&t=11738&p=54077
------------------------------------
Was this information helpful?
Question:
We use some simple strategy - it opened position and some times later connection was lost and autotrading off - we turn it on manually.
Strategy after turning on don't show position (it has it - it was still open at account) and don't manage it . Strategy was open on daily bars - bar doesn't end (that was same bar it opened position).
What should we do in order to strategy manage position (opened before) after turning on again (after connection lost) ?
viewtopic.php?f=1&t=10456&p=50934#p50934Hello,
When auto trading is turned off - the strategy position becomes zero.
You need to specify the position manually for each strategy next time you turn on the auto trading if you have a position at the broker. Please do the following:
Format-> Strategy properties-> Auto trading-> Assign the initial market position at the broker setting->Show the assign the initial market position at the broker dialogue-> Show always-> Ok.
When you start the auto trading - a dialogue window will appear where you can set the position for the strategy. This is how you can synchronize it (continue the trading from the position where you have left it).
You can also synchronize your strategy and broker position automatically with the help of the synchronizer script (!From Broker To Strategy MP Synchronizer!). But position at the broker cannot be divided between multiple strategies automatically by means of the "synchronizer" script. If you are trading with multiple strategies on one instrument - you need to assign the position manually for each strategy.
!From Broker To Strategy MP Synchronizer! - Synchronizes the market position inside MultiCharts with the market position at broker by sending a dummy order in charting.
[new]
How to make a No Realtime Data Alert
viewtopic.php?f=16&t=11715
[FAQ] Setting Up Email Alert
post #13
viewtopic.php?f=16&t=6845
[FAQ] SMS Alert (Text message)
viewtopic.php?f=16&t=11738&p=54077
------------------------------------
Was this information helpful?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
10) Backtest results different from Live Trading
[FAQ] Backtest results different from Live Trading
Question:
Is there a wiki for 'IntrabarOrderGeneration' strategy coding development/execution and debug?
I have a 1min strategy with IntrabarOrderGeneration=true and I have noticed quite a big difference between live results and back tested results
I noticed that I had not the bar magnifier set to tick data so I am trying that now.
Rather than 'guessing' this I would like to know if there is something like a 'wiki' available based on this development and testing available?
Please advise. Thanks
viewtopic.php?f=1&t=10228&p=49397&hilit ... sed#p49397It is expected that real-time strategy calculation and trading results (live broker account, demo broker account, playback etc...) are different from the performance results generated during backtesting.
• In real-time trading the order is filled according to market dynamics on Bid and Ask prices taking Volume into account. The order may not be filled in real-time trading because of insufficient volume at the broker. In backtesting and real-time strategy calculation the order is filled on the main data series price without taking Volume into account.
• In real-time trading, a strategy will monitor and respond to a data feed on tick-by-tick basis. However, the historical data available for backtesting will, in most cases, be in the form of bars based on a group of ticks, with only Open, High, Low, and Close prices available. While it is not possible from these four values to infer the actual price movement within each bar, the Backtesting Engine improves the backtesting accuracy by incorporating intra-bar price movement assumption logic
• Different detalization and strategy calculation methods can be selected which will produce different results.
- • [edited] Back Testing
• IOG
• Bar Magnifier• There are differences in real-time data and historical data that affect the strategy calculation results. You should understand how chart bars are built. A single tick difference between real-time and historical backfilled data can generate completely different looking charts. This in turn would impact the calculations of your strategy.
- 1. If you are not using IOG mode for your signal then the signal is calculated on the close of the bar.
2. In realtime with IOG enabled the script is calculated tick by tick.
3. Without IOG on history-the script is calculated on the bar close.
4. With IOG enabled on history-the script is calculated four times on OHLC of the bar.
5. Bar magnifier is a separate feature for backtesting. Bar magnifier does not affect realtime calculation. Please find more information at the Bar Magnifier wiki page.
• The difference in strategy calculation is especially seen on certain chart types (e.g. Point and Figure) than others due to their inherent nature in bar formation. Please refer to this page for more details.
This is why you may see orders not fill in real-time strategy calculation or real-time strategy trading compared to your backtesting results.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
11) Optimization
[FAQ] Good discussions on Optimization
Custom Criteria – creating your own optimization criteria
viewtopic.php?f=5&t=8838
Optimize on Sharpe Ratio
viewtopic.php?f=1&t=12625
Custom Criteria – creating your own optimization criteria
viewtopic.php?f=5&t=8838
Optimize on Sharpe Ratio
viewtopic.php?f=1&t=12625
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
12) Stop Order
[FAQ] How Stop Order Works
viewtopic.php?f=1&t=11270&view=unread#p55667
An IB stop order in TWS will change into a marketorder if the stoporder price is hit.
When you use a stop order in a strategy like this:
And you have for example 2000 stocks which are not filled immediately but for example 200, ten seconds later 500 and thirty seconds later the rest. The strategy (I use IOG) will keep sending the stop again till every stock is sold. Resulting in IB thinking it is a new stop order which is hit immediately but giving extra transaction costs.Code: Select all
if marketposition = 1 then begin
Sell ("StopLossLong") next bar "your stop price" stop;
end;
Is the stoporder that is sendout by MC also converted to market order at IB? and how to stop the strategy from sending the stoporder over and over again when the stoporder is already hit but not all stock are sold yet?
More discussion and explanations here:Hello,
If an order is sent to broker and the parameters of the order are not changed, MultiCharts will not send the same order to broker to "maintain" it. In your particular case, if from the moment the initial stop order is sent, your script doesn't generate a different stop (it can happen only if the order gets new parameters or the OCO group of the order is cancelled to be replaced by a new OCO group of orders, so the initial partially filled order has to be cancelled), no new order will be sent. MultiCharts will wait till the initial stop order is filled.
As for handling the stop orders when IB is the broker, they support stop orders, so the orders are sent directly to them and are filled on their end.
viewtopic.php?f=1&t=11270&view=unread#p55667
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
13) CPU
[FAQ] Backtesting vs Optimization CPU Usage -- Single Core vs Multi-Core vs Hyperthread
On **optimizing** Optimization -- Multi-Core, Multi-Thread, Multi-CPU
Portfolio_Trader#Script_Calculation_and_Raw_Order_Generation
Portfolio_Script_Calculation_Diagram
Sequence diagram for portfolio keywords calculation example
Optimization and Logical Cores (Hyperthread, Threadripper, etc.)
Strategy Recalculation (Backtesting) and Strategy Optimization are two very different things.
During backtesting only one core can be used, because the process is sequential, i.e. it depends on previous results to obtain a result at a later date. It cannot be split up into multiple cores.
Optimization on the other hand can be split up into multiple cores because it consists of many iterations of the same thing, but with different inputs.
viewtopic.php?f=1&t=8739&p=41127&hilit= ... ore#p41116
Logical cores don’t give any advantages in optimization speed.
Please try to set the NumberOfThreadsOnOptimization=the number of real cores on your PC. Then there will be less additional crossovers in comparison to the classic incremental GA, but the speed will remain the same.
viewtopic.php?t=51229
On **optimizing** Optimization -- Multi-Core, Multi-Thread, Multi-CPU
For Portfolio Trader, please study how Portfolio Calculation is done:For information,
2 years ago, I did several tests with a 4 CPU x 16 cores from HP.
with same results: very low cpu usage.
We had to perform the last test in an HP certified lab.
An AMD high tech specialist finally brought the explanation:
every RAM slot has to be populated. If not, CPU usage is bounded, for some (stupid) unknown technical reason.
So instead of putting 4 x 8 GB (1 per CPU), we put 16 x 2GB (4slots/cpu x4cpu), and it worked: we obtained 100% CPU usage. It was not the global quantity of Ram, which matters, but the physical presence of any Ram in each slot. Actually, probably 8GB total RAM would have been enough.
So Multicharts ( 8 beta3) was not in cause.
Please note that the speed gain between another computer with 1 CPU x 16 cores and this one 4 CPU x 16 cores was less than 3 times…
It means that, probably, a 1 CPU with 64 cores would do much better.
viewtopic.php?f=1&t=48049
Portfolio_Trader#Script_Calculation_and_Raw_Order_Generation
Portfolio_Script_Calculation_Diagram
Sequence diagram for portfolio keywords calculation example
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
14) Realtime-History Matching
[FAQ] Multi-data strategy, Realtime-History Matching
Question:
I have a quick question. Signals are evaluated at the end of the bar unless IOG is selected. But how does it work for multi-series signal scripts ?
lets say my base chart is on a 3-tick Renko and I add another series which is 5-tick Renko. For most bars the 'End of Bar' for 3-tick Renko and 5-tick Renko would be different.
So are the signals evaluated for end of bars for 3-tick and 5-tick Renko ? or just end of bar for 3-tick (base series) ?
Hope I'm clear in what I'm asking. Thanks in advance for your help
viewtopic.php?f=16&t=10553
Hello,
Calculation of a study based on several data series can be done in two ways. Realtime-History Matching option allows selection of calculation type:
1. When Realtime-history matching option is enabled the signal/indicator is calculated on the latest bar of the main data series and on the currently completed bar of the auxiliary data series. If the auxiliary data series stops updating, the final calculation will be made on the main data series bar that was received immediately after the latest bar of the auxiliary data series. In this case no further calculation will be performed.
2. When Realtime-history matching option is disabled the signal/indicator is calculated on the basis of the main data series latest bar and current (completed or not) bar of the auxiliary data series. If the auxiliary data series stops updating, the calculation will continue on the basis of the latest bar of the main data series and the open bar of the auxiliary data series.
For more information, please visit this article of our MC Wiki.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
15) Limit the Time of Autotrade
[FAQ] Limit the Time of Autotrade
Answer: see sample code below:Question:
How do I limit a strategy to trade only a specific period of time.
eg. from 10 am to 2 pm only?
Code: Select all
input:
start.time(1000),
end.time(1400);
if time >= start.time
and time <= end.time then
BEGIN
//
// put your autotrade code here:
//
END;
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
17) Results difference
[FAQ] Results difference for Backtest in Portfolio Backtester and MultiCharts
viewtopic.php?f=1&t=9794
viewtopic.php?f=1&t=9794
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
18) Multiple Time Frame, Multi-Data Analysis
[FAQ] Multiple Time Frame, Multi-Data Analysis
The Essential EasyLanguage Programming Guide
Multi-Data Analysis... pg. 15
Multi-Data Indicators... pg.71
Multi-Data Reference... pg.72
Data(n)... pg.72
Getting Started with TS EasyLanguage
Multi-data strategy... pg. 43
Note: you can google for a free copy of the above ebooks.
Note: As a rule of thumb, when using multi-data, always put the fastest fractal as data1, and slower fractals as secondary data.
(eg. 1 min as data1, 5 min as data2).
For advanced programming of multi-data in multiple charts, do a search for:
Globalvariable v2.2,
ELCollections,
ADE (All Data Everywhere).
[NEW Keywords]
i_getplotvalue
i_setplotvalue
---------------------------------------
Has this post been helpful to you?
Question:
I was wondering if someone knew a way to run multiple time frames of multiple instruments on a chart and have an indicator synced to all 3 at the same time. By this I mean I want to run the indicator on all 3 charts and only show an alert when the indicator condition is met on all 3 at the same time. Any thoughts would be appreciated
Thanks
The Essential EasyLanguage Programming Guide
Multi-Data Analysis... pg. 15
Multi-Data Indicators... pg.71
Multi-Data Reference... pg.72
Data(n)... pg.72
Getting Started with TS EasyLanguage
Multi-data strategy... pg. 43
Note: you can google for a free copy of the above ebooks.
Note: As a rule of thumb, when using multi-data, always put the fastest fractal as data1, and slower fractals as secondary data.
(eg. 1 min as data1, 5 min as data2).
For advanced programming of multi-data in multiple charts, do a search for:
Globalvariable v2.2,
ELCollections,
ADE (All Data Everywhere).
[NEW Keywords]
i_getplotvalue
i_setplotvalue
---------------------------------------
Has this post been helpful to you?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
19) Trading Multiple Instruments
[FAQ] Trading Multiple Instruments
[FAQ] Portfolio Trader / Portfolio Backtester
viewtopic.php?f=16&t=47045
More readings and discussions here:Hello,
By default from one chart you can trade only the instrument that is the main data series. You cannot send orders to any additional data series of the same chart. You need to have an individual chart for each instrument you want to trade.
That is possible to use the Portfolio Trader introduced in MC 9.0 to automate order execution for multiple instruments. You can find more details regarding the new portfolio trading here:
Portfolio Trader Manual:
https://dl.dropboxusercontent.com/u/951 ... Manual.pdf
Portfolio Trader Strategy Examples:
https://dl.dropboxusercontent.com/u/951 ... amples.pdf
[FAQ] Portfolio Trader / Portfolio Backtester
viewtopic.php?f=16&t=47045
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
20) Bar Magnifier
[FAQ] Backtest, Playback, IOG and Bar Magnifier
More Readings:
How Signals are Calculated
Additional Explanation:
Backtest and IOG, Bar Magnifier
viewtopic.php?f=16&t=10811&p=119777#p53292
-----------------------------------------
Has this post been helpful to you?
Question:
Regarding the IOG, i've got a problem, if i turn on IOG in the strategy, when i do the backtesting, will the system simulate in a way that it read every tick to see whether the buy signal trigger in the middle of the bar, or it only runs at the close of the bar?
the reason i have this question is that when i use the playback function of multicharts, it will only playback one bar each time, but not simulating the real situation and playback every tick, so i wonder if the IOG function can work in the backtesting procedure.
thanks
viewtopic.php?f=1&t=9343&p=44626#p44626In realtime with IOG enabled the script is calculated tick by tick.
Without IOG on history-the script is calculated on the bar close.
With IOG enabled on history-the script is calculated four times on OHLC.
In Backtesting you can use Bar magnifier
(Strategy Properties -> the Backtesting tab -> Backtesting Precision section -> select Use Bar Magnifier).
The Bar Magnifier backtest feature is important for precise backtesting.
Bar magnifier can be considered as a replay of the way a bar was formed.
The user can choose a replay frequency that is based on number of ticks or
number of minutes.
With IOG and Bar Magnifier enabled the script will be calculated on the close of each bar of detailed data series selected in bar magnifier + high/low of the main data series.
Also you can read about this feature in the Help section of Multicharts.
More Readings:
How Signals are Calculated
Additional Explanation:
Backtest and IOG, Bar Magnifier
viewtopic.php?f=16&t=10811&p=119777#p53292
-----------------------------------------
Has this post been helpful to you?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
21) Slippage
[FAQ] Slippage
viewtopic.php?f=1&t=49579&view=unread#p120370
In backtesting:
By default the slippage is not calculated for stop limit and limit orders as there is no slippage when such type of order is filled at broker. Limit order can be filled at the specified price or better price.
Slippage is calculated for market and stop orders. It is deducted from profit.
If you still want to have slippage calculated for stop limit and limit orders – you can enable an option in the registry editor:
HKEY_CURRENT_USER\Software\TS Support\%your version of MultiCharts%\StrategyProp
Change the value of "UseSlippageForAllTypes" key to 1.
1 = slippage for all orders
0 = slippage for market and stop orders only
In auto trading:
By default commission and slippage are not applied to any orders. But since MultiCharts 9.0 we
have added a registry key to disable/enable counting commission and slippage for special orders (SetStopLoss, SetProfitTarget, etc). One can configure UseCommissionForSpecOrders in:
HKEY_CURRENT_USER\Software\TS Support\%your version of MultiCharts%\StrategyProp.
0 - default value (commission and slippage are not applied).
1 - special orders correct the price upwards (for Long orders) and downwards (Short) to compensate the potential loss.
You will need to restart all MultiCharts processes to have these changes applied.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
22) Cancel Orders
[FAQ] Code to Cancel Orders at Session End before after hours
viewtopic.php?f=1&t=46449&p=104194
Tags:
RecalcLastBarAfter
AllowSendOrdersAlways
IntrabarOrderGeneration
viewtopic.php?f=1&t=46449&p=104194
Tags:
RecalcLastBarAfter
AllowSendOrdersAlways
IntrabarOrderGeneration
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
24) Advanced Topics
[FAQ] [Advanced Topic] Semi-Discretionary Trading
[FAQ] [Advanced Topic] Semi-Automated Trading
Semi-Discretionary or Semi-Automated Trading
viewtopic.php?f=1&t=10817
Automated Exit Strategy with Manual Trading
viewtopic.php?f=16&t=8499
Tags:
!From Broker To Chart Strategy!
!From Broker To Strategy MP Synchronizer!
AvgEntryPrice_at_Broker
---------------------------------------
Has this post been helpful to you?
[FAQ] [Advanced Topic] Semi-Automated Trading
Semi-Discretionary or Semi-Automated Trading
viewtopic.php?f=1&t=10817
Automated Exit Strategy with Manual Trading
viewtopic.php?f=16&t=8499
Tags:
!From Broker To Chart Strategy!
!From Broker To Strategy MP Synchronizer!
AvgEntryPrice_at_Broker
---------------------------------------
Has this post been helpful to you?