﻿CREATE PROCEDURE [dbo].[KST_GetKnoks]
	@KnokId				 bigint = null,
	@ActiveOnly			 bit = 0,
	@GreaterThanSignalId bigint = null
AS
SELECT KnokId  
      ,[Currency1]
      ,[Currency2]
      ,[Currency]
      ,[ExchangeId]
      ,[TickerId]
      ,[CreatorUserId]
      ,[EntryPriceFrom]
      ,[EntryPriceTo]
      ,ExitPriceFrom
      ,ExitPriceTo
      ,[StopLoss]
      ,[HasTechnical]
      ,[Technical_Header]
      ,[Technical_Description]
      ,[Technical_References]
      ,[Technical_Image_Url]
      ,[Technical_Image_FileName]
      ,[HasFundamental]
      ,[Fundamental_Header]
      ,[Fundamental_Description]
      ,[Fundamental_References]
      ,[CreateDate]
      ,[PublishedDate]
      ,[Duration]
      ,[PotentialProfitValue]
      ,[PotentialProfit]
      ,[KnokStatusId]
    
      ,[SellFinishDate]
      ,[DistanceFromTarget]
      ,[Price]
      ,[EntryPriceTouched]
	  ,[ExitPriceTouched]
	  ,[StopLossTouched]
      ,[Ranks]
	  ,[HighRate]
	  ,[LowRate]
  FROM [dbo].[Signals]
  WHERE KnokId = ISNULL(@KnokId, KnokId)
  AND (@ActiveOnly = 0 OR [KnokStatusId] < 5) --not resolved
  AND (@GreaterThanSignalId IS NULL OR KnokId > @GreaterThanSignalId)
