Quick Question – One order per day

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #7319 quote
    Cosmic1
    Participant
    Senior

    Hi, Great forum.

    I want to only have one order executed per day within my code, what is the easiest way to achieve this?

    #7323 quote
    Adolfo
    Participant
    Senior

    Hi Cosmic1,

    DEFPARAM CUMULATEORDERS = FALSE
    
    IF TIME=090000 THEN
    myLOT = 1
    ENDIF
    
    IF ONMARKET THEN
    myLOT = 0
    ENDIF
    
    IF NOT ONMARKET AND myConditions THEN
    BUY myLOT CONTRACT AT MARKET
    ENDIF
    
    

    Try it and let me know if works for you!

    Cheers

    Cosmic1 thanked this post
    #7327 quote
    Cosmic1
    Participant
    Senior

    Thanks for the quick reply. Unsure of how to get it to work within this code…

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM FLATAFTER = 160000
    
    // Conditions to enter long positions
    indicator1 = close
    indicator2 = BollingerDown[20](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF c1 AND HOUR >=08 AND HOUR <=15.5 THEN
    BUY 2 PERPOINT AT MARKET
    ENDIF
    
    
    // Conditions to enter short positions
    indicator5 = close
    indicator6 = BollingerUp[20](close)
    c3 = (indicator5 CROSSES OVER indicator6)
    
    IF c3 AND HOUR >=08 AND HOUR <=15.5 THEN
    SELLSHORT 2 PERPOINT AT MARKET
    ENDIF
    
    
    // Stops and targets
    SET STOP pLOSS 20
    SET TARGET pPROFIT 40
    //SET STOP TRAILING 4
    
    #7351 quote
    Nicolas
    Keymaster
    Master

    Hi, this is an usual question, we should made a code snippet for that within a blog article! 🙂

    Just flag whenever your first trade occur and reset this variable each new day. This variable must be also part of your conditional statement to launch a trade of course, here is your code with these modifications :

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM FLATAFTER = 160000
    
    //reset the variable each new day 
    if intradaybarindex = 0 then 
     alreadytraded = 0
    endif
    
    // Conditions to enter long positions
    indicator1 = close
    indicator2 = BollingerDown[20](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF c1 AND HOUR >=08 AND HOUR <=15.5 AND alreadytraded=0 THEN
     BUY 2 PERPOINT AT MARKET
     alreadytraded=1
    ENDIF
    
    
    // Conditions to enter short positions
    indicator5 = close
    indicator6 = BollingerUp[20](close)
    c3 = (indicator5 CROSSES OVER indicator6)
    
    IF c3 AND HOUR >=08 AND HOUR <=15.5 AND alreadytraded=0 THEN
     SELLSHORT 2 PERPOINT AT MARKET
     alreadytraded=1
    ENDIF
    
    
    // Stops and targets
    SET STOP pLOSS 20
    SET TARGET pPROFIT 40
    //SET STOP TRAILING 4
    Cosmic1 thanked this post
    #7358 quote
    Cosmic1
    Participant
    Senior

    Many thanks Nicolas.

    Another question is how do I enter trades x points above today high or low?

    #7389 quote
    Adolfo
    Participant
    Senior

    We start defining how many points

    x = 1*PipSize // Points above today high or under today low

    And then we set high and low of current day

    todayhigh = DHigh(0)
    todaylow = DLow(0)

    And last we set orders

    IF myconditions then
    buy 1 contract at todayhigh+x STOP
    sellshort 1 contract at todaylow-x STOP
    ENDIF
    Cosmic1 thanked this post
    #7390 quote
    Adolfo
    Participant
    Senior

    Your full code with this implement should be like this:

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM FLATAFTER = 160000
    
    // Parameters
    x = 1 * PipSize // Should be changed "1" to your desired number of pips.
    
    // Variables
    todayhigh = DHigh(0)
    todaylow = DLow(0)
    
    //reset the variable each new day 
    if intradaybarindex = 0 then 
     alreadytraded = 0
    endif
    
    // Conditions to enter long positions
    indicator1 = close
    indicator2 = BollingerDown[20](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    
    IF c1 AND HOUR >=08 AND HOUR <=15.5 AND alreadytraded=0 THEN
     BUY 2 PERPOINT AT todayhigh+x STOP
     alreadytraded=1
    ENDIF
    
    
    // Conditions to enter short positions
    indicator5 = close
    indicator6 = BollingerUp[20](close)
    c3 = (indicator5 CROSSES OVER indicator6)
    
    IF c3 AND HOUR >=08 AND HOUR <=15.5 AND alreadytraded=0 THEN
     SELLSHORT 2 PERPOINT AT todaylow-x STOP
     alreadytraded=1
    ENDIF
    
    
    // Stops and targets
    SET STOP pLOSS 20
    SET TARGET pPROFIT 40
    //SET STOP TRAILING 4
    Cosmic1 thanked this post
    #7424 quote
    Cosmic1
    Participant
    Senior

    Many thanks chaps, very helpful 🙂

    #7441 quote
    Cosmic1
    Participant
    Senior

    Another day another question! What is the correct way to scan the market for today’s high and low between set timeframes?

    #7447 quote
    Adolfo
    Participant
    Senior

    Hi Cosmic, we are talking about something like you ask here:

    http://www.prorealcode.com/topic/coding-for-high-and-low-between-set-hours/

    Have a look

    😉

    #7636 quote
    Cosmic1
    Participant
    Senior

    Hey Adolfo, Had a look but unsure of how to get this working.

    I want to look at the highest and lowest price for the range 1430-1700 for the current day.

    Then I will take a breakout of that range long or short on the same day.

    I have tried many things but cannot get it to work! Any help greatly appreciated.

    #7639 quote
    Cosmic1
    Participant
    Senior

    I think I may have it working, will let you know soon 🙂

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

Quick Question – One order per day


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Cosmic1 @cosmic1 Participant
Summary

This topic contains 11 replies,
has 3 voices, and was last updated by Cosmic1
9 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/19/2016
Status: Active
Attachments: No files
Logo Logo
Loading...