01-wait-after-crossWait after cross
Arm on EMA cross-down, wait N bars, then buy (classic stateful customLogic).
{
"enabled": true,
"invert": false,
"params": {
"version": 1,
"summary": "- Setup when close crosses below EMA(20)\n- Wait 4 closed candles while still below the EMA\n- Buy on the next bar if still watching\n- Cancel if price reclaims the EMA before buy",
"vars": {
"ma": {
"fn": "ema",
"args": [
{
"series": "close"
},
{
"const": 20
}
]
}
},
"state": {
"armed": {
"type": "bool",
"default": false
},
"barsWaited": {
"type": "int",
"default": 0
}
},
"onBar": [
{
"if": {
"fn": "and",
"args": [
{
"state": "armed"
},
{
"fn": "gt",
"args": [
{
"series": "close"
},
{
"var": "ma"
}
]
}
]
},
"then": [
{
"set": "armed",
"value": {
"const": false
}
},
{
"set": "barsWaited",
"value": {
"const": 0
}
}
]
},
{
"if": {
"fn": "and",
"args": [
{
"fn": "not",
"args": [
{
"state": "armed"
}
]
},
{
"fn": "crossDown",
"args": [
{
"series": "close"
},
{
"var": "ma"
}
]
}
]
},
"then": [
{
"set": "armed",
"value": {
"const": true
}
},
{
"set": "barsWaited",
"value": {
"const": 0
}
}
]
},
{
"if": {
"state": "armed"
},
"then": [
{
"if": {
"fn": "gte",
"args": [
{
"state": "barsWaited"
},
{
"const": 4
}
]
},
"then": [
{
"emit": "buy"
},
{
"set": "armed",
"value": {
"const": false
}
},
{
"set": "barsWaited",
"value": {
"const": 0
}
}
],
"else": [
{
"set": "barsWaited",
"value": {
"fn": "add",
"args": [
{
"state": "barsWaited"
},
{
"const": 1
}
]
}
}
]
}
]
}
]
}
}