Well, I'm glad no one replied to my first post because I was on the wrong track. I was looking for:
(a) a way to set a stoploss at the previous candle's Low for a buy trade, and the previous candle's High for a sell trade; and
(b) a way to set a stoploss at BEpipBuffer +/- entry price only if price hits BETpipBuffer +/- entry price.
From my understanding of Molanis code, AutoAdjustSLTP is only suitable for use if there is a preexisting stoploss in place. So I looked under ExecuteOrderinTwo, and came up with the following code modifications. I posted another thread on how to get the lastOrderPrice. Obviously, all variables are declared up top and defined under start. Molanis' PipMultiplier and Point are used to multiply my extern int's into useable numbers as BEpipBuffer and BETpipBuffer. It compiled without errors, and I'm about to test it.
Just look for the hatchet marks /////////// and you will know where I chopped up the code. Hopefully this helps someone, somewhere.
Code:
if (golong_bn) {
price_bn = NormalizeDouble(MarketInfo(symbol_bn,MODE_ASK),digits_bn);
// UsePrevHighLowSL for buy trades--Created by User ///////////////////////////////////////////////
if (( UsePrevHighLowSL ) // if UsePrevHighLowSL is true
&& ( stoploss_bn == 0 )) { // and initial stop loss is set to zero
stoploss_bn = NormalizeDouble(prevLow, digits_bn); // set sl at previous price bar Low
Print("M-Stop loss set at previous Low. ","SL= ",stoploss_bn,"."); }
///////////////////////////////////////////////////////////////////////////////////////////////////
// UseBreakEvenSL for buy trades--Created by User /////////////////////////////////////////////////
if (( UseBreakEvenSL ) // if UseBreakEvenSL is true
&& ( stoploss_bn == 0 ) // and intial stoploss is set to zero
&& ( currPrice >= BETpipBuffer + currPrice )) { // and price hits BreakEvenTrigger
stoploss_bn = NormalizeDouble(BEpipBuffer + lastOrderPrice, digits_bn); // set sl at BreakEvenSL
Print("M-Stop loss set at BreakEven. ","SL= ",stoploss_bn,"."); }
///////////////////////////////////////////////////////////////////////////////////////////////////
if (stoploss_bn > 0) {
stoploss_bn = NormalizeDouble(price_bn-stoploss_bn*points_bn, digits_bn);
stoploss_bn = CheckStopLoss(symbol_bn, price_bn, stoploss_bn);
}
if (takeprofit_bn>0) {
takeprofit_bn= NormalizeDouble(price_bn+takeprofit_bn*points_bn, digits_bn);
takeprofit_bn = CheckTakeProfit(symbol_bn, price_bn, takeprofit_bn);
}
} else { // go short set up
price_bn = NormalizeDouble(MarketInfo(symbol_bn,MODE_BID),digits_bn);
// UsePrevHighLowSL for sell trades--Created by User //////////////////////////////////////////////
if (( UsePrevHighLowSL ) // if UsePrevHighLowSL is true
&& ( stoploss_bn == 0 )) { // and initial stop loss is set to zero
stoploss_bn = NormalizeDouble(prevHigh, digits_bn); // adjust sl to previous price bar High
Print("M-Stop loss set at previous High. ","SL= ",stoploss_bn,"."); }
// UseBreakEvenSL for sell trades--Created by User /////////////////////////////////////////////////
if (( UseBreakEvenSL ) // if UseBreakEvenSL is true
&& ( stoploss_bn == 0 ) // and intial stoploss is set to zero
&& ( currPrice <= BETpipBuffer - currPrice )) { // and price hits BreakEvenTrigger
stoploss_bn = NormalizeDouble(BEpipBuffer - lastOrderPrice, digits_bn); // set sl at BreakEvenSL
Print("M-Stop loss set at BreakEven. ","SL= ",stoploss_bn,"."); }
///////////////////////////////////////////////////////////////////////////////////////////////////
if (stoploss_bn > 0) {
stoploss_bn = NormalizeDouble(price_bn+stoploss_bn*points_bn, digits_bn);
stoploss_bn = CheckStopLoss(symbol_bn, price_bn, stoploss_bn);
}
if (takeprofit_bn>0) {
takeprofit_bn= NormalizeDouble(price_bn-takeprofit_bn*points_bn, digits_bn);
takeprofit_bn = CheckTakeProfit(symbol_bn, price_bn, takeprofit_bn);
}