StopLoss not executing correctly - futures io
futures io



StopLoss not executing correctly


Discussion in EasyLanguage Programming

Updated
    1. trending_up 1,195 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 2 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 150,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
 

StopLoss not executing correctly

(login for full post details)
  #1 (permalink)
thinkorn00b
stavanger
 
 
Posts: 12 since Sep 2020
Thanks: 1 given, 1 received

Hi
So I have this code that should stop me out x number of cents above HOD. However it seems like if the candle that breaks HOD doesn't have a price within the number of cents I set above HOD, then it waits several candles before it triggers at a much higher price. I need the code to trigger exactly when the condition is.(Not taking into account slippage with realtime data) this is from backtesting the code on AMC from 09.27.22 :

Ex1:
Stop price is set at 2 cents above HOD (7.37). Here it stops me out at 7.39 (which it should, since its 2 cents above HOD (this is also the highest price of the same candle that breaks HOD):





Ex2:
Stop price is set at 3 cents above HOD (7.37). Here it stops me out at 7.46, 3 candles after it breaks HOD. It should have stopped me out at next candle at 7.4:



here is the code:
 
Code
Stoplosspricechng =  (highD(0)+0.03) - entryprice;
If I use int (to force it to be a integer) the same thing happens.
Anyone know what's going on?

Reply With Quote

Can you help answer these questions
from other members on futures io?
IKYP - How I solved email troubles on VPS
NinjaTrader
Reaching Customer Service
NinjaTrader
Asking Wall Street Billionaire for Investment Advice
Psychology and Money Management
 
 
(login for full post details)
  #2 (permalink)
 ABCTG   is a Vendor
 
 
Posts: 2,355 since Apr 2013
Thanks: 425 given, 1,574 received

Hi thinkorn00b,

I would suggest checking the values within your code to make sure that they are what you expect them to be (either using the print reserved word or the debugger).

Your screenshot cuts some important pieces from the code, but it appears you might be evaluating SetStopLoss conditionally. Depending on the condition you are using this might be causing delays.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #3 (permalink)
thinkorn00b
stavanger
 
 
Posts: 12 since Sep 2020
Thanks: 1 given, 1 received


 
Code
										{STOP LOSS CODE}        	  
         	  
 // Stop Loss variables (above hod)
 Variables:
 			Stoplosspricechng (0),
 			int MP (0);
			
			
	//Stop loss code for variables:
			MP = Marketposition;
						
//Stop loss condition(criteria):			
If MP = -1  then
begin
	//The variable stoplosspricechng is set to the entryprice of the current short position minus the high of day
	// this value is updated each tick of the bar
	Stoplosspricechng =  (highD(0)+0.03) - entryprice;
	end;

begin
setstopshare;
if MP <> 0 then setstoploss(stoplosspricechng);
End;
The only condition is that the short market position is not equal to 0. It takes the high of day minus the entryprice and plus the 3 cents, so when the market position reach that amount it should stop me out.

Can this cause a delay of 3 bars?

Reply With Quote
 
(login for full post details)
  #4 (permalink)
 ABCTG   is a Vendor
 
 
Posts: 2,355 since Apr 2013
Thanks: 425 given, 1,574 received

thinkorn00b,

no, it should not. You are updating the stop with every higher high, though. Maybe you are simply moving the stop away and this is causing the delay.
I would suggest checking the values within your code to make sure that they are what you expect them to be (either using the print reserved word or the debugger).

Regards,

ABCTG


thinkorn00b View Post
 
Code
										{STOP LOSS CODE}        	  
         	  
 // Stop Loss variables (above hod)
 Variables:
 			Stoplosspricechng (0),
 			int MP (0);
			
			
	//Stop loss code for variables:
			MP = Marketposition;
						
//Stop loss condition(criteria):			
If MP = -1  then
begin
	//The variable stoplosspricechng is set to the entryprice of the current short position minus the high of day
	// this value is updated each tick of the bar
	Stoplosspricechng =  (highD(0)+0.03) - entryprice;
	end;

begin
setstopshare;
if MP <> 0 then setstoploss(stoplosspricechng);
End;
The only condition is that the short market position is not equal to 0. It takes the high of day minus the entryprice and plus the 3 cents, so when the market position reach that amount it should stop me out.

Can this cause a delay of 3 bars?


Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:
 
(login for full post details)
  #5 (permalink)
thinkorn00b
stavanger
 
 
Posts: 12 since Sep 2020
Thanks: 1 given, 1 received

Hi, I counted the number of cents its above the new candle that makes the new HOD, and it make sense to where it stopped out. Now I just have to find a way for it to stop out at correct price. I can either calculate it from the previous high of day, if there is such a function. OR I can:

(highD(0)-entryprice)*number of shares shorted = normal risk value (dollars)
+
(multiple the number of shares shorted with 5 cents = extra risk value)
=
Total dollar amount to lose

Then have a code to stop me out when total dollar amount is reached. I'm gone try that.

Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > StopLoss not executing correctly


Last Updated on October 1, 2022


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2022 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), 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