Average cross with Opt

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #170021 quote
    josei53
    Participant
    New

    Hi All,

    Can any of you advice me how to code the following things in an average cross with optimization?

    1. Buy / Sell on the same bar where the cross happens
    2. Trade always with the 100% of available Equity
    3. No delay in opening orders.

    Thanks in advance!

    #170055 quote
    robertogozzi
    Moderator
    Master

    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.

    #170701 quote
    josei53
    Participant
    New

    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
    #170705 quote
    robertogozzi
    Moderator
    Master

    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
    #170997 quote
    josei53
    Participant
    New

    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!

    #171005 quote
    robertogozzi
    Moderator
    Master

    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.

    #171006 quote
    josei53
    Participant
    New

    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!

    Screenshot-2021-06-02-at-18.37.33.jpg Screenshot-2021-06-02-at-18.37.33.jpg
    #171008 quote
    robertogozzi
    Moderator
    Master

    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.

    #171113 quote
    josei53
    Participant
    New

    Thank you Roberto,

    I have emailed you.

    Thanks!

    #171124 quote
    josei53
    Participant
    New

    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

    Screenshot1.png Screenshot1.png Screenshot2.png Screenshot2.png Screenshot-3.png Screenshot-3.png
    #171132 quote
    robertogozzi
    Moderator
    Master

    Letme know:

    • the security you tested it on
    • the TF used
    • the number of units.

    Please also post your ITF file.

    #171154 quote
    josei53
    Participant
    New
    • the security you tested it on—> GOOGL
    • the TF used—>daily
    • the number of units.–> 500 & 1000

    Please also post your ITF file.—> attached

    Jose.itf
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Average cross with Opt


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
josei53 @josei53 Participant
Summary

This topic contains 11 replies,
has 2 voices, and was last updated by josei53
4 years, 9 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 05/20/2021
Status: Active
Attachments: 5 files
Logo Logo
Loading...