@cfta
Thanks for reply and info!
@Nicolas
Thanks for all the work you put into this!
@Everybody else
Thanks for ideas!
Ok guys, finally have some time to finish the system.
So orders basket will now exit with the floating profit curve cross below 2 standard deviation from its 20 period average. From my own test, things go well, of course this system needs a good first entry points. Also please consider that the risk reward ratio has to be set at about 3 or so to give “space” to the profit exit system to be correctly managed.. I found that adding orders in a good trend run is very powerful and can just make gigantic profit very fast, so if the “rr” variable is set to 1 then the profit exit system will be set to ON very soon and exit of orders will happen very fast.
The original system without exit is still good in this version, just set “rr” variable to 0 and nothing will happen for exiting positions.
Please find attached the whole code and pictures of the system with and without “BB exit system“.
This is an original money management code, but as you can see, we can build anything from just little imagination and knowledge, so this thing can evolve or can be totally changed to a whole new system. Your turn to find good use of this 🙂
Great work here guys! Many thanks for your efforts 🙂
Fantastic work ! Many thanks to all for their work and esp to Nicolas, you’re doing a great job and helping a lot of people here. This looks like being the start of a robust money and position management system that can benefit all. I am testing out different ideas with this and will post any interesting results here, would encourage everyone to do the same.
To all participants, I applaud the excellent result of a great team effort – thanks for the postings and the opportunity to learn from the masters.
I have tested it with the BB exit, on GBPJPY 5m chart from 18/5/16 at 20:30 AEST with a fabulous result: 578% for 8 hours exposure. I have the rr = 2.
I am finding that there are not many opportunities in the last few months where this could have been achieved in FX, as the trends haven’t lasted long enough. The retraces are firing the stop losses. But one profit like this will take care of 578 losses – so it is a Turtle Traders test of persistence.
My thoughts are that if the risk is increased to 2%, this may provide enough space for the minor retraces to pass without firing the stop losses, and so reach the target profit.
Or alternatively, if a trailing stop loss (equating to the risk) was used on the latest trade, any retracement will sacrifice the last trade, but the profit on the early trades would more than compensate. May I suggest that the grid step be set to say, 6 x ATR and the trailing stop at 2 x ATR.
I figure Nicolas is doing something like this with the money management and floating profit, but I don’t understand how the coding works.
I look forward to the experiences of others when testing this amazing system.
Hi,
I am very impressed with what has been going on here. However, I have tried the latest script ‘grid-orders-ctfa-with-BB-exit’ by importing the itf file, so I haven’t changed anything: it only does 1 trade at the start and then nothing more. It does this on EURO/USD, GBP/USD, CACA40 and it also doesn’t matter if I use a 1 min, 5 min or 15 min timeframe in the backtest. What could be wrong here?
Thank you very much for your advice and congratulations!
Glen
cftaParticipant
Senior
Thanks again Nicolas for your great work 🙂 Real time market testing begins today!
To all others, I’m very happy you appreciate my idea and suggest further improvements.
@ MikeGC, very good suggestions Mike that can definintely improve profitability and avoid being stopped out of trades before the trend starts, there is plenty of optimization which can be done for this system.
Hi everyone!
Congratulations for this fantastic job !!
@gforton I was trying the code shared and found that the first condition to join the market is set up with “strategyprofit=0” and this only occurs first time:
//first trade whatever condition
if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then
BUY amount LOT AT MARKET
endif
if NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 then
SELLSHORT amount LOT AT MARKET
endif
Change this to your conditions to enter and it will work fine, or just delete this part like this:
//first trade whatever condition
if NOT ONMARKET AND close>close[1] then
BUY amount LOT AT MARKET
endif
if NOT ONMARKET AND close<close[1] then
SELLSHORT amount LOT AT MARKET
endif
Have a nice day and better trading!!
Cheers!
Is it possible to have the final code and not the itf file.. i have an import problem ?
Thanks Nicolas!
Here is the code printed out:
defparam preloadbars = 100
once RRreached = 0
//parameters
accountbalance = 10000 //account balance in money at strategy start
riskpercent = 1 //whole account risk in percent%
gridstep = 50 //grid step in point
amount = 1 //lot amount to open each trade
rr = 5 //risk reward ratio (set to 0 disable this function)
//first trade whatever condition
if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then
BUY amount LOT AT MARKET
endif
if NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 then
SELLSHORT amount LOT AT MARKET
endif
// case BUY - add orders on the same trend
if longonmarket and close-tradeprice(1)>=gridstep*pipsize then
BUY amount LOT AT MARKET
endif
// case SELL - add orders on the same trend
if shortonmarket and tradeprice(1)-close>=gridstep*pipsize then
SELLSHORT amount LOT AT MARKET
endif
//money management
liveaccountbalance = accountbalance+strategyprofit
moneyrisk = (liveaccountbalance*(riskpercent/100))
onepointvaluebasket = pointvalue*countofposition
mindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksize
//floating profit
floatingprofit = ((close-positionprice)*pointvalue)*countofposition
MAfloatingprofit = average[20](floatingprofit)
BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*2
//floating profit risk reward check
if rr>0 and floatingprofit>moneyrisk*rr then
RRreached=1
endif
//GRAPH floatingprofit as "float"
//GRAPH RRreached as "rr"
GRAPH floatingprofit as "floating profit"
GRAPH BBfloatingprofit as "deviation of floating profit"
//stoploss trigger when risk reward ratio is not met already
if onmarket and RRreached=0 then
SELL AT positionprice-mindistancetoclose STOP
EXITSHORT AT positionprice-mindistancetoclose STOP
endif
//stoploss trigger when risj reward ratio has been reached
if onmarket and RRreached=1 then
if floatingprofit crosses under BBfloatingprofit then
SELL AT MARKET
EXITSHORT AT MARKET
endif
endif
//resetting the risk reward reached variable
if not onmarket then
RRreached = 0
endif
cftaParticipant
Senior
All right, so once again the code beats my knowledge, I don’t manage to run the system in real time because I get the error message;
“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.”
I managed to sort it in the previous version with some advice, in this version I tried to solve it the same way by cutting and pasting some of the lines to different sections of the code but I’m not able to fix it so please help me out you guys with better coding knowledge…
At least I remembered to delete the graph lines before running it real time 🙂
BTW has anyone managed to run it properly on JPY pairs yet? I have only had one entry order and then stopped out asap…
Sorry for this stupid bug.
Here is a quick fix just replace the lines 33 & 34 with these ones:
if onmarket then
onepointvaluebasket = pointvalue*countofposition
mindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksize
endif
@Mike
About ATR step instead of fixed one is clever. But, since we want to quickly make huge profit, I suggest to add more orders when the ATR is high and less when it is low. So when the ATR rise a lot in short period, it means that actual volatility can guarantee that a lot of grid orders can be launched to grow the floating profit. Then BB exit would take care of the rest. Of course, we are talking of backtest, live environment should not the exact same thing as market slippage can take its part into making trouble.
So a dynamic scale of the grid step could be coded, but it would be inverse of the ATR value. High ATR should mean minimal grid step and low ATR a larger one. Also, a minimal value of the grid step can be implemented.
Do you agree? everyone?
@simon_json
Hi Simon, I have just discovered your post re an ATR trailing stop – I couldn’t agree more. A long trend needs scope so the max profit can be achieved. The best way to do this is with a wide trailing stop but with the accompanying increased risk. This is the beauty of @cfta grid system – the profit does not rely on one trade.
@Nicolas
I agree re the order size but I am not so sure about the BB exit.
I have attached the results of a test trade on CADJPY that is mouth-watering. Goodbye 2:1, hello 10:1!
I’m afraid I butchered your code Nicolas and your money management and r:r control, cfta- many apologies.
The trailing stop in the test is the SuperTrend. As you may well know, it is based on the ATR. The formula for both………….
Super trend values are calculated as follows
Up = (HIGH + LOW) / 2 + Multiplier * ATR
Down = (HIGH + LOW) / 2 – Multiplier * ATR
When the change of trend occurs, the indicator flips
Average True Range is calculated as follows
Current ATR = [(Prior ATR x 13) + Current TR] / 14
– Multiply the previous 14-day ATR by 13.
– Add the most recent day’s TR value.
– Divide the total by 14
I have attached the butchered code – ugh, not very tidy but I don’t have the expertise to complete the money management nor the grid step – sorry.
defparam preloadbars = 100
//once RRreached = 0
//parameters
//accountbalance = 10000 //account balance in money at strategy start
//riskpercent = 1 //whole account risk in percent%
gridstep = 50 //grid step in point
amount = 1 //lot amount to open each trade
//rr = 0 //risk reward ratio (set to 0 disable this function)
ST = SuperTrend[3.2,22]
//first trade whatever condition
if NOT ONMARKET AND close>close[1] AND STRATEGYPROFIT=0 then
BUY amount LOT AT MARKET
endif
if NOT ONMARKET AND close<close[1] AND STRATEGYPROFIT=0 then
SELLSHORT amount LOT AT MARKET
endif
// case BUY - add orders on the same trend
if longonmarket and close-tradeprice(1)>=gridstep*pipsize then
BUY amount LOT AT MARKET
endif
// case SELL - add orders on the same trend
if shortonmarket and tradeprice(1)-close>=gridstep*pipsize then
SELLSHORT amount LOT AT MARKET
endif
//SuperTrend stop loss
if close > ST THEN
EXITSHORT AT MARKET
ENDIF
//money management
//liveaccountbalance = accountbalance+strategyprofit
//moneyrisk = (liveaccountbalance*(riskpercent/100))
//onepointvaluebasket = pointvalue*countofposition
//mindistancetoclose =(moneyrisk/onepointvaluebasket)*ticksize
//floating profit
//floatingprofit = ((close-positionprice)*pointvalue)*countofposition
//MAfloatingprofit = average[20](floatingprofit)
//BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*2
//floating profit risk reward check
//if rr>0 and floatingprofit>moneyrisk*rr then
//RRreached=1
//endif
//GRAPH floatingprofit as "float"
//GRAPH RRreached as "rr"
//GRAPH floatingprofit as "floating profit"
//GRAPH BBfloatingprofit as "deviation of floating profit"
//stoploss trigger when risk reward ratio is not met already
//if onmarket and RRreached=0 then
//SELL AT positionprice-mindistancetoclose STOP
//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
//SELL AT MARKET
//EXITSHORT AT MARKET
//endif
//endif
//resetting the risk reward reached variable
//if not onmarket then
//RRreached = 0
//endif