How would I add a lots exponent (multiplier) to this ''3 bars'' algorithm
Created at 15 Aug 2019, 16:38
How would I add a lots exponent (multiplier) to this ''3 bars'' algorithm
15 Aug 2019, 16:38
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Robots { [Robot()] public class TreeBarsTraDerMaTriX : Robot { [Parameter("3 BARS TraDerMaTriX n°", DefaultValue = "3")] public string InstanceName { get; set; } [Parameter("Volume", DefaultValue = 10000)] public double volume { get; set; } [Parameter("SL", DefaultValue = 270)] public int SL { get; set; } [Parameter("TP", DefaultValue = 280)] public int TP { get; set; } [Parameter("Use Trail", DefaultValue = true)] public bool UseTrail { get; set; } [Parameter("Trigger (pips)", DefaultValue = 15)] public int TrailingStopTrigger { get; set; } [Parameter("Trailing (pips)", DefaultValue = 6)] public int TrailingStopStep { get; set; } protected override void OnStart() { } protected override void OnTick() { TRAIL(); } protected override void OnBar() { play(); } private void play() { int bars = MarketSeries.Close.Count - 1; int[] b_or_m = new int[3]; Print("{0},{1},{2},{3},{4}", MarketSeries.High[bars - 1], MarketSeries.High[bars - 2], MarketSeries.High[bars - 3], MarketSeries.Close.Count, MarketSeries.High[1]); if (MarketSeries.Close[bars - 1] > MarketSeries.Open[bars - 1]) b_or_m[0] = 1; else b_or_m[0] = 2; if (MarketSeries.Close[bars - 2] > MarketSeries.Open[bars - 2]) b_or_m[1] = 1; else b_or_m[1] = 2; if (MarketSeries.Close[bars - 3] > MarketSeries.Open[bars - 3]) b_or_m[2] = 1; else b_or_m[2] = 2; Print("{0},{1},{2}", b_or_m[0], b_or_m[1], b_or_m[2]); var cBotPositions = Positions.FindAll(InstanceName); if (cBotPositions.Length >= 1) return; if ((b_or_m[0] == 1) && (b_or_m[1] == 1) && (b_or_m[2] == 1)) { ExecuteMarketOrder(TradeType.Buy, SymbolName, volume, InstanceName, SL, TP); } else if ((b_or_m[0] == 2) && (b_or_m[1] == 2) && (b_or_m[2] == 2)) { ExecuteMarketOrder(TradeType.Sell, SymbolName, volume, InstanceName, SL, TP); } } protected override void OnError(Error error) { Print("Errot={0}", error.Code); } protected override void OnStop() { Print("Robot 3BARS by TraDerMaTriX stopped by user"); } private void TRAIL() { if (UseTrail) { var sellPositions = Positions.FindAll(InstanceName, SymbolName, TradeType.Sell); foreach (Position position in sellPositions) { double distance = position.EntryPrice - Symbol.Ask; if (distance < TrailingStopTrigger * Symbol.PipSize) continue; double newStopLossPrice = Symbol.Ask + TrailingStopStep * Symbol.PipSize; if (position.StopLoss == null || newStopLossPrice < position.StopLoss) { ModifyPosition(position, newStopLossPrice, position.TakeProfit); } } var buyPositions = Positions.FindAll(InstanceName, SymbolName, TradeType.Buy); foreach (Position position in buyPositions) { double distance = Symbol.Bid - position.EntryPrice; if (distance < TrailingStopTrigger * Symbol.PipSize) continue; double newStopLossPrice = Symbol.Bid - TrailingStopStep * Symbol.PipSize; if (position.StopLoss == null || newStopLossPrice > position.StopLoss) { ModifyPosition(position, newStopLossPrice, position.TakeProfit); } } } } } }
PanagiotisCharalampous
26 Aug 2019, 09:59
Hi lukaszfx,
It is not clear where do you want to add the exponent. Can you please explain what do you mean?
Best Regards,
Panagiotis
@PanagiotisCharalampous