// Downloaded From https://www.WiseStockTrader.com
  function cccc(Buy,Sell) 
  { 

  CumCst = Null; 

  for (i = 1; i < BarCount; i++) 
  { 

     if(Buy[i]) 
     { 

        CumCst[i]=0.10; 

        for (j = i + 1; j < BarCount; j++) 
        { 
         
           if (Sell[ j ] ) 
           { 
              i = j - 1; 
              break; 
               
           }       
           else if(C[j] > C[j-1]) 
           { 
            
              CumCst[j] = Min(CumCst[j-1] + 0.003,0.13); 
            
           } 
           else if(C[j] <= C[j-1]) 
           { 
            
              CumCst[j] = CumCst[j-1];          
            
           } 
           else if (j == BarCount - 1) 
           { 
                           
              i = BarCount; 
              break; 
                           
           } 
         
        } 

     } 
     else if(Sell[i]) 
     { 

        CumCst[i]=0.10; 

        for (j = i + 1; j < BarCount; j++) 
        { 
         
           if (Sell[ j ] ) 
           { 
              i = j - 1; 
              break; 
               
           }       
           else if(C[j] < C[j-1]) 
           { 
            
              CumCst[j] = Min(CumCst[j-1] + 0.003,0.13); 
            
           } 
           else if(C[j] >= C[j-1]) 
           { 
            
              CumCst[j] = CumCst[j-1];          
            
           } 
           else if (j == BarCount - 1) 
           { 
                           
              i = BarCount; 
              break; 
                           
           } 
         
        } 

     }    

  } 

  return CumCst; 

  } 

  Buy=Cross(C,EMA(C,19)); 
  Sell=Cross(EMA(C,19),C) ; 

  CumCst = cccc(Buy,Sell); 

  per=19; 
  Smth = 2/(per+1)+CumCst; 

  MovAvg = AMA(C,Smth); 

  Plot(movavg,"",colorBlue,1); 
  Plot(C,"",1,64); 

  PlotShapes(Buy*shapeUpArrow,colorGreen,0,L,-20); 
  PlotShapes(Sell* shapeDownArrow,colorRed,0,H,-20); 

  Title="cumulative value = "+WriteVal(Cumcst,1.3);