NexusFi: Find Your Edge


Home Menu

 





StopLoss not executing correctly


Discussion in EasyLanguage Programming

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




 
Search this Thread

StopLoss not executing correctly

  #1 (permalink)
thinkorn00b
stavanger
 
Posts: 19 since Sep 2020
Thanks Given: 1
Thanks Received: 1

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 NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Futures True Range Report
The Elite Circle
Build trailing stop for micro index(s)
Psychology and Money Management
Better Renko Gaps
The Elite Circle
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

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
  #3 (permalink)
thinkorn00b
stavanger
 
Posts: 19 since Sep 2020
Thanks Given: 1
Thanks Received: 1


 
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
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

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
Thanked by:
  #5 (permalink)
thinkorn00b
stavanger
 
Posts: 19 since Sep 2020
Thanks Given: 1
Thanks Received: 1

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




Last Updated on October 1, 2022


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts