Scripts: Correlation Gaps Trading AUDJPY CADJPY NZDJPY

 
 

I really wanted this strategy, I'm really really want to ask you about that can you make this code to fully automatically trade?

cuz I was looking for this logic for 1 years and now finally fount it...so happy...but I'm just have basic understand of MT 4 code.

If you let me know your e-mail, I will contact you asap!!

please...

 
Troy C #:

I really wanted this strategy, I'm really really want to ask you about that can you make this code to fully automatically trade?

cuz I was looking for this logic for 1 years and now finally fount it...so happy...but I'm just have basic understand of MT 4 code.

If you let me know your e-mail, I will contact you asap!!

please...

For now the only implementation in an auto strategy I can think at is  Spearman correlation. I had some unsuccessful attempts to make an EA, and I am still working on it.

Thank you for your message.

 

To calculate the Spearman correlation coefficient between two instruments, you would typically follow these steps:

  1. Data Collection: Gather the data for both instruments. Ensure that for each observation, you have paired values from both instruments.

  2. Ranking: Rank the data from each instrument separately. Assign ranks based on the order of values, with the smallest value receiving a rank of 1, the next smallest a rank of 2, and so on.

  3. Calculate Differences: Calculate the differences between the ranks of corresponding pairs of values. If two values are tied, assign them the average of the ranks they would have received.

  4. Square Differences: Square each of these differences.

  5. Sum Squared Differences: Sum up all of the squared differences.

  6. Calculate Spearman's Correlation Coefficient: Use the formula for Spearman's correlation coefficient, which is given by:



This formula adjusts for ties in the data and provides a measure of the strength and direction of the monotonic relationship between the two instruments.

  1. Interpretation: The Spearman correlation coefficient ranges from -1 to 1. A value close to 1 indicates a strong positive relationship (as one variable increases, the other tends to increase), a value close to -1 indicates a strong negative relationship (as one variable increases, the other tends to decrease), and a value around 0 indicates no monotonic relationship.

Remember, the Spearman correlation coefficient assesses the strength and direction of monotonic relationships, meaning that it can detect relationships that are not necessarily linear. It's often used when the data may not meet the assumptions of other correlation methods, such as Pearson correlation, due to non-normal distributions or outliers.

Let's assume we have the following data:

Instrument 1 (X): [10, 15, 20, 25, 30] Instrument 2 (Y): [8, 12, 18, 22, 28]

  1. Ranking: For X: [1, 2, 3, 4, 5] For Y: [1, 2, 3, 4, 5]

  2. Calculate Differences: Differences (d): [0, 0, 0, 0, 0]

  3. Square Differences: Squared Differences: [0, 0, 0, 0, 0]

  4. Sum Squared Differences: Sum of squared differences (Σd²): 0

  5. Calculate Spearman's Correlation Coefficient:

Given 




  1. Interpretation: The Spearman correlation coefficient (
    ρ
    ) is 1, indicating a perfect positive monotonic relationship between the two instruments. In this case, as the values of Instrument 1 increase, the values of Instrument 2 also increase in a perfect linear manner.

This example demonstrates how to calculate the Spearman correlation coefficient using specific data points for two instruments (X and Y).

MathML Namespace
  • www.w3.org
MathML Namespace
Reason: