need help coding simple D open strategy
Forums › ProRealTime English forum › ProOrder support › need help coding simple D open strategy
- This topic has 15 replies, 2 voices, and was last updated 3 years ago by ullle73.
-
-
11/11/2020 at 4:45 PM #150147
Hi, could anyone help out coding this strategy found on forexfactory: https://www.forexfactory.com/thread/1032108-dos-daily-open-strategy-easy-to-trade-simple
here are conditions:
- If difference in pips between Open to Close (or Close to Open) of previous daily closed bar is more than 110 pips, then at the open of current day – open a market order to the opposite direction of previous day.
- i.e: if yesterday’s daily bar is Bullish (moved up) and BODY (Close price – Open price) is more than 110 pips, then today at the Open of new daily bar, at 00:00, open Sell market order.
Note: if spread at midnight is too high (more than 4.0 pips) – Don’t open a trade yet. Wait with market order till spread narrows back. It may take even 1-2 hours but usually it will take only a few minutes. So once spread is less than 4.0 pips, open the trade. - TP = 20 to 50 pips, depends on currency’s volatility.
- No SL.
- If price goes from last entry against the direction of the trade, open at the Open of every new day an additional market order with same lot size as original trade. No TP for additional trade.
- Close all trades together when sum of all open profitable and losing trades (“basket“) is positive (may be 0.1$ or 1$).
- Instead of SL: If sum of all open trades (“basket”) is losing more than 25% of account balance – close all trades. *This may happen once in a decade if at all.
11/11/2020 at 6:05 PM #150167It’s not possible to know what the spread is, usually pretty high around midnight.
What TF do you plan to use?
11/11/2020 at 8:27 PM #15018611/12/2020 at 12:34 AM #150201There you go:
12345678910111213141516171819DefParam CumulateOrders = trueCapital = 10000000Equity = Capital + StrategyProfitBody = abs(close - open)Bullish = close > openc1 = Bullish AND (Body > 110 * PipSize)If c1 AND Not OnMarket THENSellShort 1 Contract at MarketSet Target pProfit 50ElsIf ShortOnMarket AND PositionPerf < 0 ThenSellShort 1 Contract at MarketEndifIf PositionPerf > 0 ThenExitShort at MarketEndifMoneyGained = abs(PositionPerf * PositionPrice / PipSize * PipValue)IF (MoneyGained >= (Equity * 0.25)) AND PositionPerf < 0 ThenExitShort at MarketEndif1 user thanked author for this post.
11/12/2020 at 11:03 AM #15024711/12/2020 at 11:32 AM #15025611/12/2020 at 12:20 PM #150268This should do (not tested):
123456789101112131415161718192021222324252627DefParam CumulateOrders = trueCapital = 10000000Equity = Capital + StrategyProfitBody = abs(close - open)Bullish = close > openBearish = close < openc1 = Bullish AND (Body > 110 * PipSize)c2 = Bearish AND (Body > 110 * PipSize)If c1 AND Not OnMarket THENSellShort 1 Contract at MarketSet Target pProfit 50ElsIf ShortOnMarket AND PositionPerf < 0 ThenSellShort at MarketElsIF c2 AND Not OnMarket THENBuy 1 Contract at MarketSet Target pProfit 50ElsIf LongOnMarket AND PositionPerf < 0 ThenSell at MarketEndifIf PositionPerf > 0 ThenExitShort at MarketEndifMoneyGained = abs(PositionPerf * PositionPrice / PipSize * PipValue)IF (MoneyGained >= (Equity * 0.25)) AND PositionPerf < 0 ThenExitShort at MarketSell at MarketEndif11/12/2020 at 2:44 PM #15029511/12/2020 at 2:56 PM #150300Adjust Capital to the actual size.
11/12/2020 at 8:12 PM #150331still, code does not sell ALL pos as soon as in profit. You can see in picture that it does sell each individual trade when in profit. Is it possible to ALL open shorts when trade is in profit. In the example in the picture, it should probably have been 7 contracts before reaching BE, but after 5 it sold some and bought some
11/12/2020 at 8:40 PM #150334Individual SL’s and TP’s are sent each time a position is added, so every position has it’s own life, if one hits the target or the stop loss it’s closed and POSITIONPERF is updated, so there’s no way to know the whole profit until ALL positions are close (that’s the time STRATEGYPROFIT is updated, not earlier).
Managing accumulation of positions is not easy and, unless there’s only one global TP or SL, it’s impossible to know exactly what the performance is, since some positions may still be opened and some may have already been closed.
But I have spotted a missing line, add this line just AFTER, or BEFORE, line 21:
1SELL AT Market1 user thanked author for this post.
11/12/2020 at 10:31 PM #15033811/12/2020 at 11:17 PM #150341Try removing AND Not OnMarket from lines 9 and 14.
11/13/2020 at 10:38 AM #150362sdos1234567891011121314151617181920212223242526272829DefParam CumulateOrders = trueCapital = 100000Equity = Capital + StrategyProfitBody = abs(close - open)Bullish = close > openBearish = close < openc1 = Bullish AND (Body > 110 * PipSize)c2 = Bearish AND (Body > 110 * PipSize)If c1 THENSellShort 1 Contract at MarketSet Target pProfit 50ElsIf ShortOnMarket AND PositionPerf < 0 ThenSellShort at MarketElsIF c2 THENBuy 1 Contract at MarketSet Target pProfit 50ElsIf LongOnMarket AND PositionPerf < 0 Thensell at MarketEndifIf PositionPerf > 0 ThenSELL AT MarketExitShort at MarketEndifMoneyGained = abs(PositionPerf * PositionPrice / PipSize * PipValue)IF (MoneyGained >= (Equity * 0.25)) AND PositionPerf < 0 ThenExitShort at MarketSell at MarketEndifDoes not work :/
11/13/2020 at 1:31 PM #150376This should match the requirements (I made numeric values variable):
1234567891011121314151617181920212223242526272829303132333435DefParam CumulateOrders = trueONCE BodySize = 110 //110 Pips (zize of candle's body)ONCE TP = 30 //30 Take ProfitONCE MaxLoss = 25 //25% max. lossONCE Capital = 100000 //100000 starting CapitalEquity = Capital + StrategyProfitBody = abs(close - open)Bullish = close > openBearish = close < openc1 = Bullish AND (Body > BodySize * PipSize)c2 = Bearish AND (Body > BodySize * PipSize)// - SHORTIf c1 THENSellShort 1 Contract at MarketSet Target pProfit TPElsIF ShortOnMarket AND PositionPerf < 0 THENSellShort 1 Contract at Marketendif// - LONGIF c2 THENBuy 1 Contract at MarketSet Target pProfit TPElsIF LongOnMarket AND PositionPerf < 0 THENBuy 1 Contract at Marketendif/////////////////////////////////////////////MoneyGained = PositionPerf * PositionPrice / PipSize * PipValueIF (abs(MoneyGained) >= (Equity * (MaxLoss / 100))) AND PositionPerf < 0 ThenExitShort at MarketSell at MarketEndif////graph CountOfPosition//graph PositionPerf//graph MoneyGained1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on