Total Beginner

Viewing 15 posts - 16 through 30 (of 39 total)
  • Author
    Posts
  • #201986 quote
    Trader Sab
    Participant
    New

    Hi

    I am not sure in what TF you let it run. I get much poorer result than you 🙁

     

    I also have another question and I can’t find the ‘thinking’ error I am doing (blond after all! LOL)

    The below code opens at random positions although price has moved far away from EMA20. I tried the comands great than and lesser than but the results are not good either.

    Appreciate you taking time to help me out.

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM FLATBEFORE = 083000
    DEFPARAM FLATAFTER = 220000

    // Conditions to enter long positions
    indicator1 = ExponentialAverage[20](close)
    c1 = (close crosses over indicator1)

    IF c1 THEN
    BUY 0.5 CONTRACT AT MARKET
    ENDIF

    // Conditions to exit long positions
    indicator2 = ExponentialAverage[20](close)
    c2 = (close CROSSES UNDER indicator1)

    IF c2 THEN
    SELL AT MARKET
    ENDIF
    SET STOP TRAILING 10

    // Conditions to enter short positions
    indicator1 = ExponentialAverage[20](close)
    c3 = (close crosses under indicator1)

    IF c3 THEN
    SELLSHORT 0.5 CONTRACT AT MARKET
    ENDIF

    // Conditions to exit short positions
    indicator2 = ExponentialAverage[20](close)
    c4 = (close CROSSES OVER indicator1)

    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    SET STOP TRAILING 10

    Trade-Activity-061022.jpg Trade-Activity-061022.jpg DAX-CHART-TRADES-061022.jpg DAX-CHART-TRADES-061022.jpg
    #201990 quote
    robertogozzi
    Moderator
    Master

    A couple of ENDIFs are missing.

    Trader Sab thanked this post
    #201992 quote
    robertogozzi
    Moderator
    Master

    Actually they were missing in your previous code.

    Trader Sab thanked this post
    #202001 quote
    Trader Sab
    Participant
    New

    Hi

    I try to reduce the variables as much as possible to get a really simple system working.

    However when I let the code below run, it always opens random short positions for me, instead of having just one since early morning. I know the issue is with the entry condition c1 and c2, which I have defined as crossing over/under, but for some reason the code then opens random positions that are below indicator1 and have not fullfilled the conditon of crossing. I know there is a fault in my thinking and I can’t figure it out. Greatly appreciate your help! Thanks in advance

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM FLATBEFORE = 083000
    DEFPARAM FLATAFTER = 220000

    // Conditions to enter long positions
    indicator1 = ExponentialAverage[20](close)
    c1 = (close crosses over indicator1)

    IF c1 THEN
    BUY 0.5 CONTRACT AT MARKET
    ENDIF

    // Conditions to exit long positions
    indicator1 = ExponentialAverage[20](close)
    c2 = (close < indicator1)

    IF c2 THEN
    SELL AT MARKET
    ENDIF
    SET STOP TRAILING 10

    // Conditions to enter short positions
    indicator1 = ExponentialAverage[20](close)
    c3 = (close crosses under indicator1)

    IF c3 THEN
    SELLSHORT 0.5 CONTRACT AT MARKET
    ENDIF

    // Conditions to exit short positions
    indicator2 = ExponentialAverage[20](close)
    c4 = (close > indicator1)

    IF c4 THEN
    EXITSHORT AT MARKET
    ENDIF
    SET STOP TRAILING 10

    #202004 quote
    GraHal
    Participant
    Master

    You don’t say in the post above an Instrument or Timeframe.

    Anyway I got attached curve with attached .itf  (Note attached is on 1K bars only for quickness in optimising for me.  A12, A13 are variables in the optimiser … my quick way of id notation) 

    It may help motivation and understanding if you see a profit developing … I know it does with me!! 🙂

    Import the .itf into your Algo area of platform.

    Trader Sab thanked this post
    Sab.jpg Sab.jpg Sab-EAx-DJI-M5-1K-v1gh.itf
    #202007 quote
    GraHal
    Participant
    Master

    it always opens random short positions for me

    By random do you mean NOT when crosses under occurs?

    If you insert below in your code you can see when C3 = True / 1

    IF c3 THEN
    SELLSHORT 0.5 CONTRACT AT MARKET
    ENDIF

    GRAPH C3

    Trader Sab thanked this post
    #202008 quote
    Trader Sab
    Participant
    New

    Thank you very much. I know that I need to clearly define as the only short scenario the bar crossing over the indicator.

    I tried your idea but I couldn’t make it work.

    Appreciate your help. Looks like this system would work nicely once this fault is eliminated.

    If-c3-True.jpg If-c3-True.jpg
    #202010 quote
    Trader Sab
    Participant
    New

    I still can’t get it to work with only one indicator and such a simple strategy. What am I missing? I know the error is somewhere in the definition of crossing over or under but how can I define this precise? I tried with close [0] open [0] and close [1] none did eliminate the mistake.

    Thank you very much.

    #202011 quote
    GraHal
    Participant
    Master

    Code on your screen shot above is not replicating what I specified using GRAPH

    GRAPH

    #202012 quote
    GraHal
    Participant
    Master

    I know the error is somewhere in the definition of crossing over or under

    No … as seen by my .itf I provided … which is why I posted the .itf to show that the crossing over / under can and does work.

    It’s more your original strategy – re Sell and ExitShort – that are not working … if we cross under EA20 then chances are we might – for a while – get whipsawed out again due to price > EA 20.

    Above is why I rem’d out your Sell and Exitshort conditions in your original strategy.

    Trader Sab thanked this post
    #202014 quote
    GraHal
    Participant
    Master

    I still can’t get it to work

    What do you mean by “get it to work”?

    If you mean get your code to do what the code states it should do? Then by using GRAPH you can analyse what it is doing and when etc.

    If you mean … doesn’t make profit, then my comments in my previous post above are more relevant.

    (Do not go Live with REAL money and any Algo until tested in Demo Account for > min of 50 trades and 1 month; preferable 100’s of trades and 6 to 12 months in Demo! 🙁 )

    Trader Sab thanked this post
    #202015 quote
    PeterSt
    Participant
    Master

    Trader Sab, change that line of code (see attachment) into :

    If C3 = True then // 1

    That will avoid that error. It is just a syntax error.

    Trader Sab thanked this post
    image_2022-10-06_154425147.png image_2022-10-06_154425147.png
    #202030 quote
    Trader Sab
    Participant
    New

     

    @GraHal

    Good evening

    Thanks for the improved code and I run the new code on DJI with 1k on 5 min chart, however I got a dismal result. I am not sure why back testing can give such different results with on the same instrument when performed at different times.

    In the code with only the EMA20 as signal line, I tried to work with your suggestion but it returns an error message. I figured out that I need to define the crossing candle differently to set it apart from the other candles that open below the EMA20. However non of the candles that opened positions after the initial crossing fulfilled the close crosses over/ under EMA20 but the system still opened the position

    I truly appreciate your help, I am a bit lost but enjoy the learning tremendously.

    Have a great evening

    GraHal-Test.jpg GraHal-Test.jpg GraHal-Test-2.jpg GraHal-Test-2.jpg trying-to-define-the-cross-over-candle.jpg trying-to-define-the-cross-over-candle.jpg
    #202035 quote
    Trader Sab
    Participant
    New

    Well I tried your suggestion but it still returns an error.

    I know I have to define that only the first candle is the signal to open a new position but I am not sure how to do this.

    Thank you so much for your help

    trying-to-define-the-cross-over-candle-1.jpg trying-to-define-the-cross-over-candle-1.jpg
    #202040 quote
    robertogozzi
    Moderator
    Master

    TRUE cannot be used that way, replace it with 1.

    Trader Sab thanked this post
Viewing 15 posts - 16 through 30 (of 39 total)
  • You must be logged in to reply to this topic.

Total Beginner


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Trader Sab @trader-sab Participant
Summary

This topic contains 38 replies,
has 6 voices, and was last updated by GraHal
3 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/03/2022
Status: Active
Attachments: 27 files
Logo Logo
Loading...