Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Hello friends. This is my first time on the forum but I have searched extensively on the internet and the forum for a sample implementation of a stop/reverse strategy in EasyLanguage but have had no luck in finding some currently usable sample code. Here is what I want to do in words:
1. I want to enter a trade either long or short at a fixed time every day, at let's say BeginTime = 0830. The direction of the entry is based on some method EnterLong() which will decide (based on a combination of indicators and daily qualitative analysis) which direction I'm entering.
2. The moment that the trade is entered, I want a fixed stop-loss in the opposite direction of let's say StopLossAmt = 0.20, with a profit target that is set every day but determined at the beginning of the day according to a static variable ProfitTargetForDay = GetProfitTarget() If the profit target is met for the day, exit the trade and stop trading for the day. If the stop loss is reached, immediately exit the trade (incurring the 0.20 loss) and enter a new trade in the same direction as the stop-loss (hence the stop & reverse strategy).
3. Once a trade is reentered in the opposite direction, the same conditions hold except the direction of the profit target and the stop loss are now opposite to what they were in the trade before.
4. Say I want a maximum of NumStops = 5 to occur during the day, after which the strategy is done excuting for the day and the 0.20 * 5 = 1.00 total loss is incurred for the day.
5. If we get to a certain time for the day at let's say EndTime = 1600 and neither the profit target has been met in any direction or the 5 stops have been hit, we immediately liquidate whatever contracts are still live, incurring either a gain or loss depending on where the ticker is relative to our last trade entry.
Also, the strategy should operate using intra-bar settings for both backtesting and live orders.
Here is my attempt:
It seems to work properly for some days, and then other days it goes haywire and trades way more than the number of stops that I have programmed in. I cannot figure out what is going wrong. There is probably a couple of coding errors and such throughout, so if anyone could help point out the errors it would be much appreciated. Thanks!
Can you help answer these questions from other members on NexusFi?
I would suggest taking a look at the NumStops variable values using the print command or the Debugger. Check if it gets incremented when you think it should and also check its values at the moment you issue new orders.
This should tell you what is going on internally and help you to get to the problem.
to check if the incremental of a value was correct (like your numStops) is working correcltly and the only way is using print command to check values...
Anyway maybe you can build your code using EntriesToday(date) and by checking the Last position profit ...