﻿CREATE PROCEDURE [GetProbabilityOfWinning]
@UserId bigint

AS
declare @total int
DECLARE @win int 
DECLARE @res int 

	Set @total = 	(SELECT Count(*)
  FROM [Signals] Where CreatorUserId = 7
  AND  DATEADD(dd,Duration, CreateDate) <= GETUTCDATE()
   OR [EntryPriceTouched] = 1 
   Or [StopLossTouched] = 1
   OR [ExitPriceTouched]=1)

   Set @win = 	(SELECT Count(*)
  FROM [Signals] Where CreatorUserId = @UserId 
   AND  [EntryPriceTouched] = 1 
   OR [ExitPriceTouched]=1)
  
  if(@total > 0)
  
 
SET	@res = @win/@total
else
SET	@res =0

return  @res
