ProRealCode - Trading & Coding with ProRealTime™
HA indicator incoming
//Heikin-Ashi
xClose = (Open+High+Low+Close)/4
if(barindex>2) then
xOpen = (xOpen[1] + xClose[1])/2
endif
changeToGreencandle = xClose>xOpen AND xClose[1]<xOpen[1]
ChangeToRedcandle = xClose<xOpen AND xClose[1]>xOpen[1]
Greencandle=xclose>xopen
redcandle=xclose<xopen
If changeToGreencandle then
Indicator1=1
elsif greencandle then
indicator1=0.5
Else
Indicator1=0
Endif
If ChangeToRedcandle then
Indicator22=-1
elsif redcandle then
indicator22=-0.5
Else
Indicator22=0
Endif
Return indicator1 COLOURED(0,255,0) as "Buy", indicator22 COLOURED(255,0,0) as "Sell"
🙂
Good afternoon, I’m a beginner.
Could someone put the final system? It seems interesting. Thank you
Hi Iramirez and welcome to the thread 🙂
There is no final version yet since the system is still under developement but the current verions is on the previous page;
Grid orders with one combined stop loss and limit, can it be done?
I don’t recommend this system for beginners but everyone is free to use it but make sure you do your homework on it and pay attention to if cumulative orders are allowed or not.
For all other followers I’m currently working on an alternate entry method and possibly another CTFTA indicator to facilitate setting alerts for setups.
Hey fellows,
It’s been quite a while since the last update here. I have been working on an alternate entry and exit version of the strategy which is better suited for the low volatility and slow markets we have been seeing for the most part of the last few months. This version is aiming at getting 25-100 pips per trade so we still need to catch a decent move but often we will get out quickly with a very small loss, since the entry signal is Heiken Ashi changing color we need to run it on a higher TF than the other verions of the system, I have focused on M15 mainly but it can be run on M5 or H1 as well. The entry filter is directional movement (25) and ADX (25), these values are discretionary depending on the TF.
However I only run it when I can keep an eye on the markets the market can travel many pips the wrong way in 15 mins, hence I also recommend turning off cumulative orders or set a low amount of maximum entries to 3 or 5.
In order for it to work you will need the below HA Change indicator (a modified version of the one Kasper provided);
//Heikin-Ashi
xClose = (Open+High+Low+Close)/4
if(barindex>2) then
xOpen = (xOpen[1] + xClose[1])/2
endif
changeToGreencandle = xClose>xOpen AND xClose[1]<xOpen[1]
ChangeToRedcandle = xClose<xOpen AND xClose[1]>xOpen[1]
Greencandle=xclose>xopen
redcandle=xclose<xopen
If changeToGreencandle then
Indicator1=1
elsif greencandle then
indicator1=0.5
elsif Changetoredcandle then
indicator1=-1
elsif redcandle then
indicator1=-0.5
Else
Indicator1=0
Endif
Return indicator1
Long;
/// Definition of code parameters
defparam preloadbars =10000
DEFPARAM CumulateOrders = true // Cumulating positions deactivated
AAA= ADX [25]
DIM= DI[25]
HAC= call "HA Change"
once RRreached = 0
accountbalance = 10000 //account balance in money at strategy start
riskpercent = 1 //whole account risk in percent%
amount = 1 //lot amount to open each trade
rr = 1 //risk reward ratio (set to 0 disable this function)
sd = 0.25 //standard deviation of MA floating profit
//dynamic step grid
minSTEP = 5 //minimal step of the grid
maxSTEP = 30 //maximal step of the grid
ATRcurrentPeriod = 150 //recent volatility 'instant' period
ATRhistoPeriod = 3000 //historical volatility period
ATR = averagetruerange[ATRcurrentPeriod]
histoATR= highest[ATRhistoPeriod](ATR)
resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)
resultMIN = MIN(resultMAX,maxSTEP*pipsize)
gridstep = (resultMIN)
// Conditions to enter long positions
c1 = (AAA > 10)
c2 = (DIM > 0)
c3 = (HAC = 1)
//first trade whatever condition, for one cycle only add "AND STRATEGYPROFIT=0" on line 39.
if NOT ONMARKET AND (c1)=1 AND (c2)=1 AND (c3)=1 AND close>close[1] then
BUY amount LOT AT MARKET
endif
// case BUY - add orders on the same trend
if longonmarket and close-tradeprice(1)>=gridstep then
BUY amount LOT AT MARKET
endif
//money management
liveaccountbalance = accountbalance+strategyprofit
moneyrisk = (liveaccountbalance*(riskpercent/100))
if onmarket then
onepointvaluebasket = pointvalue*countofposition
mindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsize
endif
//floating profit
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
//actual trade gains
MAfloatingprofit = average[20](floatingprofit)
BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*sd
//floating profit risk reward check
if rr>0 and floatingprofit>moneyrisk*rr then
RRreached=1
endif
//stoploss trigger when risk reward ratio is not met already
c4 = (HAC = -1)
if onmarket and (c4)=1 then
SELL AT MARKET
endif
if onmarket and RRreached=0 then
SELL AT positionprice-mindistancetoclose STOP
endif
//stoploss trigger when risk reward ratio has been reached
if onmarket and RRreached=1 then
if floatingprofit crosses under BBfloatingprofit then
SELL AT MARKET
endif
endif
//resetting the risk reward reached variable
if not onmarket then
RRreached = 0
endif
Short
/// Definition of code parameters
defparam preloadbars =10000
DEFPARAM CumulateOrders = true // Cumulating positions deactivated
AAA= ADX [25]
DIM= DI[25]
HAC= call "HA Change"
once RRreached = 0
accountbalance = 100000 //account balance in money at strategy start
riskpercent = 1 //whole account risk in percent%
amount = 1 //lot amount to open each trade
rr = 1 //risk reward ratio (set to 0 disable this function)
//sd = 0.25 //standard deviation of MA floating profit
//dynamic step grid
minSTEP = 5 //minimal step of the grid
maxSTEP = 30 //maximal step of the grid
ATRcurrentPeriod = 150 //recent volatility 'instant' period
ATRhistoPeriod = 3000 //historical volatility period
ATR = averagetruerange[ATRcurrentPeriod]
histoATR= highest[ATRhistoPeriod](ATR)
resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)
resultMIN = MIN(resultMAX,maxSTEP*pipsize)
gridstep = (resultMIN)
// Conditions to enter short positions
c11 = (AAA > 10)
c12 = (DIM < 0)
c13 = (HAC = -1)
//first trade whatever condition, for only one cycle add "AND STRATEGYPROFIT=0" on line 39.
if NOT ONMARKET AND (c11)=1 AND (c12)=1 AND (c13)=1 AND close<close[1] then
SELLSHORT amount LOT AT MARKET
endif
// case SELL - add orders on the same trend
if shortonmarket and tradeprice(1)-close>=gridstep then
SELLSHORT amount LOT AT MARKET
endif
//money management
liveaccountbalance = accountbalance+strategyprofit
moneyrisk = (liveaccountbalance*(riskpercent/100))
if onmarket then
onepointvaluebasket = pointvalue*countofposition
mindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsize
endif
//floating profit
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
//actual trade gains
MAfloatingprofit = average[200](floatingprofit)
BBfloatingprofit = MAfloatingprofit - std[200](MAfloatingprofit)//*sd
//floating profit risk reward check
if rr>0 and floatingprofit>moneyrisk*rr then
RRreached=1
endif
c14 = (HAC > 0)
if c14 then
EXITSHORT AT MARKET
endif
//stoploss trigger when risk reward ratio is not met already
if onmarket and RRreached=0 then
EXITSHORT AT positionprice-mindistancetoclose STOP
endif
//stoploss trigger when risk reward ratio has been reached
if onmarket and RRreached=1 then
if floatingprofit crosses under BBfloatingprofit then
EXITSHORT AT MARKET
endif
endif
//resetting the risk reward reached variable
if not onmarket then
RRreached = 0
endif
I hope you will enjoy it and find room for improvements 🙂
Hello Brains
could help me with the following request:
https://www.prorealcode.com/topic/request-of-money-management-for-a-grid-strategy/
Thanks in advance
Ale
Kasper, have you tried the latest code with HA entry and exit? It seems very promising when limiting the number of entries and running it on M15 or H1 but I’m looking for a way to filter out the sideways movement but it’s tricky to find a good one, I have been experimenting with Keltner and Donchian but no major progress yet. I’m hoping you may have some suggestions 🙂
Hi. I just tried the long version on DAX 15m TF .I have made the indicator and named it “HA Change”
So it runs as an automated strategy and I can see that it continues, but it’s not profitable- properly as mentioned because of sideways marked.
I have been trying to figure out what to do the code, and I got stuck. I have no idea of what to do, other that wait until multiframe support.
I have also tried to incorporate the grid code into Reiners Pathfinder, but it can not be done. it either ruins the pathfinder profit or change it so much that it’s not pathfinder anylonger. Mainly because that grid order are keeping a thight MM strategy of only trading for 1% of the account, which Pathfinder does not.
We could try and give the ALE code a shoot.
Well it is coded as an automated strategy but just as with the other versions of my strategies we need to pick and choose the period to start it when we have the right setup and stop it when we are happy with our profits or the setup has disappeared. If we expect an up move on DAX on Monday we start the strategy on Monday morning and keep an eye on it and the price action during the day.
Indeed MTF support would make a huge difference with more precise entries and a stoploss ready to kick in right away when a retrace occurs rather than at the close of each 15m candle, do think there is a chance that we can change the code in the HA Change to reflect a higher TF, for instance running it on 5m with the changes of 15m? I know I have asked the question before but perhaps we have found new answers since last time it was asked.
I will look inte Ale’s code more and give it a shot too, it has a lot of potential for the ranging markets we have been seeing lately.
Thanks for your feedback Kasper 🙂
Hey traders,
Long time no speak, I have been waiting for MTF to become available but it seem to take longer and longer.
However here is an early christmas gift. The below update is fairly useful on low-medium timframes such as M15 but when using aggregating orders (of course we can stick with single orders too) we need to run it on low TF such as M1 or lower to be able to rely on our SL or BB exit since it kicks in at close of candle and too much can happen during a M15 candle and cause much larger losses during the 15 minutes it takes for the candle too close hence I recommend setting a low maximum number of orders and monitor the system manually while it is up and running.
The update is based on Squeeze (from BB Squeeze but only the squeeze function and not the momentum) and Heiken Ashi. Squeeze need to be off (blue bar) and Heiken Ashi decide the direction of the trade either by change of color or by the current color when Squeeze changes to off (for change of color “HAC crosses over 0” and for current direction “HAC >0” for long) on line 31.
First the required indicators, HA Change;
//Heikin-Ashi
xClose = (Open+High+Low+Close)/4
if(barindex>2) then
xOpen = (xOpen[1] + xClose[1])/2
endif
changeToGreencandle = xClose>xOpen AND xClose[1]<xOpen[1]
ChangeToRedcandle = xClose<xOpen AND xClose[1]>xOpen[1]
Greencandle=xclose>xopen
redcandle=xclose<xopen
If changeToGreencandle then
Indicator1=1
elsif greencandle then
indicator1=0.5
elsif Changetoredcandle then
indicator1=-1
elsif redcandle then
indicator1=-0.5
Else
Indicator1=0
Endif
Return indicator1
And Squeeze;
// Bollinger bands
source = close
bbMa = Average[bbLength](source)
dev = bbMult * STD[bbLength](source)
bbUpper = bbMa + dev
bbLower = bbMa - dev
// Keltner channels
kcMa = Average[kcLength](source)
kcRange = TR(source)
kcMaRange = Average[kcLength](kcRange)
kcUpper = kcMa + kcMaRange * kcMult
kcLower = kcMa - kcMaRange * kcMult
// Squeeze indicator
if bbLower > kcLower and bbUpper < kcUpper then
// Squeeze on
indicator1=-1
else
// Squeeze off
indicator1=1
endif
return indicator1
The strategy for longs;
/// Definition of code parameters
defparam preloadbars =10000
DEFPARAM CumulateOrders = true // Cumulating positions deactivated
SQ= call "Squeeze"[12, 1.5, 12, 1]
HAC= call "HA Change"
once RRreached = 0
accountbalance = 10000 //account balance in money at strategy start
riskpercent = 1 //whole account risk in percent%
amount = 1 //lot amount to open each trade
rr = 1 //risk reward ratio (set to 0 disable this function)
sd = 0.25 //standard deviation of MA floating profit
//dynamic step grid
minSTEP = 20 //minimal step of the grid
maxSTEP = 50 //maximal step of the grid
ATRcurrentPeriod = 150 //recent volatility 'instant' period
ATRhistoPeriod = 3000 //historical volatility period
ATR = averagetruerange[ATRcurrentPeriod]
histoATR= highest[ATRhistoPeriod](ATR)
resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)
resultMIN = MIN(resultMAX,maxSTEP*pipsize)
gridstep = (resultMIN)
// Conditions to enter long positions
c1 = (SQ > 0)
c2 = (HAC CROSSES OVER 0)
//first trade whatever condition, for one cycle only add "AND STRATEGYPROFIT=0" on lne 34
if NOT ONMARKET AND (c1)=1 AND (c2)=1 then
BUY amount LOT AT MARKET
endif
// case BUY - add orders on the same trend
if longonmarket and close-tradeprice(1)>=gridstep then
BUY amount LOT AT MARKET
endif
//money management
liveaccountbalance = accountbalance+strategyprofit
moneyrisk = (liveaccountbalance*(riskpercent/100))
if onmarket then
onepointvaluebasket = pointvalue*countofposition
mindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsize
endif
//floating profit
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
//actual trade gains
MAfloatingprofit = average[20](floatingprofit)
BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*sd
//floating profit risk reward check
if rr>0 and floatingprofit>moneyrisk*rr then
RRreached=1
endif
//stoploss trigger when risk reward ratio is not met already
if onmarket and RRreached=0 then
SELL AT positionprice-mindistancetoclose STOP
endif
//stoploss trigger when risk reward ratio has been reached
if onmarket and RRreached=1 then
if floatingprofit crosses under BBfloatingprofit then
SELL AT MARKET
endif
endif
//resetting the risk reward reached variable
if not onmarket then
RRreached = 0
endif
And shorts;
/// Definition of code parameters
defparam preloadbars =10000
DEFPARAM CumulateOrders = true // Cumulating positions deactivated
SQ= call "Squeeze"[12, 1.5, 12, 1]
HAC= call "HA Change"
once RRreached = 0
accountbalance = 10000 //account balance in money at strategy start
riskpercent = 1 //whole account risk in percent%
amount = 1 //lot amount to open each trade
rr = 2 //risk reward ratio (set to 0 disable this function)
sd = 0.25 //standard deviation of MA floating profit
//dynamic step grid
minSTEP = 20 //minimal step of the grid
maxSTEP = 50 //maximal step of the grid
ATRcurrentPeriod = 150 //recent volatility 'instant' period
ATRhistoPeriod = 3000 //historical volatility period
ATR = averagetruerange[ATRcurrentPeriod]
histoATR= highest[ATRhistoPeriod](ATR)
resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)
resultMIN = MIN(resultMAX,maxSTEP*pipsize)
gridstep = (resultMIN)
// Conditions to enter short positions
c11 = (SQ > 0)
c12 = (HAC CROSSES UNDER 0)
//first trade whatever condition, for only one cycle add "AND STRATEGYPROFIT=0" on line 34
if NOT ONMARKET AND (c11)=1 AND (c12)=1 then
SELLSHORT amount LOT AT MARKET
endif
// case SELL - add orders on the same trend
if shortonmarket and tradeprice(1)-close>=gridstep then
SELLSHORT amount LOT AT MARKET
endif
//money management
liveaccountbalance = accountbalance+strategyprofit
moneyrisk = (liveaccountbalance*(riskpercent/100))
if onmarket then
onepointvaluebasket = pointvalue*countofposition
mindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsize
endif
//floating profit
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
//actual trade gains
MAfloatingprofit = average[20](floatingprofit)
BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*sd
//floating profit risk reward check
if rr>0 and floatingprofit>moneyrisk*rr then
RRreached=1
endif
//stoploss trigger when risk reward ratio is not met already
if onmarket and RRreached=0 then
EXITSHORT AT positionprice-mindistancetoclose STOP
endif
//stoploss trigger when risk reward ratio has been reached
if onmarket and RRreached=1 then
if floatingprofit crosses under BBfloatingprofit then
EXITSHORT AT MARKET
endif
endif
//resetting the risk reward reached variable
if not onmarket then
RRreached = 0
endif
Remember to be mindful of line 34 to set or avoid recurring cycles, recurring is great for testing but risky for live trading, also note to increase most parameters if using on very low TF.
I hope you will find it useful 🙂
//BREAKOUT////////////////////////////////////////////////////////////////////////
K=highest[X](close) //IC*0.25
//FÖRVÄNTAD DAGLIG RÖRELSE (PROCENT) = INKÖP/STOP////////////////////////
DP=0.007
//AVSTÅND INKÖP MATTA / STOP////////////////////////////////////////////////
IC=((CLOSE*DP)/4)
BOMHAST=IC
//-------------------------------------------------------------------------
//graph close as "close"
//GRAPH K AS "BREAKOUT"
//GRAPH START AS "START"
//GRAPH IC AS "NORMALSPANN"
//GRAPH floatingprofit as "floating profit"
//GRAPH BBfloatingprofit as "BB Floating Profit"
//-------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////////
// Conditions to enter long positions
////////////////////////////////////////////////////////////////////////////////////////
//TREND INDI////////////////////////////////////////////////////////////////////////
TFC=1
indicator1 = dema[18*TFC](ROC[13*TFC](ExponentialAverage[1*TFC]))
indicator2 = dema[18*TFC](ROC[13*TFC](ExponentialAverage[1*TFC]))
c1 = (indicator1 > indicator2[1])
//SET STOP ORDER INDI////////////////////////////////////////////////////////////////////////
TFC2=15
indicator10 = dema[20*TFC2](ROC[25*TFC2](ExponentialAverage[1*TFC2]))
indicator20 = dema[20*TFC2](ROC[25*TFC2](ExponentialAverage[1*TFC2]))
c10 = (indicator10 > indicator20[1])
//c20 = (indicator10[1] < indicator20[2]) AND C20
IF c1 AND C10 AND NOT ONMARKET THEN
START=K
BUY 1 CONTRACT AT K STOP
BUY 1 CONTRACT AT CLOSE+K+BOMHAST STOP
BUY 2 CONTRACT AT CLOSE+K+(BOMHAST*2) STOP
//BUY 4 CONTRACT AT START+(BOMHAST*3) STOP
ENDIF
IF c1 AND COUNTOFPOSITION=1 THEN
BUY 1 CONTRACT AT START+BOMHAST STOP
BUY 2 CONTRACT AT START+(BOMHAST*2) STOP
//BUY 4 CONTRACT AT START+(BOMHAST*3) STOP
ENDIF
IF c1 AND COUNTOFPOSITION=2 THEN
BUY 2 CONTRACT AT START+(BOMHAST*2) STOP
//BUY 4 CONTRACT AT START+(BOMHAST*3) STOP
ENDIF
//IF c1 AND COUNTOFPOSITION=4 THEN
//BUY 4 CONTRACT AT START+(BOMHAST*3) STOP
//ENDIF
////////////////////////////////////////////////////////////////////////////////////////
// SAFETY STOPS MATTA
////////////////////////////////////////////////////////////////////////////////////////
// Stops and targets
if countofposition=1 then
SELL AT START-BOMHAST STOP
ENDIF
if countofposition=2 then
SELL AT START STOP
ENDIF
if countofposition=4 then
SELL AT START+BOMHAST STOP
ENDIF
//if countofposition=8 then
//SELL AT START+(BOMHAST*2) STOP
//ENDIF
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize
//actual trade gains
MAfloatingprofit = average[20](floatingprofit) //[ONMARKET]
BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*1.8//0.25
FPP= (BBfloatingprofit)/((pointvalue*countofposition/pipsize))+positionprice
if onmarket then
if FPP<CLOSE then
SELL AT FPP STOP
endif
ENDIF
GRAPH FPP AS "floatingprofit stop FPP"
//GRAPH floatingprofit AS "floatingprofit"
GRAPH CLOSE AS "Close"
Grid orders with one combined stop loss and limit, can it be done?
This topic contains 307 replies,
has 1 voice, and was last updated by OtherAttorney
1 year, 9 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 04/14/2016 |
| Status: | Active |
| Attachments: | 106 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.