Help with basic strategy

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #31813 quote
    dvdroversdvdrovers
    Participant
    New

    Hi,

    Was hoping someone could provide me with some code for a very simple strategy. I cant quite get the code to do what i want it to. below are the parameters;

    Trading on the major FX pairs (usd/jpy, eur/usd, gbp/usd etc)

    Daily bars

    If previous days bar was an up bar (open < close) then I want to sell on the previous days low

    If previous days bar was a down bar (open > close) then i want to buy on the previous days high

    stop will be 10 points

    limit/target will be 40

    If the limit or stop hasnt been hit during the trading day I want to exit on the close of that same day.

    Only want to trade from monday to friday, wary that there is a sunday bar on the FX due to it opening on sunday for a lot of the world (Im in Australia, opens 7am Monday)

    Ideally would like the backtesting to ignore the sunday bar

     

    Thanks for the help with this.

    #31872 quote
    NicolasNicolas
    Keymaster
    Legend

    Please find below a rough code that should work for your query. I didn’t test it, please make your own and give feedbacks, thank you.

    bull = dclose(0)>dopen(0)
    bear = dclose(0)<dopen(0)
    
    if day<>day[1]=0 then 
     alreadytraded=0
    endif
    
    if dayofweek>0 then 
    if not onmarket and bull and alreadytraded=0 then 
     sellshort 1 contract at dlow(0)
     alreadytraded=1
    endif
    
    if not onmarket and bear and alreadytraded=0 then 
     buy 1 contract at dhigh(0)
     alreadytraded=1
    endif
    endif
    
    set stop ploss 10
    set target pprofit 40
    
    #31890 quote
    GraHalGraHal
    Participant
    Master

    I played around with above and got attached results on DAX 100,000 bars @ 5 Min (cos I like 5 mins  TF 🙂

    Had to change code at Line 5, 10 and 15 to get it going  … rightly or wrongly?

    bull = dclose(0)>dopen(0)
    bear = dclose(0)<dopen(0)
    
    if day<>day[1] then
    alreadytraded=0
    endif
    
    if dayofweek>0 then
    if not onmarket and bull and alreadytraded=0 then
    sellshort 1 contract at dlow(0)stop
    alreadytraded=1
    endif
    
    if not onmarket and bear and alreadytraded=0 then
    buy 1 contract at dhigh(0)limit
    alreadytraded=1
    endif
    endif
    
    set stop ploss 100
    set target pprofit 80
    

    GraHal

    Nicolas.jpg Nicolas.jpg Nicolas-2.jpg Nicolas-2.jpg
    #31895 quote
    NicolasNicolas
    Keymaster
    Legend

    Well done Grahal, I should have tested my code!

    I think the order at line 15 should also be a stop one, we are buying higher, looking for a breakout.

    #31896 quote
    GraHalGraHal
    Participant
    Master

    Yeah I tried a stop at Line 15, attached are the results.

    I tried all combinations, with one eye on tv watching a film it’s easier (for me) to try stuff than work out if we’re trading higher or lower 🙂

    Nicolas-3.jpg Nicolas-3.jpg
    #31916 quote
    NicolasNicolas
    Keymaster
    Legend

    The backtest should be made on a daily timeframe, because the pending orders only last one bar in my code. I’m on my smartphone, can’t do it myself!

    #31924 quote
    GraHalGraHal
    Participant
    Master

    Nice one Nicolas!  Shut phone and brain off, sit in sun, get whiskey … you’re on holiday??

    WF Results for 1000 Daily bars,

    Daily Code:

    //https://www.prorealcode.com/topic/help-with-basic-strategy/
    //GH DCloseDOpen DAX 1D
    
    bull = dclose(0)>dopen(0)
    bear = dclose(0)<dopen(0)
    
    if day<>day[1] then
    alreadytraded=0
    endif
    
    if dayofweek>0 then
    if not onmarket and bull and alreadytraded=0 then
    sellshort 1 contract at dlow(0)stop
    alreadytraded=1
    endif
    
    if not onmarket and bear and alreadytraded=0 then
    buy 1 contract at dhigh(0)stop
    alreadytraded=1
    endif
    endif
    
    set stop ploss 160
    set target pprofit 780
    

    GraHal

    Nicolas-4.jpg Nicolas-4.jpg Nicolas-5.jpg Nicolas-5.jpg
    #31928 quote
    GraHalGraHal
    Participant
    Master

    Attached overall result for above code in tick-tick mode with no WF.

    Any ideas to increase % of winning trades?

    I can’t BT more than 1000 x Daily due to that annoying error message … one or more candles are not available … etc.   

    GraHal

    Nicolas-6.jpg Nicolas-6.jpg
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Help with basic strategy


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
dvdrovers @dvdrovers Participant
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by GraHalGraHal
9 years, 5 months ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 04/12/2017
Status: Active
Attachments: 6 files
ProRealCode ProRealCode
Loading...