Average cross with Opt
Forums › ProRealTime English forum › ProScreener support › Average cross with Opt
- This topic has 11 replies, 2 voices, and was last updated 3 years ago by josei53.
Tagged: mtf
-
-
05/20/2021 at 9:32 AM #170021
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!
05/20/2021 at 2:50 PM #1700551. 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.
05/28/2021 at 4:57 PM #170701Thank 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!123456789101112131415161718DEFPARAM CumulateOrders = False // Acumulación de posiciones desactivadaDEFPARAM NOCASHUPDATE = falseindicator1 = ExponentialAverage[short](close)indicator2 = ExponentialAverage[long](close)c1 = (indicator1[1] CROSSES over indicator2[1])IF c1 THENBUY 10000 cash AT MARKET NextBarOpenENDIFc2 = (indicator1[1] CROSSES under indicator1[1])IF c2 THENSELL AT MARKET NextBarOpenENDIFSET STOP %LOSS 605/28/2021 at 5:57 PM #170705There 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.12345678910111213141516171819202122232425DEFPARAM CumulateOrders = False // Acumulación de posiciones desactivadaDEFPARAM NOCASHUPDATE = falseONCE Capital = 10000ONCE BaseLots = 1ONCE MinLots = 1Equity = Capital + StrategyProfitLots = Equity * BaseLots / CapitalLots = max(MinLots,round((Lots * 10) - 0.5) / 10)indicator1 = ExponentialAverage[short](close)indicator2 = ExponentialAverage[long](close)c1 = (indicator1 CROSSES over indicator2)IF c1 THENBUY Lots cash AT MARKET NextBarOpenENDIFc2 = (indicator1 CROSSES under indicator2)IF c2 THENSELL AT MARKET NextBarOpenENDIFSET STOP %LOSS 606/02/2021 at 2:27 PM #170997Thank 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!06/02/2021 at 5:28 PM #171005Unless 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.
06/02/2021 at 5:39 PM #17100606/02/2021 at 5:55 PM #171008Ok, 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.
06/04/2021 at 10:02 AM #17111306/04/2021 at 11:05 AM #17112406/04/2021 at 11:32 AM #171132Letme know:
- the security you tested it on
- the TF used
- the number of units.
Please also post your ITF file.
06/04/2021 at 2:59 PM #171154 -
AuthorPosts
Find exclusive trading pro-tools on