Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module MkUniRenkoTargets
- (*
- There are 6 possible ways a UniRenko bar can close:
- 1. for 1st bar of session, only: upTrd or dnTrd target is met
- 2. if currently in a downTrend, a dnTrd target is met
- 3. if currently in a upTrend, an upTrd target is met
- 4. if currently in a upTrend, a dnRev target is met
- 5. if currently in a downTrend, an upRev target is met
- 6. the session ends
- *)
- let priceTargets uOpen (tickValue : float) (trendParm : int)
- (reversalParm : int) =
- // compute all price targets based on clParams
- let dnTrdTarget = uOpen - (tickValue * float trendParm)
- let upTrdTarget = uOpen + (tickValue * float trendParm)
- let dnRevTarget = uOpen - (tickValue * float reversalParm)
- let upRevTarget = uOpen + (tickValue * float reversalParm)
- (dnTrdTarget, upTrdTarget, dnRevTarget, upRevTarget)
- // ========================================================
- // active patterns for determining whether bar is complete
- // ========================================================
- let (|DnTrdTarget|_|) (priceTargets, price, direction, lastFlag : string) =
- let dnTrdTarget, _, _, _ = priceTargets
- if (price = dnTrdTarget && direction <> "U") then Some()
- else None
- let (|UpTrdTarget|_|) (priceTargets, price, direction, lastFlag : string) =
- let _, upTrdTarget, _, _ = priceTargets
- if (price = upTrdTarget && direction <> "D") then Some()
- else None
- let (|DnRevTarget|_|) (priceTargets, price, direction, lastFlag : string) =
- let _, _, dnRevTarget, _ = priceTargets
- if (price = dnRevTarget && direction = "U") then Some()
- else None
- let (|UpRevTarget|_|) (priceTargets, price, direction, lastFlag : string) =
- let _, _, _, upRevTarget = priceTargets
- if (price = upRevTarget && direction = "D") then Some()
- else None
- let (|LastRow|_|) (_priceTargets, _price, _direction, lastFlag : string) =
- if (lastFlag = "L") then Some()
- else None
- //===================================================
- // Entire logic for handling bar close, using the active patterns
- let isBarComplete priceTargets price tickVal openBar openParm lastFlag =
- match (priceTargets, price, openBar.direction, lastFlag) with
- | DnTrdTarget -> complete price tickVal openBar openParm "D" lastFlag
- | UpTrdTarget -> complete price tickVal openBar openParm "U" lastFlag
- | DnRevTarget -> complete price tickVal openBar openParm "D" lastFlag
- | UpRevTarget -> complete price tickVal openBar openParm "U" lastFlag
- | LastRow -> complete price tickVal openBar openParm "U" lastFlag
- | _ -> incomplete price tickVal openBar "_" lastFlag
Add Comment
Please, Sign In to add comment