Hello folks,
Here’s my code:
DEFPARAM CumulateOrders = False
//dynamic position sizing
INITIALCAPITAL = 10000
d = (INITIALCAPITAL/close)
if d < 0.2 then
d = 0.2
endif
//end dynamic position sizing
indicator1 = SAR[0.3,0.3,0.1]
c1 = (close > indicator1)
indicator2 = RSI[4](close)
c2 = (indicator2 < 80)
c3 = (close >= open)
indicator3 = AroonUp[15]
c4 = (indicator3 > 5)
IF c1 AND c2 AND c3 AND c4 THEN
BUY d PERPOINT AT MARKET
ENDIF
indicator4 = SAR[0.3,0.1,0.1]
c5 = (indicator4 > close)
indicator5 = RSI[4](close)
c6 = (indicator5 > 80)
set stop $loss 800
IF c5 OR c6 THEN
SELL AT MARKET
ENDIF
As you can see, one of the sell rules is:
indicator4 = SAR[0.3,0.1,0.1]
c5 = (indicator4 > close)
However, once these conditions where satisfied last night, the algo did not exit my trade. What am I missing?
I’ve looked over my code five times and I’m starting to think I’m going crazy. I’d appreciate any help.
Thanks,
Aleks
In your chart I can’t see where it was supposed to exit.
Append
GRAPH c5
GRAPH c6
then, after backtesting, check the variables’window to see what value they retain candle by candle. If their value is not, then conditions are not met.
Hi Robert, thanks for your answer. After including the graph commands, here’s what I get:
As you can see, the parabolic SAR gives off a sell signal, however, the system stays long.
Your pic shows that on the bar where your mouse is sitting there were no trades open!
Hi Roberto,
The blue bars bellow the graphed variables show that a position of 0.66 lots was open.
Thanks,
Aleks
Does the SAR on your Price Chart have same settings as the SAR in your Algo at Line 23 – (SAR[0.3,0.1,0.1] )
Yep, I checked for that and it seems like both the SAR on the chart and the system are the same.
So you must have changed the SAR on the Price Chart because the default settings are – SAR[0.02,0.02,0.2]
Odd you say … ‘seems they are the same’ … either they are the same or they are not the same? 🙂
Anyway your condition c5 = (indicator4 > close) occurs on the bar marked with the red arrows on attached and so the Sell will occur at the open of the next bar … as indeed it does??
Or maybe you just haven’t shown any more bars??
Forgive my brusque comment in my previous post … I have one eye on the tv and I’ve had a beer! 🙂
The GRAPH shows that C5 was true at the close of the second to last bar so the trade should be closed at the open of the last bar shown on the chart. I think we will not see the true backtest actions until this latest bar is actually closed and the backtest engine can see what trading actions would have occurred in that last bar. It is a back test and not live trading and actions are not real time.
I’ve not been back testing for a while so might be a bit rusty and talking rubbish though!
Hi GraHal,
Thanks for your answer. All good- personally I’m nursing quite a hard hangover from yesterday, so my English might not be as clear as I’d like it to be. I apologise for any miscommunication.
In my last screenshot, my cursor hides the first red dot that appeared on the 19th of November. The trade should’ve been closed on the opening of the 20th of November.
I thought I might also add that this system was actually live while these trades where on, and I thought that the system would’ve exited me out of my trade in real time?
Thanks,
Aleks
Try using this as line 30:
IF c5 <> 0 OR c6 <> 0 THEN
it’s the same as the original one but… never say never!
You can’t use the GRAPH instruction in live trading. Are you sure that you mean live and not just a currently running backtest?