Hi All,
Can any of you advice me how to code the following things in an average cross with optimization?
- Buy / Sell on the same bar where the cross happens
- Trade always with the 100% of available Equity
- No delay in opening orders.
Thanks in advance!
1. strategies are executed when a candle closes, so any trade is entered just a few microseconds before the new candle opens
2. can you post an example or more details, please?
3. (same as 1.)
To overcome points 1 and 2, MTF (Multi Time Frame) support can be used so that you can earlier see what happens on the higher TF from a lower one.
Thank you Roberto for your answer.
What I meant by “Trade always with the 100% of available Equity” is that I want to always make orders with the available capital, not with the Initial one (reinvesting gains)
This is what I am using, do you see any error that makes my EMA cross not accurate?
Thanks!
DEFPARAM CumulateOrders = False // Acumulación de posiciones desactivada
DEFPARAM NOCASHUPDATE = false
indicator1 = ExponentialAverage[short](close)
indicator2 = ExponentialAverage[long](close)
c1 = (indicator1[1] CROSSES over indicator2[1])
IF c1 THEN
BUY 10000 cash AT MARKET NextBarOpen
ENDIF
c2 = (indicator1[1] CROSSES under indicator1[1])
IF c2 THEN
SELL AT MARKET NextBarOpen
ENDIF
SET STOP %LOSS 6
There are some errors:
1. in line 6 you are referencing the previous candle using [1], so I removed it for the current candle
2. in line 12 you used the same indicator for the cross under, so I changed it.
As to lot management, I added a calculation which is based on three parameters I added after DEFPARAM:
1. starting capital (you have to write the capital you plan to use when the strategy starts)
2. the minimum lot size allowed by the broker (or any greater value that suits you best)
3. the number of lots that you usually trade with the starting capital (you will set the number according to
your preferences about risk, drawdown, margin, etc…) then the calculations that follow will adjust it
to your profits/losses.
DEFPARAM CumulateOrders = False // Acumulación de posiciones desactivada
DEFPARAM NOCASHUPDATE = false
ONCE Capital = 10000
ONCE BaseLots = 1
ONCE MinLots = 1
Equity = Capital + StrategyProfit
Lots = Equity * BaseLots / Capital
Lots = max(MinLots,round((Lots * 10) - 0.5) / 10)
indicator1 = ExponentialAverage[short](close)
indicator2 = ExponentialAverage[long](close)
c1 = (indicator1 CROSSES over indicator2)
IF c1 THEN
BUY Lots cash AT MARKET NextBarOpen
ENDIF
c2 = (indicator1 CROSSES under indicator2)
IF c2 THEN
SELL AT MARKET NextBarOpen
ENDIF
SET STOP %LOSS 6
Thank Roberto! I appreciate your help on this and I understand your corrections.
Im trying to replicate what you created, but for any reason that I cannot spot, the line 8 got error ” Close the line”
Do you know where this could come from?
Thanks!
Unless you did a wrong Copy & Paste the only solution could be to either:
- comment out line 2
- remove or comment out + StrategyProfit from line 7
in both cases there is a conflict between your intention to reinvest gains and line 2.
I never used line 2.
If the error is still reported you should post your code.
I have commented out line 2, and I have also tried removing + + StrategyProfit from line 7, and I still have the error.
Please find attached the error message, I think is something simple but I cannot spot it.
Thanks!
Ok, I see, sorry my fault.
LOTS is a reserved keyword. Replace any occurrence of that word with MyLots, or any one else that you wish.
But I think you should also comment out line 2, as it may affect STRATEGYPROFIT.
Hi Roberto,
I have tried your system following all your instructions, but It does not give me any result..All values in 0.
Any idea where the issue comes from? see attached screenshots
Letme know:
- the security you tested it on
- the TF used
- the number of units.
Please also post your ITF file.
- the security you tested it on—> GOOGL
- the TF used—>daily
- the number of units.–> 500 & 1000
Please also post your ITF file.—> attached