Guest User

Untitled

a guest
Jan 15th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. module MkUniRenkoTargets
  2. (*
  3. There are 6 possible ways a UniRenko bar can close:
  4. 1. for 1st bar of session, only: upTrd or dnTrd target is met
  5. 2. if currently in a downTrend, a dnTrd target is met
  6. 3. if currently in a upTrend, an upTrd target is met
  7. 4. if currently in a upTrend, a dnRev target is met
  8. 5. if currently in a downTrend, an upRev target is met
  9. 6. the session ends
  10. *)
  11. let priceTargets uOpen (tickValue : float) (trendParm : int)
  12. (reversalParm : int) =
  13. // compute all price targets based on clParams
  14. let dnTrdTarget = uOpen - (tickValue * float trendParm)
  15. let upTrdTarget = uOpen + (tickValue * float trendParm)
  16. let dnRevTarget = uOpen - (tickValue * float reversalParm)
  17. let upRevTarget = uOpen + (tickValue * float reversalParm)
  18. (dnTrdTarget, upTrdTarget, dnRevTarget, upRevTarget)
  19.  
  20. // ========================================================
  21. // active patterns for determining whether bar is complete
  22. // ========================================================
  23. let (|DnTrdTarget|_|) (priceTargets, price, direction, lastFlag : string) =
  24. let dnTrdTarget, _, _, _ = priceTargets
  25. if (price = dnTrdTarget && direction <> "U") then Some()
  26. else None
  27.  
  28. let (|UpTrdTarget|_|) (priceTargets, price, direction, lastFlag : string) =
  29. let _, upTrdTarget, _, _ = priceTargets
  30. if (price = upTrdTarget && direction <> "D") then Some()
  31. else None
  32.  
  33. let (|DnRevTarget|_|) (priceTargets, price, direction, lastFlag : string) =
  34. let _, _, dnRevTarget, _ = priceTargets
  35. if (price = dnRevTarget && direction = "U") then Some()
  36. else None
  37.  
  38. let (|UpRevTarget|_|) (priceTargets, price, direction, lastFlag : string) =
  39. let _, _, _, upRevTarget = priceTargets
  40. if (price = upRevTarget && direction = "D") then Some()
  41. else None
  42.  
  43. let (|LastRow|_|) (_priceTargets, _price, _direction, lastFlag : string) =
  44. if (lastFlag = "L") then Some()
  45. else None
  46. //===================================================
  47. // Entire logic for handling bar close, using the active patterns
  48. let isBarComplete priceTargets price tickVal openBar openParm lastFlag =
  49. match (priceTargets, price, openBar.direction, lastFlag) with
  50. | DnTrdTarget -> complete price tickVal openBar openParm "D" lastFlag
  51. | UpTrdTarget -> complete price tickVal openBar openParm "U" lastFlag
  52. | DnRevTarget -> complete price tickVal openBar openParm "D" lastFlag
  53. | UpRevTarget -> complete price tickVal openBar openParm "U" lastFlag
  54. | LastRow -> complete price tickVal openBar openParm "U" lastFlag
  55. | _ -> incomplete price tickVal openBar "_" lastFlag
Add Comment
Please, Sign In to add comment