This code, applied to the EurUsd with time frame H1, does not always produce the correct behavior.
The logic of the operation should be well described by the comments in the code. If necessary, however, I am here to integrate the missing information.
For example, on August 29th (candle at 7:00 pm) last, he makes a sale and a purchase, inside the same candle. But in the previous candle the conditions for entering the market were already false.
Another example is that of last September 2nd (7:00 am candle): all three conditions are verified and in the next candle a sale should take place as there is a rupture of the lower end of the canal. But this does not happen.
Can anyone help me understand?
Thank you.
Defparam cumulateorders = false
// At 5 am I define the width of the canal (RangeBreakout) and its extremes (HH and LL)
// Furthermore, I set the TradeLong and TradeShort variables to zero
IF TIME = 050000 THEN
HH = highest[8](high)
LL = lowest[8](low)
TradeLong = 0
TradeShort = 0
RangeBreakout = HH-LL
ENDIF
//I define the condition that requires working in a specific time interval
Condtime = time >= 050000 AND time <= 180000
// I define the condition that requires the closing price to be inside the channel
Condchannel = close < HH and close > LL
// If the Condchannel and CondTime conditions are met ...
IF Condtime and Condchannel THEN
IF TradeLong = 0 THEN
buy at HH stop //... and if the system is not Long, then buy at the breaking of the upper end of the channel
ELSIF TradeShort = 0 THEN
sellshort at LL stop //... and if the system is not Short, then it sells at the breaking of the lower end of the channel
ENDIF
ENDIF
// If the position is long, set the value of the TradeLong variable to 1
IF longonmarket THEN
TradeLong = 1
ENDIF
// If the position is short, set the value of the TradeShort variable to 1
IF shortonmarket THEN
TradeShort = 1
ENDIF
// Set a stop loss equal to the width of the channel
set stop loss RangeBreakout
// Set a profit equal to a percentage of the channel width
set target profit RangeBreakout*Tgt
graph Condtime
graph Condchannel
graph TradeLong
graph TradeShort
graph HH
graph LL
Try below for Lines 20 to 25 (addition of not short / long onmarket)
IF Condtime and Condchannel THEN
IF not shortonmarket and TradeLong = 0 THEN
buy at HH stop //... and if the system is not Long, then buy at the breaking of the upper end of the channel
ELSIF not longonmarket and TradeShort = 0 THEN
sellshort at LL stop //... and if the system is not Short, then it sells at the breaking of the lower end of the channel
ENDIF
ENDIF
Tgt (Target) is a variable that in a first optimization I made vary between 0.1 and 5 with steps of 0.1.
On Aug. 29th no trade entered (EurUsd, 1H).
Are you sure about dates and times?
Please attach scrrenshot to be able to see:
– wrong trades
– price
– instrument
– date
– time
You’re right, Roberto, and I thank you. For completeness I will do so next time. Now I focus on the error I identified thanks to GraHal’s intervention.
I get attached at Spread = 4
In the version I provided .itf above, if you use below (instead of as in the .itf) then it gives a better equity curve?
I had time >= 000000 in the .itf I provided.
Condtime = time >= 030000
But aren’t 4 spread points excessive?
On the DJI, spread is never lower than 1.6 and does go to around 4 between 23:00 and 01:30 so unless a System trades only during times when spread = 1.6 then I use spread = 4. Also there are overnight costs etc so spread = 4 for DJI goes some way towards covering these also.
I feel it is better to be a worst case re costs in Demo then maybe costs will be less and a pleasant surprise in Live trading! 🙂
Yes, it is certainly a prudent and acceptable way to proceed.
The only risk, in my opinion, (I think of other underlying assets) is to discard systems that could prove profitable.
Thank you.
🙂
A good test is to remove spread altogether and then re-test the strategy several times slowly adding it back in up to an extreme value such as GraHal suggests. You should see a slowly decreasing performance as less trades get opened and spread hits profits more but your strategy should not break completely.
It seems to me a good way to proceed but I have to try and try again several times: this phase of the process of building an automated trading strategy is still unclear to me.
Thank you for your time.
(I think of other underlying assets) is to discard systems that could prove profitable
I don’t use spread = 4 on all markets, for example on eurusd I use spread = 2 as eurusd is mostly spread = 0.6 during the day .