Hi, Great forum.
I want to only have one order executed per day within my code, what is the easiest way to achieve this?
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
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
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
Many thanks Nicolas.
Another question is how do I enter trades x points above today high or low?
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
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
Many thanks chaps, very helpful 🙂
Another day another question! What is the correct way to scan the market for today’s high and low between set timeframes?
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
😉
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.
I think I may have it working, will let you know soon 🙂