Move stop to next candle's high (short) or low (long)
Created at 04 Nov 2015, 13:50
CT
Move stop to next candle's high (short) or low (long)
04 Nov 2015, 13:50
Could anyone give me a hand on how could I possibly move the stop to the next candle's high (when going short) or low (when going long)?
Thank you
Replies
ctid205024
04 Nov 2015, 23:31
RE: RE:
Very good mate, thanks heaps!!
mindbreaker said:
//Accessing historical O-H-L-C prices from Robots // prev bar int index = MarketSeries.Close.Count-2; double high = MarketSeries.High[index]; double low = MarketSeries.Low[index];with trailing
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class oodboo : Robot { [Parameter(DefaultValue = 50, MinValue = 0)] public int TrailingStop { get; set; } protected override void OnStart() { Print("Open position !!!"); } protected override void OnTick() { //===================================================== Trailing if (TrailingStop > 0) { foreach (var openedPosition in Positions) { Position Position = openedPosition; if (Position.TradeType == TradeType.Buy) { //double distance = Symbol.Bid - Position.EntryPrice; //if (distance >= TrailingStop * Symbol.PipSize) //{ double newStopLossPrice = Math.Round(Symbol.Bid - TrailingStop * Symbol.PipSize, Symbol.Digits); if (Position.StopLoss == null || newStopLossPrice > Position.StopLoss) { ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); } //} } else { //double distance = Position.EntryPrice - Symbol.Ask; //if (distance >= TrailingStop * Symbol.PipSize) //{ double newStopLossPrice = Math.Round(Symbol.Ask + TrailingStop * Symbol.PipSize, Symbol.Digits); if (Position.StopLoss == null || newStopLossPrice < Position.StopLoss) { ModifyPosition(Position, newStopLossPrice, Position.TakeProfit); } //} } } } } protected override void OnStop() { Print("cBot was stoped."); } } }
@ctid205024
mindbreaker
04 Nov 2015, 14:02
RE:
with trailing
@mindbreaker