This lesson builds a complete long-only moving-average crossover from the Data node to the Trade entry node, with a stop from ATR and a target at twice the risk. The aim is to learn the pattern, not to suggest the strategy is profitable.
The idea in words
Enter a long trade on the candle where a fast moving average crosses above a slow one. Place the stop 1.5 ATR below the entry and the target at twice the distance to the stop. The numbers used below, 20 and 50, are examples, not recommendations. Nodes can be placed anywhere in the editor, so build it from left to right.
Step 1: the averages and the state
- Add a
Datanode. Add twoSMAnodes and setPeriod (N)to 20 on one (the fast average) and 50 on the other (the slow average). - Connect
Data.Closeto theDatainput of bothSMAnodes. - Add a
GreaterThannode. Connect the fastSMAoutput toAand the slowSMAoutput toB. ItsResultis true on every candle where the fast average is above the slow one.
Step 2: only on the crossing candle
The state alone is not enough. If the Trade entry trigger were connected here, it would be true on every candle while the fast average stays above the slow one, which can be dozens of candles in a row. You want to enter once, on the candle where the state changes from false to true.
A crossing means that the fast average is above the slow one now and was not above it one candle ago. PreviousValue takes a number and returns the value from one candle earlier, so apply it to each average, not to the boolean.
- Add two
PreviousValuenodes. Connect the fastSMAto one and the slowSMAto the other. TheirPreviousoutputs are last candle's averages. - Add a second
GreaterThannode with the previous fast value onAand the previous slow value onB. ItsResultsays whether the fast average was above the slow one on the previous candle. - Add a
Notnode and connect that secondResultto its inputA. It is true when the fast average was not above the slow one one candle ago. - Add an
Andnode. Connect the firstGreaterThanResult(the state now) toAand theNotResulttoB.
Worked example
Why the trigger fires once
- Suppose the fast-above-slow state over seven candles is: false, false, true, true, true, false, true.
- The previous-candle state is the same list shifted by one: (none), false, false, true, true, true, false.
- The trigger is the state now
AndNotprevious state, which is true only where the state is true and the previous state was false. - That is candle 3 (true after false) and candle 7 (true after false). Candles 4 and 5 are true but follow a true, so
Notmakes them false.
Without the previous-candle check the trigger would be true on 4 candles (3, 4, 5 and 7); with it, only on 2 (3 and 7), one per crossing.
Step 3: the entry and a stop from ATR
- Add a
Trade entrynode, set the direction to buy and the entry price type toMarket. Connect theAndResulttoTrigger. - Add an
ATRnode (for example a period of 14) and connectData.High,Data.LowandData.Closeto itsHigh,LowandCloseinputs. - Add a
Multiplynode with theATRoutput onAand a number constant of 1.5 onB. That is the stop distance. - Add a
Subtractnode withData.CloseonAand theMultiplyResultonB, then connect itsResulttoSL1. The stop is the close minus 1.5 ATR.
Step 4: a target at 2R
A target at 2R is twice as far from the entry as the stop is. The graph needs the risk, which is the entry minus the stop, then twice that, added to the entry. Here Data.Close stands in for the entry price.
Risk = Entry − Stop
Target = Entry + 2 × RiskSubtract, Multiply (by 2) and Add, ending in TP1.Worked example
The numbers on the crossing candle
- On the crossing candle the close is 100.30 and the ATR is 2.00.
- Stop distance: 1.5 × 2.00 = 3.00, so the stop is 100.30 − 3.00 = 97.30.
- Risk: 100.30 − 97.30 = 3.00. Twice the risk is 2 × 3.00 = 6.00.
- Target: 100.30 + 6.00 = 106.30. Reward to risk is 6.00 / 3.00 = 2.
Entry 100.30, stop 97.30, target 106.30: risking 3.00 per unit to aim for 6.00 per unit.
Connect the final Add Result to TP1. Connect Data.Close to Entry Price too, so the graph and your calculation use the same reference. With the Market type the actual fill can differ from the close, so compare the entry prices in the replay with what you expected.
Key takeaways
- A comparison of two averages is a state; adding a
PreviousValuecheck withNotandAndturns it into a one-candle crossing event. PreviousValuetakes numbers, so apply it to eachSMAoutput and compare the earlier values in a secondGreaterThan.- An ATR stop is
Subtractof close and ATR × 1.5, fed intoSL1. - A 2R target is entry + 2 × (entry − stop), built from
Subtract,MultiplyandAdd, fed intoTP1.