Inquiry coding inside bar momentum strategy
Forums › ProRealTime English forum › ProOrder support › Inquiry coding inside bar momentum strategy
- This topic has 14 replies, 3 voices, and was last updated 2 years ago by robertogozzi.
-
-
08/22/2021 at 12:35 PM #175909
Hello, I have a request to code the Inside Bar Momentum strategy of baby pips. The following link contains the exact rules. Can someone code that for me, please?
https://www.babypips.com/trading/new-forex-system-inside-bar-momentum-strategy
08/22/2021 at 5:33 PM #175930There you go (not tested, though):
1234567891011121314151617181920212223242526272829303132333435363738Once EntryL = 0Once EntryS = 0Bullish = close > openBearish = close < openInside = (high <= high[1]) and (low >= low[1]) and (range < range[1])//Inside = (high < high[1]) and (low > low[1])If Inside thenEntryL = high[1] + (range * 0.1)EntryS = low[1] - (range * 0.1)slL = abs(EntryL - (high[1] - (range * 0.2)))slS = abs(EntryS - (low[1] + (range * 0.2)))tpL = abs(EntryL - (high[1] + (range * 0.8)))tpS = abs(EntryS - (low[1] - (range * 0.8)))EndifIf Not OnMarket And EntryL ThenBuy 1 contract at EntryL STOPSellshort 1 contract at EntryS STOP// initially set a unique SL & TP to// the max of the twoSet Target Profit max(tpL,tpS)Set Stop Loss max(slL,slS)Else// set real SL and TP after first bar on marketIf ShortOnMarket thenSet Target Profit tpSSet Stop Loss slSElseSet Target Profit tpLSet Stop Loss slLEndifEntryL = 0EntryS = 0// close if another INSIDE bar showsIf Inside thenSELLSHORT at MarketSELL at MarketEndifEndif1 user thanked author for this post.
08/22/2021 at 5:51 PM #175931I coded two different ways to define an INSIDE bar.
Line 5 (which I used) requires than only one among prior Low and High be greater/lower, the other one can be EQUAL.
Line 6 (commented) requires that BOTH prior High and Low be greater/lower.
You can uncomment line 6 and comment out line 5, if preferred.
1 user thanked author for this post.
08/22/2021 at 7:17 PM #175939That’s very good. Thanks! This is exactly what I imagined. Of course, when I start it in an H4 timeframe, I don’t have a TP or SL for 4 hours which can be fatal at times. Can I also use these terms as an MTF? H4 in M1? Then I would have a maximum of 1 minute in the M1 timeframe without SL and TP.
08/22/2021 at 8:54 PM #175955You HAVE a TP & SL, though it can be slightly higher and will be updated the next bar.
08/22/2021 at 10:53 PM #17596408/23/2021 at 3:51 PM #175996On the one hand, the instructions “bullish” and “bearish” must still be included in the input conditions. Nonetheless, this type of system seems to work quite well in manual trading, but not really functional as an algo. At least I haven’t gotten it profitable until now. Not even with MTF. I think range breakouts are easier to automate than individual candles. At least not with stop orders. Unless someone has another idea?
08/23/2021 at 4:47 PM #176005I usually add them, as they are no more returned as an error (like it was in v10.3). You can safely remove lines 3-4.
08/23/2021 at 5:12 PM #17600808/23/2021 at 6:35 PM #176016No, not good results.
I tried changing some lines.
Lines 10-11 to set the SL to the previous LOW/HIGH:
12slL = abs(EntryL - (low[1] - (range * 0.2)))slS = abs(EntryS - (high[1] + (range * 0.2)))Lines 12-13 to set a TP as a factor of SL:
12tpL = slL * 3//abs(EntryL - (high[1] + (range * 0.8)))tpS = slS * 3//abs(EntryS - (low[1] - (range * 0.8)))and commented out lines 35-36, so that the strategy doesn’t exit on a subsequent INSIDE bar.
Positive results (without a trailing stop) a Daily TF (200K units and 2-pip spread, I did not change it each time) are best on AudJpy, AudNzd, AudUsd, CadJpy, EurAud, EurUsd, GbpJpy, GbpUsd, Italy 40, NzdJpy and UsdChf.
1234567891011121314151617181920212223242526272829303132333435363738Once EntryL = 0Once EntryS = 0//Bullish = close > open//Bearish = close < openInside = (high <= high[1]) and (low >= low[1]) and (range < range[1])//Inside = (high < high[1]) and (low > low[1])If Inside thenEntryL = high[1] + (range * 0.1)EntryS = low[1] - (range * 0.1)slL = abs(EntryL - (low[1] - (range * 0.2)))slS = abs(EntryS - (high[1] + (range * 0.2)))tpL = slL * 3//abs(EntryL - (high[1] + (range * 0.8)))tpS = slS * 3//abs(EntryS - (low[1] - (range * 0.8)))EndifIf Not OnMarket And EntryL ThenBuy 1 contract at EntryL STOPSellshort 1 contract at EntryS STOP// initially set a unique SL & TP to// the max of the twoSet Target Profit max(tpL,tpS)Set Stop Loss max(slL,slS)Else// set real SL and TP after first bar on marketIf ShortOnMarket thenSet Target Profit tpSSet Stop Loss slSElseSet Target Profit tpLSet Stop Loss slLEndifEntryL = 0EntryS = 0// close if another INSIDE bar showsIf Inside then//SELLSHORT at Market//SELL at MarketEndifEndif08/23/2021 at 6:43 PM #176017Adding this trailing stop improved results slightly:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960//*********************************************************************************// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/// (righe 17- 56) with the addition of DISTANCE////trailing stop functionIF (BarIndex - TradeIndex) >= 0 THEN //0trailingstart = 40 //40 trailing will start @trailinstart points profittrailingstep = 10 //10 trailing step to move the "stoploss"distance = 10 //10 pips distance from caurrent price (if required by the broker)//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENIF LongOnMarket THENIF (close + distance) > newSL THENSELL AT newSL STOPELSIF (close - distance) < newSL THENSELL AT newSL LIMITELSESELL AT MarketENDIFELSIF ShortOnmarket THENIF (close + distance) < newSL THENEXITSHORT AT newSL STOPELSIF (close - distance) > newSL THENEXITSHORT AT newSL LIMITELSEEXITSHORT AT MarketENDIFENDIFENDIFENDIF//*********************************************************************************08/23/2021 at 6:51 PM #17601909/09/2021 at 11:26 AM #177129Using the code on the link below, I am getting rejected loads for being too close / less than IG minimum etc.
https://www.prorealcode.com/topic/inquiry-coding-inside-bar-momentum-strategy/#post-175930
What can I add so the code is not rejcted please?
PS
I even ticked the Guaranteed box and the IG can move stops box but it made no difference … still got rejected for beng too close to price etc
09/09/2021 at 11:58 AM #177133You have to check, each time a pending order is to be placed, whether its entry price sits within the rquired distance from the current price (CLOSE).
I have added DISTANCE, as first line, to which you want to assign the distance (in Pips) required by IG for the traded instrument/asset:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253Once Distance = 10 * PipSizeOnce EntryL = 0Once EntryS = 0Bullish = close > openBearish = close < openInside = (high <= high[1]) and (low >= low[1]) and (range < range[1])//Inside = (high < high[1]) and (low > low[1])If Inside thenEntryL = high[1] + (range * 0.1)EntryS = low[1] - (range * 0.1)slL = abs(EntryL - (high[1] - (range * 0.2)))slS = abs(EntryS - (low[1] + (range * 0.2)))tpL = abs(EntryL - (high[1] + (range * 0.8)))tpS = abs(EntryS - (low[1] - (range * 0.8)))EndifIf Not OnMarket And EntryL Then// LONG entryIF close > (EntryL + Distance) THENBuy 1 contract at EntryL LIMITELSIF close < (EntryL - Distance) THENBuy 1 contract at EntryL STOPELSEBuy 1 contract at MarketENDIF// SHORT entryIF close > (EntryS + Distance) THENSellshort 1 contract at EntryS STOPELSIF close < (EntryS - Distance) THENSellshort 1 contract at EntryS LIMITELSESellshort 1 contract at MarketENDIF// initially set a unique SL & TP to// the max of the twoSet Target Profit max(tpL,tpS)Set Stop Loss max(slL,slS)Else// set real SL and TP after first bar on marketIf ShortOnMarket thenSet Target Profit tpSSet Stop Loss slSElseSet Target Profit tpLSet Stop Loss slLEndifEntryL = 0EntryS = 0// close if another INSIDE bar showsIf Inside thenSELLSHORT at MarketSELL at MarketEndifEndif1 user thanked author for this post.
09/09/2021 at 12:01 PM #177134If you don’t want to enter at market because you may refer to wait longer for the proper conditions for a pending order, simply comment out lines 23 and 31.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on