Scripts: Hedge_Dollar_Index_Against_Forex_Pairs_V1

 

Hedge_Dollar_Index_Against_Forex_Pairs_V1:

Hedge Dollar index USIDX against its constitutive FOREX pairs EURUSD GBPUSD USDJPY USDCAD USDSEK USDCHF

Author: Iulian Persinaru

 

How to calculate the position size of the red box in the picture below?


 
HyungCheol Cho #:

How to calculate the position size of the red box in the picture below?


Hello, Mr. Cho 

Thank you for your message.

These Positions were calculated using Dukascopy Pip Calculator and JForex 4.2.9 demo trading platform. MT4 and my FOREX provider do not offer this kind of calculations.

Let me know if you have other questions! 

Cheers :) Julian

 
Iulian Persinaru #:

Hello, Mr. Cho 

Thank you for your message.

These Positions were calculated using Dukascopy Pip Calculator and JForex 4.2.9 demo trading platform. MT4 and my FOREX provider do not offer this kind of calculations.

Let me know if you have other questions! 

Cheers :) Julian

To create an MQL4 position size calculator, you need to consider various factors such as risk percentage, stop loss distance, account balance, and currency pair volatility. Here's a basic example of an MQL4 function to calculate position size based on these inputs:

In this example:
  • CalculatePositionSize function calculates the position size based on the risk percentage, stop loss distance, and account balance.
  • riskPercentage is the percentage of the account balance that you're willing to risk on a single trade.
  • stopLossDistance is the distance in pips from the entry price to the stop loss price.
  • accountBalance is the current account balance.

Make sure to verify the pip value calculation for the specific currency pair being traded, as it can vary. Also, consider additional factors such as leverage and margin requirements based on your broker's specifications. This example is a basic one and may need modifications to suit your specific trading strategy and requirements.

// Function to calculate position size
double CalculatePositionSize(double riskPercentage, double stopLossDistance, double accountBalance)
{
    // Calculate position size based on risk percentage, stop loss distance, and account balance
    double riskAmount = accountBalance * (riskPercentage / 100.0);
    double pipValue = MarketInfo(Symbol(), MODE_POINT); // Get pip value for the current symbol
    double positionSize = riskAmount / (pipValue * stopLossDistance);

    return positionSize;
}

// Example usage
void OnStart()
{
    double riskPercentage = 2.0; // Risk percentage (e.g., 2%)
    double stopLossDistance = 50.0; // Stop loss distance in pips
    double accountBalance = AccountBalance(); // Get account balance

    double positionSize = CalculatePositionSize(riskPercentage, stopLossDistance, accountBalance);
    Print("Position size: ", positionSize);
}

Reason: