Looking for some help with MQL4 function to parse a variable

 

Hi,

I've written a function that I'm setting up to slowly reduce a profit target on a basket of trades.

I have a variable set up 

input string ExitStrategyAsian = "00:00-1;08:00-0.9,08:30-0.8,09:00-0.75,09:30-0.65,10:00-0.50,10:30-0.40";

The theory is that every 30 minutes ( or whatever interval I want ) it sets a new scaling factor which is then used by a closing function to try and exit a basket of trades.

The function I have written is below.

I send it the current DailyProfitTarget ( which might be 1% ) and a target for each instrument ( which could be 0.5% ) and the exit strategy variable ( above )

At the moment it's not always calculating the correct value based on the current market watch time. 

Can anyone spot where I've gone wrong please? Thanks!

( CreateLabel is a custom function used to show the result on screen )


void ReduceDailyProfitTarget(double& DailyProfitTarget2, double& DailyPairTarget2, string ExitStrategy)
{
    string delimiter = ",";
    int pos = 0;
    string token;

    datetime currentTime = TimeCurrent();
    double latestRatio = 1.0;
    datetime exitTime; 
    
    while ((pos = StringFind(ExitStrategy, delimiter)) >= 0)
    {
        token = StringSubstr(ExitStrategy, 0, pos);
        ExitStrategy = StringSubstr(ExitStrategy, pos + 1);

        int delimiterPos = StringFind(token, "-");
        string timeStr = StringSubstr(token, 0, delimiterPos);
        string ratioStr = StringSubstr(token, delimiterPos + 1);

        exitTime = StringToTime(timeStr);

        if (currentTime >= exitTime)
        {
            latestRatio = StringToDouble(ratioStr);
        }
    }

   DailyProfitTarget2 *= latestRatio;
   DailyPairTarget2 *= latestRatio;
   CreateLabel("Exit",0, "Ratio of " + latestRatio + " applied",9,"Tahoma",Orange,4,800,0);
}