AIS Optimal Duration Transaction

0.00

This script is designed to allow the trader to determine the average duration of trading transactions, at which the ratio of possible profits and losses will be optimal.
First, let’s look at the general approach to determining the optimal duration of trading transactions. Enter the following variables:
R – the result of the transaction;
T – the time during which the transaction was open;
W – the time between closing the previous trade and opening the next one.
Every trader strives to get the maximum profit in the shortest possible time. This desire can be described by the following simple expression:
Obviously, the variables T and W depend on both the total duration of the trade and the number of transactions made. Let ATD be the average duration of the transaction, and N be the total number of transactions. Then the average duration of the transaction should grow in proportion to the square root of their total number, that is:
However, there are well-founded questions here – is every transaction duration equal in relation to others, and how can the duration of transactions affect the results of trading operations? To get answers to these questions, we will conduct a small study of the price behavior on historical data.

Let’s proceed as follows. Let’s break the historical data into series consisting of a certain number of bars corresponding to the average duration of the trade. In each such series, we will calculate the maximum price movement, while the larger deviation will be attributed toStopLoss, and less – to TakeProfit.
After that, we will calculate the average ratio of the price span over the entire history, and see how it changes depending on the number of bars that determine the length of the series.
Script parameters:
• MTD – maximum duration of the series;
• OCD – if set to true, only the optimal series sizes will be output.
• MTD – maximum duration of the series;
• OCD – if set to true, only the optimal series sizes will be output.
Run the script on the currency pair of interest and the desired time frame, and wait for the message about the end of the work. The calculation result is saved in the file “AIS-ODT. csv“. The first column indicates the length of the series, expressed in bars. The second column shows the average ratio of possible gains and losses on a given currency pair and a given time frame.
From the point of view of trading, the most interesting are the series lengths at which the ratio of profit to loss reaches a local maximum. If, when developing a trading strategy, a trader will focus on such durations of trading transactions, then he will be able to achieve a small, but an advantage.

[/spoiler]