Differing Values

 

Hi, im not sure why but two different values are being printed. Can't seem to figure out why, thanks in advance

input bool                                MAEntryRequirement               = true;

input int                                 MAMinimumDistance                = 0;
input int                                 MAMaximumDistance                = 40;

//+-------------------------------------------------------------------------------------------------------+
//|  Global Variables                                                                                     |
//+-------------------------------------------------------------------------------------------------------+

double symbol_points[];
string symbol_loop[] = {"GBPUSD"};
ENUM_TIMEFRAMES timeframe_loop[] = {PERIOD_M15, PERIOD_H1};

int maHandle[];

datetime old_time;

//+-------------------------------------------------------------------------------------------------------+
//|  Include Files                                                                                        |
//+-------------------------------------------------------------------------------------------------------+

#include <Trade/Trade.mqh>
CTrade trade;

//+-------------------------------------------------------------------------------------------------------+
//|  On OnInit                                                                                            |
//+-------------------------------------------------------------------------------------------------------+

int OnInit()
  {
   ArrayResize(maHandle, ArraySize(symbol_loop));

   for(int i = 0; i < ArraySize(symbol_loop); i++)
     {
      maHandle[i] = iMA(symbol_loop[i], PERIOD_H1, 14, 0, MODE_SMA, PRICE_CLOSE);
     }

   return(INIT_SUCCEEDED);
  }

//+-------------------------------------------------------------------------------------------------------+
//|  OnTick                                                                                               |
//+-------------------------------------------------------------------------------------------------------+

void OnTick()
{  
   datetime GMT = iTime(_Symbol, PERIOD_H1, 1);
   if(GMT > old_time)
   {
      old_time = GMT;

      for(int i = 0; i < ArraySize(symbol_loop); i++)
      {
         string symbol = symbol_loop[i];

         for(int j = 0; j < ArraySize(timeframe_loop); j++)
         {
            ENUM_TIMEFRAMES timeframe = timeframe_loop[j];

            //------------------------------------//
            // GENERAL INFO                       //
            //------------------------------------//
         
            double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
            double contractSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_CONTRACT_SIZE);
            double point = tickValue / contractSize;
      
            double spread = 2;
            double PipValue = point * 10;

            //------------------------------------//
            // PRICE INFO                         //
            //------------------------------------//                  
            double Low = low(symbol, timeframe, 1);
            double High = high(symbol, timeframe, 1);
          
            double ma[];
            ArraySetAsSeries(ma, true);
            CopyBuffer(maHandle[i], 0, 0, 1, ma);
            double MA_Value = ma[0];

            double TP_SL_maScore = MA_Score(MAEntryRequirement, MAMinimumDistance, MAMaximumDistance, MA_Value, point, High, Low);
                      Print(TP_SL_maScore);
            }           
                        
         }  
      }
   }


//+-------------------------------------------------------------------------------------------------------+
//|  Execution                                                                                            |
//+-------------------------------------------------------------------------------------------------------+

double MA_Score(bool pMAEntryRequirement, double pMAMinimumDistance, double pMAMaximumDistance, double pMA_Value, double pPoints, double pHigh, double pLow)
{
    double pipValue = pPoints * 10;
    double MA_Range = (pMAMaximumDistance - pMAMinimumDistance) * pipValue;
    double MAMinimumDistanceConversion = pMAMinimumDistance * pipValue;

    double MaximumSellingPriceLevel = pMA_Value + MAMinimumDistanceConversion + MA_Range;
    double MinimumSellingPriceLevel = pMA_Value + MAMinimumDistanceConversion;

    double MaximumBuyingPriceLevel = pMA_Value - MAMinimumDistanceConversion - MA_Range;
    double MinimumBuyingPriceLevel = pMA_Value - MAMinimumDistanceConversion;

    double Entry_Score = 0;
    double relativeValue = 0;

    if (pMAEntryRequirement)
    {
        if (pHigh > pMA_Value)
        {
            if (pHigh > MaximumSellingPriceLevel)
            {
                Entry_Score = 1;
            }
            else if (pHigh > MinimumSellingPriceLevel && pHigh < MaximumSellingPriceLevel)
            {
                relativeValue = pHigh - MinimumSellingPriceLevel;
                Entry_Score = relativeValue / MA_Range;

            }
        }
        else if(pHigh <= pMA_Value){
        relativeValue = 1000000;
        }
        /*
        else if (pLow < pMA_Value) 
        {
            if (pLow < MaximumBuyingPriceLevel)
            {
                Entry_Score = 1;
            }
            else if (pLow > MinimumBuyingPriceLevel && pLow < MaximumBuyingPriceLevel)
            {
                relativeValue = MaximumBuyingPriceLevel - pLow;
                Entry_Score = relativeValue / MA_Range;
            }
        }*/
    }

    return relativeValue;
}


double high(string symbol, ENUM_TIMEFRAMES timeframe, int shift)
  {
   return iHigh(symbol, timeframe, shift);
  }

double low(string symbol, ENUM_TIMEFRAMES timeframe, int shift)
  {
   return iLow(symbol, timeframe, shift);
  }