Need help with simple stop/reverse strategy - futures io
futures io futures trading



Need help with simple stop/reverse strategy


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one ABCTG with 1 posts (0 thanks)
    2. looks_two flaaghara with 1 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 Dvdkite with 1 posts (0 thanks)
    1. trending_up 1,248 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Need help with simple stop/reverse strategy

(login for full post details)
  #1 (permalink)
NY, NY
 
 
Posts: 1 since May 2018
Thanks: 0 given, 0 received

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:

 
Code
If (time = BeginTime AND NumStops = 0) then begin
	EntryDirection = EnterLong();
	ProfitTargetForDay = GetProfitTarget(); 

	If EntryDirection then begin
		Buy ("Long Entry") NumContracts contracts next bar at Market;
		MorningEntry = EntryPrice;
	end
	Else begin
		SellShort ("Short Entry") NumContracts contracts next bar at Market;
		MorningEntry = EntryPrice;
	end;
end;

If time = EndTime then begin
	NumStops = 0;
	If MarketPosition = 1 then
		Sell ("Long Timed Exit") NumContracts contracts next bar at Market;
	If MarketPosition = -1 then
		BuyToCover ("Short Timed Exit") NumContracts contracts next bar at Market;
end;


If (time >= BeginTime AND time < EndTime AND MarketPosition = 1 AND NumStops <= 5) then begin
	Sell ("Take Profit Long") NumContracts contracts next bar at MorningEntry + ProfitTargetForDay Limit;
	Sell ("Stop Loss Long") NumContracts contracts next bar at MorningEntry - StopLossAmt Stop;
end;

If (time >= BeginTime AND time < EndTime AND MarketPosition = -1 AND NumStops <= 5) then begin
	BuyToCover ("Take Profit Short") NumContracts contracts next bar at MorningEntry - ProfitTargetForDay Limit;
	BuyToCover ("Stop Loss Short") NumContracts contracts next bar at MorningEntry + StopLossAmt Stop;
end;

If (time >= BeginTime AND time < EndTime AND MarketPosition = 0 AND MarketPosition(1) = 1 AND ExitPrice(1) < EntryPrice(1) AND NumStops <= 5) then begin
	SellShort ("Short Reversal") NumContracts contracts next bar at Market;
	NumStops +=1;
end;

If (time >= BeginTime AND time < EndTime AND MarketPosition = 0 AND MarketPosition(1) = -1 AND ExitPrice(1) > EntryPrice(1) AND NumStops <= 5) then begin
	Buy ("Long Reversal") NumContracts contracts next bar at Market;
	NumStops +=1;
end;
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!

Reply With Quote

Can you help answer these questions
from other members on futures io?
Which kind of Blockvolume is visible? - order processing
Emini and Emicro Index
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
What blockvolume is visible? - order processing
NinjaTrader
Short Interest Ratio indicator?
ThinkOrSwim
Automatic pattern research with NT
Elite Algorithmic NinjaTrader Trading
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Selling Options on Futures?
109 thanks
Battlestations: Show us your trading desks!
108 thanks
Rank your Futures vs Stocks trading priority
55 thanks
Want your NinjaTrader indicator created, free?
27 thanks
Whats this confusion with margins?
21 thanks
 
(login for full post details)
  #3 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received


flaaghara,

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.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #4 (permalink)
Trieste Italy
 
 
Posts: 159 since Feb 2018
Thanks: 129 given, 20 received

Hello,

In some of my test I've found useful also using
 
Code
EntriesToday(date)
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 ...

Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Need help with simple stop/reverse strategy


Last Updated on May 15, 2018


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts