Grid orders with one combined stop loss and limit, can it be done?
Forums › ProRealTime English forum › ProOrder support › Grid orders with one combined stop loss and limit, can it be done?
- This topic has 307 replies, 1 voice, and was last updated 7 months ago by OtherAttorney.
-
-
05/11/2016 at 9:33 AM #6775
Hi guys!
This code looks really interesting and I’m following your work and progress since I think proper money management is a key to profitable trading.
Just a thought on the 1% stoploss. As it is coded now newSL = positionprice – (positionprice*0.99) doesn’t it just calculate the difference between the positionprice and the new sl? Shouldn’t it just be newSL = positionprice*0.99?
05/11/2016 at 9:57 AM #6779This code states:
make the New Stop Loss = POSITIONPRICE (being the average of the Positions Price(s) – 1% of the Average Position Price(s))
Lets say the Position Prices are:
95 + 100 +105 = 300
300/3 = 100
newSL = 100 – (100*0.99)
newSL = 100 – 99
newSL = 1 (which is 1% of 100)
If understand it correctly.
05/11/2016 at 12:46 PM #6799Thanks for your help.
Yes It were that I thought at the first glance, but since we want to exit at 1% loss of the account balance, it’s not it 🙂
So now tests are good, I coded the sell side version and made a small fixed for forex pairs. Here is the full code (also attached in itf file to this post):
12345678910111213141516171819202122232425262728293031323334353637383940defparam preloadbars = 0//parametersaccountbalance = 10000 //account balance in money at strategy startriskpercent = 1 //whole account risk in percent%gridstep = 20 //grid step in pointamount = 1 //lot amount to open each trade//first trade whatever conditionif NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 thenBUY amount LOT AT MARKETendifif NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 thenSELLSHORT amount LOT AT MARKETendif// case BUY - add orders on the same trendif longonmarket and close-tradeprice(1)>=gridstep*pipsize thenBUY amount LOT AT MARKETendif// case SELL - add orders on the same trendif shortonmarket and tradeprice(1)-close>=gridstep*pipsize thenSELLSHORT amount LOT AT MARKETendif//money managementliveaccountbalance = accountbalance+strategyprofitmoneyrisk = (liveaccountbalance*(riskpercent/100))onepointvaluebasket = pointvalue*countofpositionmindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsize//GRAPH mindistancetoclose as "d"//stoploss triggerif onmarket thenSELL AT positionprice-mindistancetoclose STOPEXITSHORT AT positionprice-mindistancetoclose STOPendifPlease don’t leech it only. Instead, please add comments or any ideas that would improve a strategy or create a new one with this code. There are many brainful traders here and i’m pretty sure that we can make something cool all together with this nice money management idea 🙂
05/11/2016 at 5:10 PM #681705/11/2016 at 8:54 PM #683905/11/2016 at 9:52 PM #6842I’m afraid I have already come across some trouble, when I try to run the code in real time market I get this error message and the system is stopped;
“This trading system was stopped due to a division by zero during the evaluation of the last candlestick. Please add protections to your code to prevent divisions by zero.”
This is the code I was using, tried both long and short and with or without the graph line;
12345678910111213141516171819202122232425262728293031//-------------------------------------------------------------------------// Main code : Grid Short Nicolas//-------------------------------------------------------------------------defparam preloadbars = 0//parametersaccountbalance = 10000 //account balance in money at strategy startriskpercent = 1 //whole account risk in percent%gridstep = 20 //grid step in pointamount = 1 //lot amount to open each trade//first trade whatever conditionif NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 thenSELLSHORT amount LOT AT MARKETendif// case SELL - add orders on the same trendif shortonmarket and tradeprice(1)-close>=gridstep*pipsize thenSELLSHORT amount LOT AT MARKETendif//money managementliveaccountbalance = accountbalance+strategyprofitmoneyrisk = (liveaccountbalance*(riskpercent/100))onepointvaluebasket = pointvalue*countofpositionmindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsize//stoploss triggerif onmarket thenEXITSHORT AT positionprice-mindistancetoclose STOPendifAny idea what might be the problem?
05/12/2016 at 8:36 AM #6856Ahahah
“division by zero” is something that ProBacktest don’t know apparently 🙂
Well, if you have set correctly the line 7 to 10 (no zero values), the problem is in line 26 (this is the only code line with a division).
A quick fix would be, move the line 26 into the “//stoploss trigger” function, like this:
12345//stoploss triggerif onmarket thenmindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsizeEXITSHORT AT positionprice-mindistancetoclose STOPendifThat would make the trick.
05/12/2016 at 11:32 AM #6867Great work! This is fun! 🙂
Question: Is it possibile to add a breakeven function, and a stop loss that moves up when the orders are in profit?I thought the code:
1liveaccountbalance = accountbalance+strategyprofitwould do that, but it seems like the stop loss don’t take the profit (from the orders) into calculation? But only start account balace?
So maybe a breakeven function, and a stop loss that moves up when the orders are in profit based on equity curve?
I have tried this but can’t make it right.
Or will this behave differently in real market?
All the best!
05/12/2016 at 11:43 AM #6870Yes, everything’s possible.
Actually, the code don’t calculate the floating profit. The code do actually exactly what cfta wanted and there’s no any ‘takeprofit’ system in it. I already have some ideas for that based on the live equity curve as you mentioned it.
Firstly I would like to find a mechanical way to enter the market for this system, that would be fun 🙂 Any idea?
05/12/2016 at 12:31 PM #6872Nice Nicolas!
Yes, I have thought and tried a few things 🙂
My conclustion was that maybe it isn’t nessesarily because of the 1% account stop loss.Otherwise my best suggestions is:
a) Entry based on pricemove:
123456789101112// Conditions to enter long and short positionsgridstep1=x//first trade whatever conditionif NOT ONMARKET AND close-tradeprice(1)>=gridstep1*pipsize thenBUY amount LOT AT MARKETendifif NOT ONMARKET AND tradeprice(1)-close>=gridstep1*pipsize thenSELLSHORT amount LOT AT MARKETendifb) “Good old turtle fashion” (on 5min TF):
1234567891011121314// Conditions to enter long positionsc1 = (close=Highest[600](close))// Conditions to enter short positionsc2 = (close=Lowest[600](close))//first trade whatever conditionif NOT ONMARKET AND c1 thenBUY amount LOT AT MARKETendifif NOT ONMARKET AND c2 thenSELLSHORT amount LOT AT MARKETendifc) I have also tried MA, but don’t like it:
12345678910111213141516// Conditions to enter long positionsindicator1 = WilderAverage[40](close)indicator2 = WilderAverage[40](close)c1 = (indicator1 > indicator2[1])// Conditions to enter shortpositionsc2 = (indicator1 < indicator2[1])//first trade whatever conditionif NOT ONMARKET AND c1 thenBUY amount LOT AT MARKETendifif NOT ONMARKET AND c2 thenSELLSHORT amount LOT AT MARKETendifBut as said, maybe this is not nessisarily, or maybe a “mini-turtle” is enough :
1c1 = (close=Highest[200](close))I also think its important that I don’t “cut” this thread from cfta, since he started it 🙂
05/12/2016 at 12:33 PM #6873I think cfta described a breakeven and moving stoploss here:
05/12/2016 at 1:21 PM #6880You are right. I’ll code floating profit of the whole orders basket and then we’ll can move stoploss accordingly to x% profit.
About entries, breakout of recent highs or lows is clever. However, I think that we should introduce another trigger like recent volatility.
05/12/2016 at 1:52 PM #6891Hi Nicolas and cfta!
Nice work so far. Really interesting.
Can this grid order code be combined with any of the 15-min Breakout-systems in the library for a daytrading system? With gridsteps and riskpercent adjusted to the market traded? And perhaps flat after market close?
05/12/2016 at 2:13 PM #689305/13/2016 at 7:25 AM #6951Good morning fellows,
I had a very long day at my regular old school job yesterday so I didn’t have time for posting but I did some testing remotely. I’m thrilled to see all the suggestions for further developement, a stop loss triggered by trend change, by MA cross, stochastics, ADX or whatever is the most effective is of course a great way to maximize profits.
For the real market testing everything looks well, entries where taken as intended and the SL worked perfectly. Great job Nicolas!
I’ll stay in the mix for discussing further improvements…
-
AuthorPosts
Find exclusive trading pro-tools on