If stopped out, dont trade for N days
Forums › ProRealTime English forum › ProOrder support › If stopped out, dont trade for N days
- This topic has 5 replies, 2 voices, and was last updated 5 years ago by Vonasi.
-
-
10/10/2018 at 2:37 PM #82460
Hi,
I’m struggling to write the logic to use when skipping trades for N days if last trade was stopped out. This is to avoid consecutive bad days in poor market conditions.
Progress so far1234567891011121314151617181920once varhardSL = 70// Determine when to skip:// If low of today's bar is below today's SL level (close last bar minus stop loss level), it determines the stop was hit.skipTrade = 0 // Start by assuming not hit every barif Low[0] <= (Close[1] - (varhardSL)) thenskipTrade = 1endifgraphOnPrice (Close[1] - (varhardSL))graph skipTrade// Enter tradec1 = 1c2 = 1buyCriteria = c1 and c2 and skipTrade < 1if buyCriteria thenBUY possize SHARES AT MARKETSet stop $loss varhardSLset target $profit 140endifTrying this on Usa500 daily 00:00-00:00 hours
It will skip the third down day but still enter on the second which I’d want to avoid.
Any ideas?
Br10/10/2018 at 3:31 PM #82477You could try something like this:
1234567891011121314151617181920once varhardSL = 70// Determine when to skip:// If low of today's bar is below today's SL level (close last bar minus stop loss level), it determines the stop was hit.if Low[0] <= (Close[1] - (varhardSL)) thenskipTrade = 4endifskiptrade = skiptrade - 1// Enter tradec1 = 1c2 = 1buyCriteria = c1 and c2 and skipTrade < 1if buyCriteria thenBUY possize SHARES AT MARKETSet stop $loss varhardSLset target $profit 140endifI’m guessing that you are trading daily candles?
10/10/2018 at 4:57 PM #8249510/10/2018 at 5:37 PM #82504It is difficult to understand what you think is not working from your description and images. I cannot see what time frame you are on or what the values of the candles are.
The code as written will stay out of the market any time that the current candles low is less than the previous candles close minus 70. It does not know whether you were on the market with a trade or not.
I just adjusted the code you provided to do what you wanted!
10/10/2018 at 7:31 PM #82513I understand. I’ve attached the full strategy code if you’d like to test. On Usa500 (ES) 1eur contract daily bars 00:00-00:00 hours. Spread 1.6.
As can be seen there are sharp drops in the equity curve at August 24 2015 and February 2 2018, which I was thinking could be avoided if not allowing consecutive trades around stop loss reached days.
Full strategy1234567891011121314151617181920212223242526272829303132333435363738394041424344454647DEFPARAM CumulateOrders = Falseonce varMaxHoldTime = 6once varSellAtProfitablecloses = 1once varNumProfitableClose = 0once varAvoidDay = 3once varhardSL = 70// Entryonce skipTrade = 0if Low[0] <= (Close[1] - (varhardSL)) thenskipTrade = 4endifskiptrade = skiptrade - 1graphOnPrice (Close[1] - (varhardSL))graph skipTradec1 = dayofweek <> varAvoidDayc2 = ((high + low + close)/3)[0] <= ((high + low + close)/3)[1]c3 = open[6] <= close[7] and high[1] <= high[8]buyConditions = c1 and c2 and c3 and skipTrade < 1if buyConditions thenBUY 1 SHARES AT MARKETSet Stop $Loss varhardSLendifif onmarket[0] = 0 and onmarket[1] = 1 thenvarNumProfitableClose = 0endif// +1 profitable closeif LongOnMarket and Close[0] >= TradePrice thenvarNumProfitableClose = varNumProfitableClose + 1endif// Exit: Profitable closeif varNumProfitableClose >= varSellAtProfitablecloses thenSell at MarketENDIF// Exit: Max hold time reachedif LongOnMarket and barindex - tradeindex >= varMaxHoldTime - 1 thensell at Marketendif10/10/2018 at 9:25 PM #82518As far as I can see the reason for the poor equity curve at those times is because your entry criteria was met. 70 pips on the SP500 is a big drop and on the day of Aug 20 that condition was not met so a trade was entered at the open of the next day. On the Aug 23 the conditions were also met and another losing trade entered. On Aug 24 your 70 pip drop condition was met and no trade entered.
Your code has a lot of unnecessary stuff in it so I edited it to make it more readable. Here is my ‘light’ version:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546DEFPARAM CumulateOrders = FalsevarMaxHoldTime = 6varSellAtProfitablecloses = 1varAvoidDay = 3varhardSL = 70// EntryskipTrade = 0if Low <= (Close[1] - (varhardSL)) thenskipTrade = 4endifskiptrade = skiptrade - 1c1 = dayofweek <> varAvoidDayc2 = ((high + low + close)/3) <= ((high + low + close)/3)[1]c3 = open[6] <= close[7] and high[1] <= high[8]buyConditions = c1 and c2 and c3 and skipTrade < 1if buyConditions thenBUY 1 SHARES AT MARKETSet Stop $Loss varhardSLendifif not onmarket and onmarket[1] thenvarNumProfitableClose = 0endif// +1 profitable closeif LongOnMarket and Close >= TradePrice thenvarNumProfitableClose = varNumProfitableClose + 1endif// Exit: Profitable closeif varNumProfitableClose >= varSellAtProfitablecloses thenSell at MarketENDIF// Exit: Max hold time reachedif LongOnMarket and barindex - tradeindex >= varMaxHoldTime - 1 thensell at Marketendifgraph skiptrade1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on