Break Even Isn't Working!
Break Even Isn't Working!
27 Mar 2017, 10:55
I tried everything I could think of before coming here, however.. the Break Even code below still isn't working in either a back test or with a demo account.
I've tried a range of examples from other source codes including the one from the sample Spotware provided.. but none seem to work. As far as I can tell, it should be.
Essentially and be clear.. what I wanted it to do was, once the pending order that was previously created was hit and turned into a position, then, wait for symbol price in pips to hit the target trigger in pips and then modify that position with an updated stop loss.
I don't normally ask for help and would appreciate any that anyone can spare.
--Thank you.
//Break Even Settings [Parameter("Move SL To Break Even", DefaultValue = true)] public bool MoveToBreakEven { get; set; } [Parameter("Trigger when gaining:", DefaultValue = 5, MinValue = 0, Step = 0.25)] public double BETriggerWhenGaining { get; set; } [Parameter("Additional pips to move SL:", DefaultValue = 0.75, MinValue = 0, Step = 0.25)] public double AdditionalAfterBE { get; set; } protected override void OnTick() { { StopLossOnBreakEven(); } } private void StopLossOnBreakEven() //Set Stop Loss To Break Even + Desired Pips If Entry Price + Pips Is Hit { foreach (var LongPosition in Positions.FindAll(OpenLong, Symbol, TradeType.Buy)) foreach (var ShortPosition in Positions.FindAll(OpenShort, Symbol, TradeType.Sell)) { if (LongPosition != null) { double BEStopLossLong = (LongPosition.EntryPrice + (Symbol.PipSize * AdditionalAfterBE)); double BETakeProfitLong = (LongPosition.EntryPrice + (Symbol.PipSize * TakeProfitAllPips)); { if (MoveToBreakEven == true & LongPosition.TradeType == TradeType.Buy & ((LongPosition.EntryPrice + LongPosition.Pips) >= ((LongPosition.EntryPrice) + (Symbol.PipSize * BETriggerWhenGaining)))) ModifyPosition(LongPosition, BEStopLossLong, BETakeProfitLong); } } else if (ShortPosition != null) { double BEStopLossShort = (ShortPosition.EntryPrice - (Symbol.PipSize * AdditionalAfterBE)); double BETakeProfitShort = (ShortPosition.EntryPrice - (Symbol.PipSize * TakeProfitAllPips)); { if (MoveToBreakEven == true & ShortPosition.TradeType == TradeType.Sell & ((ShortPosition.EntryPrice + ShortPosition.Pips) <= ((ShortPosition.EntryPrice) - (Symbol.PipSize * BETriggerWhenGaining)))) ModifyPosition(ShortPosition, BEStopLossShort, BETakeProfitShort); } } } }
201058436
28 Mar 2017, 11:30
RE:
AthenasGuidance said:
@201058436