示例#1
0
        public NBarFade(QREBridgeBase bridge, Symbol symbol) : base(bridge, symbol)
        {
            atrLen         = parameter <int>("ATRLen");
            nDays          = parameter <int>("nDays");
            nATREntry      = parameter <double>("nATRentry");
            stopAfStep     = parameter <double>("stopAfStep");
            stopAfMax      = parameter <double>("stopAfMax");
            entryBarWindow = parameter <double>("entryBarWindow");
            closeBetter    = parameter <bool>("closeBetter");
            riskDollars    = parameter <double>("riskDollars");

            atr           = new AverageTrueRangeEW(bars, atrLen); // this should be a daily spud
            nATRStopStart = nATREntry * parameter <double>("exitATRmultiple");

            entryHighestHigh = bars.high.highest(nDays);
            entryLowestLow   = bars.low.lowest(nDays);
            var halfNDays = (int)Math.Round(nDays * 0.5, 0);

            exitHighestHigh = bars.high.highest(halfNDays);
            exitLowestLow   = bars.low.lowest(halfNDays);

            inConfirm = false;

            //Plot methods
            parabolicStop = null;
            stopIndicator = new RootSpud <double>(bars.manager);
            addToPlot(stopIndicator, "ParabolicStop", Color.Red);
            addToPlot(entryHighestHigh, "entryHighestHigh", Color.LightBlue);
            addToPlot(entryLowestLow, "entryLowestLow", Color.Blue);
            addToPlot(exitHighestHigh, "exitHighestHigh", Color.Pink);
            addToPlot(exitLowestLow, "exitLowestLow", Color.Salmon);
            addToPlot(bars.close, "price", Color.Purple);
            addToPlot(atr, "ATR", Color.Blue, "ATRPane");
        }
示例#2
0
        protected override void onNewBar()
        {
            //Remove this code later
            if (parabolicStop != null)
            {
                if (parabolicStop.positionClosed())
                {
                    parabolicStop = null;
                }
                else
                {
                    stopIndicator.set(parabolicStop);
                }
            }
            if (parabolicStop == null)
            {
                stopIndicator.set(bars[0].close);
            }
            //*****************************************************************

            //Setup from prior bar, now in confirm
            if (inConfirm)
            {
                confirmBarCount++;
                if (confirmBarCount <= entryBarWindow)
                {
                    placeEntryOrders();
                }
                else
                {
                    inConfirm = false;
                }
            }
            if (inConfirm)
            {
                return;
            }

            //Not in confirm from prior bar, so check for setup
            setup = tradeSetup();
            if (!hasPosition() && (setup != null))
            {
                tradeSize       = (long)Math.Max(Math.Round(riskDollars / ((nATRStopStart * atr) * bigPointValue()), 0), 1);
                atrAtEntry      = atr;
                longEntryPrice  = entryLowestLow[1] + atr * nATREntry;
                shortEntryPrice = entryHighestHigh[1] - atr * nATREntry;
                placeEntryOrders();
                inConfirm       = true;
                confirmBarCount = 1;
            }

            //Currently in position, submit exit orders
            if (hasPosition())
            {
                placeExitOrders();
            }
        }
示例#3
0
 protected override void onFilled(Position position, Trade trade)
 {
     if (position.isEntry(trade))
     {
         //Only place the stop on the fill, the objective exit gets placed at close of bar
         var initialStopPrice = trade.price - (position.direction() * atrAtEntry * nATRStopStart);
         parabolicStop = new ParabolicStop(position, bars, initialStopPrice, stopAfStep, stopAfMax, LOOKBACK_BARS, "Parabolic Stop");
         addDynamicExit(parabolicStop, false);
     }
     inConfirm = false;
 }