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.
It’s not possible to know what the spread is, usually pretty high around midnight.
What TF do you plan to use?
yes, i understand that, dont mind the spread for now. Planing on using daily tf 🙂
thanks for fast answer
There you go:
DefParam CumulateOrders = true
Capital = 10000000
Equity = Capital + StrategyProfit
Body = abs(close - open)
Bullish = close > open
c1 = Bullish AND (Body > 110 * PipSize)
If c1 AND Not OnMarket THEN
SellShort 1 Contract at Market
Set Target pProfit 50
ElsIf ShortOnMarket AND PositionPerf < 0 Then
SellShort 1 Contract at Market
Endif
If PositionPerf > 0 Then
ExitShort at Market
Endif
MoneyGained = abs(PositionPerf * PositionPrice / PipSize * PipValue)
IF (MoneyGained >= (Equity * 0.25)) AND PositionPerf < 0 Then
ExitShort at Market
Endif
you are the best! thanks roberto
tried adding long conditions as well, but then it does not take any shorts… could you help me with that as well? 🙂
This should do (not tested):
DefParam CumulateOrders = true
Capital = 10000000
Equity = Capital + StrategyProfit
Body = abs(close - open)
Bullish = close > open
Bearish = close < open
c1 = Bullish AND (Body > 110 * PipSize)
c2 = Bearish AND (Body > 110 * PipSize)
If c1 AND Not OnMarket THEN
SellShort 1 Contract at Market
Set Target pProfit 50
ElsIf ShortOnMarket AND PositionPerf < 0 Then
SellShort at Market
ElsIF c2 AND Not OnMarket THEN
Buy 1 Contract at Market
Set Target pProfit 50
ElsIf LongOnMarket AND PositionPerf < 0 Then
Sell at Market
Endif
If PositionPerf > 0 Then
ExitShort at Market
Endif
MoneyGained = abs(PositionPerf * PositionPrice / PipSize * PipValue)
IF (MoneyGained >= (Equity * 0.25)) AND PositionPerf < 0 Then
ExitShort at Market
Sell at Market
Endif
thanks!! long and short short, long does not scale up though, and the panic 25% of capital SL does not seem to work
Adjust Capital to the actual size.
still, 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
Individual 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:
SELL AT Market
oh okay, i see. Do you know why strategy does not increase long positions? I have capital and initial capital the same.
Try removing AND Not OnMarket from lines 9 and 14.
DefParam CumulateOrders = true
Capital = 100000
Equity = Capital + StrategyProfit
Body = abs(close - open)
Bullish = close > open
Bearish = close < open
c1 = Bullish AND (Body > 110 * PipSize)
c2 = Bearish AND (Body > 110 * PipSize)
If c1 THEN
SellShort 1 Contract at Market
Set Target pProfit 50
ElsIf ShortOnMarket AND PositionPerf < 0 Then
SellShort at Market
ElsIF c2 THEN
Buy 1 Contract at Market
Set Target pProfit 50
ElsIf LongOnMarket AND PositionPerf < 0 Then
sell at Market
Endif
If PositionPerf > 0 Then
SELL AT Market
ExitShort at Market
Endif
MoneyGained = abs(PositionPerf * PositionPrice / PipSize * PipValue)
IF (MoneyGained >= (Equity * 0.25)) AND PositionPerf < 0 Then
ExitShort at Market
Sell at Market
Endif
Does not work :/
This should match the requirements (I made numeric values variable):
DefParam CumulateOrders = true
ONCE BodySize = 110 //110 Pips (zize of candle's body)
ONCE TP = 30 //30 Take Profit
ONCE MaxLoss = 25 //25% max. loss
ONCE Capital = 100000 //100000 starting Capital
Equity = Capital + StrategyProfit
Body = abs(close - open)
Bullish = close > open
Bearish = close < open
c1 = Bullish AND (Body > BodySize * PipSize)
c2 = Bearish AND (Body > BodySize * PipSize)
// - SHORT
If c1 THEN
SellShort 1 Contract at Market
Set Target pProfit TP
ElsIF ShortOnMarket AND PositionPerf < 0 THEN
SellShort 1 Contract at Market
endif
// - LONG
IF c2 THEN
Buy 1 Contract at Market
Set Target pProfit TP
ElsIF LongOnMarket AND PositionPerf < 0 THEN
Buy 1 Contract at Market
endif
/////////////////////////////////////////////
MoneyGained = PositionPerf * PositionPrice / PipSize * PipValue
IF (abs(MoneyGained) >= (Equity * (MaxLoss / 100))) AND PositionPerf < 0 Then
ExitShort at Market
Sell at Market
Endif
//
//graph CountOfPosition
//graph PositionPerf
//graph MoneyGained