diff --git a/src/propeller/push/instructions/numeric.cljc b/src/propeller/push/instructions/numeric.cljc index 847b013..c6e4a45 100755 --- a/src/propeller/push/instructions/numeric.cljc +++ b/src/propeller/push/instructions/numeric.cljc @@ -533,6 +533,14 @@ Otherwise, acts as a NOOP" (fn [stack state] (make-instruction state dec [stack] stack))) +;; Pushes the square of the top item of the stack +(def _square + "Pushes the square of the top item of the stack" + ^{:stacks #{} + :name "_square"} + (fn [stack state] + (make-instruction state #(* % %) [stack] stack))) + (generate-instructions [:float :integer] [_gt _gte _lt _lte _add _subtract _mult _quot _mod _max _min _inc _dec @@ -541,7 +549,8 @@ Otherwise, acts as a NOOP" _gt_buy_sell _gt_buy_hold _gt_sell_buy _gt_sell_hold _gt_hold_buy _gt_hold_sell _gte_buy_sell _gte_buy_hold _gte_sell_buy _gte_sell_hold _gte_hold_buy _gte_hold_sell _lt_buy_sell _lt_buy_hold _lt_sell_buy _lt_sell_hold _lt_hold_buy _lt_hold_sell - _lte_buy_sell _lte_buy_hold _lte_sell_buy _lte_sell_hold _lte_hold_buy _lte_hold_sell]) + _lte_buy_sell _lte_buy_hold _lte_sell_buy _lte_sell_hold _lte_hold_buy _lte_hold_sell + _square]) ;; ============================================================================= ;; FLOAT Instructions only @@ -579,24 +588,17 @@ Otherwise, acts as a NOOP" ;; Pushes the square root of the top FLOAT. Makes the value ;; absolute first. (def-instruction - :float_tan + :float_sqrt ^{:stacks #{:float}} (fn [state] - (make-instruction state #(math/sqrt (abs %)) [:float] :float))) + (make-instruction state #(math/sqrt (math/abs %)) [:float] :float))) -;; Pushes the log of the top FLOAT +;; Pushes the natural log of the top FLOAT (def-instruction - :float_tan + :float_log ^{:stacks #{:float}} (fn [state] - (make-instruction state #(if (zero? %) 1 (math/log (abs %))) [:float] :float))) - -;; Pushes the square of the top FLOAT -(def-instruction - :float_tan - ^{:stacks #{:float}} - (fn [state] - (make-instruction state #(* % %) [:float] :float))) + (make-instruction state #(if (zero? %) 1 (math/log (math/abs %))) [:float] :float))) ;; Pushes the floating point version of the top INTEGER (def-instruction diff --git a/src/propeller/push/instructions/signal.cljc b/src/propeller/push/instructions/signal.cljc index 95ea7d1..03458e5 100644 --- a/src/propeller/push/instructions/signal.cljc +++ b/src/propeller/push/instructions/signal.cljc @@ -6,3 +6,44 @@ generate-instructions make-instruction]])) +;; Changes the top signal from :buy to :sell if applicable +(def-instruction + :signal_swap_buy_sell + ^{:stacks #{:signal}} + (fn [state] + (make-instruction state #(if (= :buy %) :sell :buy) [:signal] :signal))) + +;; Changes the top signal from :buy to :hold if applicable +(def-instruction + :signal_swap_buy_hold + ^{:stacks #{:signal}} + (fn [state] + (make-instruction state #(if (= :buy %) :hold :buy) [:signal] :signal))) + +;; Changes the top signal from :sell to :buy if applicable +(def-instruction + :signal_swap_sell_buy + ^{:stacks #{:signal}} + (fn [state] + (make-instruction state #(if (= :sell %) :buy :sell) [:signal] :signal))) + +;; Changes the top signal from :sell to :hold if applicable +(def-instruction + :signal_swap_sell_hold + ^{:stacks #{:signal}} + (fn [state] + (make-instruction state #(if (= :sell %) :hold :sell) [:signal] :signal))) + +;; Changes the top signal from :hold to :buy if applicable +(def-instruction + :signal_swap_hold_buy + ^{:stacks #{:signal}} + (fn [state] + (make-instruction state #(if (= :hold %) :buy :hold) [:signal] :signal))) + +;; Changes the top signal from :hold to :sell if applicable +(def-instruction + :signal_swap_hold_sell + ^{:stacks #{:signal}} + (fn [state] + (make-instruction state #(if (= :hold %) :sell :hold) [:signal] :signal))) \ No newline at end of file