EA with ma-crosses, chart show profit but code show loss, why?

 
void start()
  {
  double ma, currentcross=0, previouscross=0;
  double cutlevel=0.03, totalprofit=0, volume=1;
  double resulttable[40][50000][5];
  ArrayInitialize(resulttable,-12345);
  int a=0, iMa=926, b=0, profitelement=0; string time;
  
  
  for(int j=1;j<3;j++){ 
      iMa+=25;
      cutlevel=0.03;    
   for(int c=0;c<100;c++){  
       cutlevel+=0.01;     
       b=0;                                  
       totalprofit=0;
       currentcross=0;
       previouscross=0;
       volume=1;
      for(int s=80000;s>1;s--){       
         ma=iMA(NULL,PERIOD_M1,iMa,0,MODE_SMA,PRICE_CLOSE,s);
         if((Open[s]>ma && Close[s]<ma)||(Open[s]<ma && Close[s]>ma)){   
            
            if(b==0)
               currentcross=0;
            else
               currentcross=Close[s];
            
            if((Open[s]>ma) && (Close[s]<ma))
               resulttable[a][b][0]=currentcross-previouscross; 
            
            if((Open[s]<ma) && (Close[s]>ma))
               resulttable[a][b][0]=-currentcross+previouscross;
               
            time=TimeToStr(Time[s],TIME_DATE|TIME_MINUTES);
            
            if(resulttable[a][b][0]!=-12345)
               totalprofit+=volume*resulttable[a][b][0];
            Sleep(100);
            Print("VOL ,",volume,"  ,PIP ",resulttable[a][b][0],"  ,TOT, ",totalprofit,"  ,CUT, ",cutlevel,"  ,MA, ",iMa,"  ,Number, ",b,"  ,Candle, ",s,"  ,TIME, ",time);
            
            if(totalprofit<cutlevel) 
               volume=(cutlevel-totalprofit)/cutlevel;
            else  
               volume=1;  
            
            if(totalprofit>=cutlevel){
               totalprofit=0;
               volume=1;
            }
                                                       
            b++;
            Sleep(100);
            previouscross=Close[s];
         }//if open                 
       }//price   
     }//cut
    a++; //new ma value
  }//ma
}//start

This is the code I´m using, it simply buy and sell when the price cross the ma-indicator. The code type -0,0196 pip on one cross but it is 0.0196 when looking at the chart (picture below), why is the sign reversed?