In my MQL4 code that I re-use across all of my tools I have a library of common functions that I reuse all the time. As an exercise I wanted to see how easy it would be to recreate this functionality in Chart Logic, and to be able to import and use these functions in my Chart Logic strategies. The answer is: easy. It was very, very easy.
Points to Pips - Convert a value like "0.00200" or "0.200" to "20.0" pips correctly, taking the chart symbol into account.
Pips to Points - Convert a value like "20.0" pips to "0.00200" or "0.200" correctly, taking the chart symbol into account.
PipValue - Calculate the value per pip per lot for this symbol. Used when calculating lot sizes.
Percent to Amount - Convert "0.25%" to an amount of your account balance.
Amount to Percent - Convert an amount to the percentage of your account balance.
calculateLots - Given a SL distance in pips and an amount, calculate the number of lots.
calcuateAmount - Given a number of lots and a distance, calculate the amount this represents. Used to find position average lines, or the price at which a trade or position would reach a certain value.
The test file sets some variables and passes data into the functions to see what they do with it. Activate the strategy and view it in the strategy viewer to see the results.
The other file contains each function as a separate file. These are conditions in Chart Logic, which you can import directly into your Logic Sets and Set Conditions when you need to perform one of these calculations.
