Signals
HaasScript uses signals to indicate when to execute certain actions such as buying, selling, exiting a position, or doing nothing. Signals are represented as an enumerator in HaasScript, and are used in combination with conditional statements to execute trades.
Here are the signals available in HaasScript:
SignalBuy
orSignalLong
: Indicates a signal to buy or go long on a position.SignalSell
orSignalShort
: Indicates a signal to sell or go short on a position.SignalExitLong
: Indicates a signal to exit a long position.SignalExitShort
: Indicates a signal to exit a short position.SignalExitPosition
: Indicates a signal to exit any position, regardless of whether it is a bought, sold, long or short position.SignalNone
: Indicates a signal for “do nothing”.SignalError
: Indicates a signal error.SignalReservedA
: A reserved signal used in remote signals.SignalReservedB
: A reserved signal used in remote signals.
To use signals in HaasScript, you can trigger a trade directly using DoSignal
or create a conditional statement that checks for the signal value and execute the corresponding action. For example:
-------------------
-- Direct action
DoSignal( signal )
-------------------
-- Advanced actions
if signal == SignalBuy then
-- Execute buy action
elseif signal == SignalSell then
-- Execute sell action
elseif signal == SignalExitPosition then
-- Execute exit position action
elseif signal == SignalNone then
-- Do nothing
else
-- Handle signal error
end
You can also directly input the signal(s) to certain commands, such as GetUnanimousSignal
, GetConsensusSignal
and GetWeightedConsensusSignal
. For example:
signal1 = SignalLong
signal2 = SignalLong
signal3 = SignalShort
unanimousSignal = GetUnanimousSignal(signal1, signal2, signal3)
consensusSignal = GetConsensusSignal(signal1, signal2, signal3)
Log(unanimousSignal) -- output: SignalNone
Log(consensusSignal) -- output: SignalLong
Signals can be used in combination with other indicators or strategies to create more complex trading algorithms. Understanding how to use signals effectively is a key aspect of trading with HaasScript.