Good work…. BUT… Why 10000 ? You only plan to use it on 5 digits only? What if you place on JPY pairs… or NonFX… your cream VALUE will fail. Also… Why use magic Numbers to Store a VALUE … use global variables …
Hi DannyBass, thank you for replying!
Well the 10k is to make the ATR into an int, otherwise i cant store it in the magic number. Im aware it creates a problem for the jpy pairs, but i could simply copy paste my EA into an JPY friendly version by changing the 10k into 1k (or 100, didnt fully check what pips were there). The main point in using magic numbers is because theyre persistent during the whole process.
Im totally into using more conventional methods, but apart from vaguely conceptualizing an array storing the ATR values at the time a trade is made and then somehow connecting the numbers in the array to the orders made.. i got nothing. Also, when i test my EA over 10 or 15 years its going to have a loooot of trades, not sure if that goes well with arrays, need to look into that.
I shouldve maybe said im just a crazy idiot writing while he discovers how all this beautiful coding stuff works, so if you have something more specific, like how i could use those global variables you mention, i'd be happy to hear what youre thinking.
I am using a similar code but I use percentage of TakeProfit to modify the order. The closing half orders is interesting. So you have half orders with a wider TakeProfit so that it's not closed when the TakeProfit price is hit?
Hi William William :)
Thanks for your reply! Actually i dont really set a take profit traditionally, i have my code check on every tick whether the price has reached the takeprofit that i want (which is also calculated on the ATR, now that i think of it i should probably stabilize that in the same way i did with the trailing stop) and then, since my volume of trades is 0.02, it takes of half of that, leaving a 0.01 order and slapping on a break even stoploss on the opening price. Then my trailing stop code check once per candle if it should stay or go up.
Basically the only thing i put on the order when i create it is the stoploss, the rest is done in realtime while the order runs. Static safetynet, but dynamic takeprofit and trailing stoploss i guess! :P
Using a percentage of the TakeProfit is hard for me, because i dont have one. And if i did it would close the whole order, like you implied.
Hi DannyBass, thank you for replying!
Well the 10k is to make the ATR into an int, otherwise i cant store it in the magic number. Im aware it creates a problem for the jpy pairs, but i could simply copy paste my EA into an JPY friendly version by changing the 10k into 1k (or 100, didnt fully check what pips were there). The main point in using magic numbers is because theyre persistent during the whole process.
Im totally into using more conventional methods, but apart from vaguely conceptualizing an array storing the ATR values at the time a trade is made and then somehow connecting the numbers in the array to the orders made.. i got nothing. Also, when i test my EA over 10 or 15 years its going to have a loooot of trades, not sure if that goes well with arrays, need to look into that.
I shouldve maybe said im just a crazy idiot writing while he discovers how all this beautiful coding stuff works, so if you have something more specific, like how i could use those global variables you mention, i'd be happy to hear what youre thinking.
Hi Dominik, Great feedback! Im going to look into that iTimeShift :D
Hi DannyBass, Haha yeah, i know.. Teachers teach because they dont do, right? ;) I've been studying this method for two years now, it seems to make sense. But im also looking into other strategies. So far i've taught myself to program because it seems really cool.. And to be honest im really appreciating the feedback! :D I will look more into both your feedback for sure!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all :)
Making my own EA according to the No Nonsense Forex method. One of the points in that method is to use a trailing stop based on the ATR score at the time of making the order.
My own code was taking the current ATR value instead (Timeframe daily). Largely because i couldnt find how to 'record' and hold the value in any way. The trailing stop worked perfectly - but the problem is that when volatility drops, the ATR usually drops too - and that made my trailing stops smaller (or bigger if the opposite happened). Not ideal.
old code:
(where AtrSlTs is 1.5)
my solution is a little convoluted so im including the whole chunk. Sorry if its hard to read :P
First when placing an order my code injects the current ATR value into the order as magic number. Had to convert to int, hence the MathFloor and *10000.
==============================================
==============================================
Then after the order reaches a take profit point (1*ATR) it closed half, after which point it becomes valid for the trailing stop function.
==============================================
==============================================
As you can see i simply extract the magic number and divide by 10000 again to get the pip value. The system then simply passes it as an OrderModify. The code nags about data conversion, which is fair, but it works!
Most of you will realize that this wont work for any pair that goes with the JPY, because the pips are different there. I could make a separate EA for those pairs, or just make a menu entry where you put in either which pair to trade or what the multiplication factor is. Those arent ideal, but thats how far i got with this idea.
I would love to hear what you think :) Have a nice day!
Edit: Changed my code sections with the code button. Didnt know that was a thing, still learning!