This script allows you to select the TakeProfit and StopLoss levels. It analyzes historical data, and then calculates the probability of reaching a particular price level.
Let’s say you have a trading strategy and you want to match it with the TakeProfit and StopLoss levels. Run the script and set the parameter:
- Number of Bars – the average lifetime of an open position, expressed in bars.
After the script finishes working, the AIS-PPL.csv file will be created in the terminal data directory in the Files folder . The PCT column shows the probability (as a percentage) of the price deviation from the entry point by the number of points indicated in the LVL column.
When choosing the TakeProfit and StopLoss levels, you should strive to meet the following conditions::
- PCT_tp >= PCT_sl
- PCT_tp * LVL_tp >= PCT_sl * LVL_sl.
If we take V = PCT_tp / (PCT_tp PCT_sl), then the most optimal case is obtained when the equation V * (V * LVL_tp – (1-V) * LVL_sl) strives for the maximum.
These optimal values are displayed at the end of the script in the Alert window.