NexusFi: Find Your Edge


Home Menu

 





Need help with a stop loss based off a moving average value


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one kevinkdog with 10 posts (7 thanks)
    2. looks_two xxjoocexx with 7 posts (5 thanks)
    3. looks_3 vmodus with 5 posts (2 thanks)
    4. looks_4 ABCTG with 1 posts (2 thanks)
      Best Posters
    1. looks_one ABCTG with 2 thanks per post
    2. looks_two kevinkdog with 0.7 thanks per post
    3. looks_3 xxjoocexx with 0.7 thanks per post
    4. looks_4 vmodus with 0.4 thanks per post
    1. trending_up 6,778 views
    2. thumb_up 16 thanks given
    3. group 3 followers
    1. forum 22 posts
    2. attach_file 1 attachments




 
Search this Thread

Need help with a stop loss based off a moving average value

  #1 (permalink)
xxjoocexx
Akron, Oh
 
Posts: 8 since Oct 2021
Thanks Given: 3
Thanks Received: 5

Hey all. Brand new to Easy Language so don't be to harsh

What I'm trying to do:
I'm calculating Pivot Lows and a moving average on @ESH22 on a 5min chart. I would like to use the moving average value of the pivot low as a static stop loss.

This is what I'm using for Pivot calculation:
 
Code
inputs: 
	{Pivot low}
	Price( Low ) [DisplayName = "Price", ToolTip = 
	 "Enter an EasyLanguage expression to use for pivot low determination."], 
	LeftStrength( 2 ) [DisplayName = "LeftStrength", ToolTip = 
	 "Enter the number of bars to the left of the current bar to be analyzed to see if the price of those bars is greater than the price of the current bar."], 
	RightStrength( 2 ) [DisplayName = "RightStrength", ToolTip = 
	 "Enter the number of bars to the right of the current bar to be analyzed to see if the price of those bars is greater than the price of the current bar."],

If price > SlowAvg Then
Begin;

if PivotLowVS( 1, Price, LeftStrength, RightStrength, RightStrength + 1 ) <> -1 then
	Buy ( !( "PivLowEntry" ) ) next bar at market;
	
			End;
		End;
This part is fine. What I'm having trouble with is:
 
Code
if marketposition = 1 Then
	Begin;
	
	if Condition1 then SellStop = SlowAvg[3];
		 SetStopLoss(Sellstop);
				 
	End;
The entry executed as it should but the position was closed on the next candle at the same entry price. Another position was opened later in the day but then not closed at all like the previous position. So I'm kind of at a loss.

Any help or direction would be appreciated!

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

xxjoocexx,

welcome to futures.io. SetStopLoss is expecting a currency amount i.e. it places the stop Sellstop $ from the entry price in your case and does not seem to be the right choice for what you have in mind.
If you want to place orders at specific prices using actual stop orders is usually the better approach.

Regards,

ABCTG


xxjoocexx View Post
Hey all. Brand new to Easy Language so don't be to harsh

What I'm trying to do:
I'm calculating Pivot Lows and a moving average on @ESH22 on a 5min chart. I would like to use the moving average value of the pivot low as a static stop loss.

This is what I'm using for Pivot calculation:
 
Code
inputs: 
	{Pivot low}
	Price( Low ) [DisplayName = "Price", ToolTip = 
	 "Enter an EasyLanguage expression to use for pivot low determination."], 
	LeftStrength( 2 ) [DisplayName = "LeftStrength", ToolTip = 
	 "Enter the number of bars to the left of the current bar to be analyzed to see if the price of those bars is greater than the price of the current bar."], 
	RightStrength( 2 ) [DisplayName = "RightStrength", ToolTip = 
	 "Enter the number of bars to the right of the current bar to be analyzed to see if the price of those bars is greater than the price of the current bar."],

If price > SlowAvg Then
Begin;

if PivotLowVS( 1, Price, LeftStrength, RightStrength, RightStrength + 1 ) <> -1 then
	Buy ( !( "PivLowEntry" ) ) next bar at market;
	
			End;
		End;
This part is fine. What I'm having trouble with is:
 
Code
if marketposition = 1 Then
	Begin;
	
	if Condition1 then SellStop = SlowAvg[3];
		 SetStopLoss(Sellstop);
				 
	End;
The entry executed as it should but the position was closed on the next candle at the same entry price. Another position was opened later in the day but then not closed at all like the previous position. So I'm kind of at a loss.

Any help or direction would be appreciated!


Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,647 since Jul 2012
Thanks Given: 1,890
Thanks Received: 7,338


Exactly what @ABCTG said...


sell next bar at SlowAvg[3] stop;

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
xxjoocexx
Akron, Oh
 
Posts: 8 since Oct 2021
Thanks Given: 3
Thanks Received: 5

Progress! Thanks for your replies! Still learning the details of this code (never tried coding before) so I was sure I missed something like that.

For my future knowledge, is it not possible to have the stop execute when that SlowAvg[3] price get's touched? Or will it always need to be the next bar. Going back through this forum, it seems most replies to similar questions was that it needed to be done at the next bar.

Reply With Quote
Thanked by:
  #5 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,647 since Jul 2012
Thanks Given: 1,890
Thanks Received: 7,338


xxjoocexx View Post
Progress! Thanks for your replies! Still learning the details of this code (never tried coding before) so I was sure I missed something like that.

For my future knowledge, is it not possible to have the stop execute when that SlowAvg[3] price get's touched? Or will it always need to be the next bar. Going back through this forum, it seems most replies to similar questions was that it needed to be done at the next bar.

Hello fellow NorthEast Ohioan (I am in Cleveland, Bay Village actually).

If you are looking to have that stop on the entry bar, your choices are limited. SetStopLoss provides entry bar protection, but the "sell next bar at XXX stop;" does not.

If you need the entry bar protection, I would convert or try to estimate the dollar amount from your entry to the exit, and then use SetStopLoss.

I say estimate it because you may not know the exact entry price. It might be one of those things you play around with to see what works best for you.

Follow me on Twitter Reply With Quote
Thanked by:
  #6 (permalink)
xxjoocexx
Akron, Oh
 
Posts: 8 since Oct 2021
Thanks Given: 3
Thanks Received: 5


kevinkdog View Post
Hello fellow NorthEast Ohioan (I am in Cleveland, Bay Village actually).

If you are looking to have that stop on the entry bar, your choices are limited. SetStopLoss provides entry bar protection, but the "sell next bar at XXX stop;" does not.

If you need the entry bar protection, I would convert or try to estimate the dollar amount from your entry to the exit, and then use SetStopLoss.

I say estimate it because you may not know the exact entry price. It might be one of those things you play around with to see what works best for you.

Hey neighbor! Small world!

Let me ask this, would it be possible to figure out how many points the moving average is below the pivot low calculation and then use SetStopLoss? Being able to figure out the points distance from pivot to moving average would actually be beneficial in another part of the code. Sorry for the lack of knowledge I'm still trying to grasp all that this language can do and get the syntax right.

Reply With Quote
  #7 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,647 since Jul 2012
Thanks Given: 1,890
Thanks Received: 7,338


xxjoocexx View Post
Hey neighbor! Small world!

Let me ask this, would it be possible to figure out how many points the moving average is below the pivot low calculation and then use SetStopLoss? Being able to figure out the points distance from pivot to moving average would actually be beneficial in another part of the code. Sorry for the lack of knowledge I'm still trying to grasp all that this language can do and get the syntax right.

Sure, you'd just have to subtract that pivot low from the moving average. You should have those values available in your code.

Let's say the difference is calculated to be X.

Then, you'd do

SetStopPosition;
SetStopLoss(X*BigPointvalue); //stop in dollars per total position

Follow me on Twitter Reply With Quote
Thanked by:
  #8 (permalink)
xxjoocexx
Akron, Oh
 
Posts: 8 since Oct 2021
Thanks Given: 3
Thanks Received: 5


kevinkdog View Post
Sure, you'd just have to subtract that pivot low from the moving average. You should have those values available in your code.

Let's say the difference is calculated to be X.

Then, you'd do

SetStopPosition;
SetStopLoss(X*BigPointvalue); //stop in dollars per total position

I'll give this a go. I appreciate the help. I'm sure I'll be back for more. It'll be a good weekend to play around with it with that ice/snow coming our way. Take care!

Reply With Quote
Thanked by:
  #9 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,647 since Jul 2012
Thanks Given: 1,890
Thanks Received: 7,338


xxjoocexx View Post
I'll give this a go. I appreciate the help. I'm sure I'll be back for more. It'll be a good weekend to play around with it with that ice/snow coming our way. Take care!

Gotta love Ohio in late Winter / early Spring!!!

Let me know if you need more help.

Also, I can't post it here since it links to my vendor website, but I do have a nice Tradestation resource list for lessons, tips etc.

If you are on Tradestation website forum, it it also posted there.

Follow me on Twitter Reply With Quote
  #10 (permalink)
 
vmodus's Avatar
 vmodus 
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
Posts: 1,271 since Feb 2017
Thanks Given: 2,958
Thanks Received: 2,853



xxjoocexx View Post
I'll give this a go. I appreciate the help. I'm sure I'll be back for more. It'll be a good weekend to play around with it with that ice/snow coming our way. Take care!

@kevinkdog and @ABCTG already answered, but I figured as an Akron native myself, I figured I would welcome you to the forum. Stay warm and dry this weekend!

~vmodus

Enjoy everything!
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on March 28, 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