Is it possible to have the Fibonacci Lines be an indicator? Aka when close crosses above the lower Fibonacci line I can buy and sell when it crosses the middle line?
Rename
Fibonacci lines have to be based on anchor points. I guess the anchor points could be determined algorithmically, but it isn't something that lends itself to an Indicator.
The best expression for this, I feel, is a C# Coded Strategy where you can determine your anchor points, calculate the retracements, and place the trades accordingly.
The best expression for this, I feel, is a C# Coded Strategy where you can determine your anchor points, calculate the retracements, and place the trades accordingly.
Here's a quick demo based on some legacy code by @Cone:
CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript6 { public class DivergenceExample2 : UserStrategyBase { PeakTroughCalculator _ptc; double[] levels = { 0.382, 0.5, 0.618 }; //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) { _ptc = new PeakTroughCalculator(bars, 5.0, PeakTroughReversalTypes.Percent); PlotStopsAndLimits(2); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { PeakTrough pk = _ptc.GetPeak(idx); if (pk == null) return; PeakTrough prevT = _ptc.GetPrevTrough(pk); if (prevT == null) return; int b1 = pk.PeakTroughIndex, b2 = prevT.PeakTroughIndex; double p1 = bars.High[b1]; DrawLine(b1, pk.Value, b2, prevT.Value, Color.Blue, 2); //Fibonacci Retracements double dec = b1 - b2; for (int n = 0; n < levels.Length; n++) { double ret = p1 - dec * levels[n]; int endBar = b1 +10 > idx ? idx : b1 +10; DrawLine(b1, ret, endBar, ret, Color.Blue, 2, LineStyles.Dotted); if (bars.Close[idx] > ret) PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, ret, levels[n].ToString("0.0##")); } } else { Position p = LastPosition; double tgt = p.EntryPrice * 1.10; //10% gain double stop = p.EntryPrice * 0.95; //-5% stop PlaceTrade(bars, TransactionType.Sell, OrderType.Stop, stop); PlaceTrade(bars, TransactionType.Sell, OrderType.Limit, tgt); } } } }
Your Response
Post
Edit Post
Login is required