Need help with a stop loss based off a moving average value - futures io
futures io



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 5,526 views
    2. thumb_up 16 thanks given
    3. group 3 followers
    1. forum 22 posts
    2. attach_file 1 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
 

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

(login for full post details)
  #1 (permalink)
xxjoocexx
Akron, Oh
 
 
Posts: 7 since Oct 2021
Thanks: 3 given, 5 received

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
The following user says Thank You to xxjoocexx for this post:

Can you help answer these questions
from other members on futures io?
Multi Time Frame High/Low/Median levels
NinjaTrader
Big Mo Indicator for NT8
NinjaTrader
NT8 Order Management Strategy
The Elite Circle
Market on Close data within IB
Platforms and Indicators
Dissect open interest data
Crypto Futures
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Is anyone actually making money?
123 thanks
ApexTraderFunding.com experience and review
11 thanks
Want your NinjaTrader indicator created, free?
7 thanks
Artificial Intelligence (AI) and Chat GPT
7 thanks
Dax market profile (FDAX, TPO)
7 thanks
 
(login for full post details)
  #2 (permalink)
 ABCTG   is a Vendor
 
 
Posts: 2,360 since Apr 2013
Thanks: 426 given, 1,578 received

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
The following 2 users say Thank You to ABCTG for this post:
 
(login for full post details)
  #3 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,464 since Jul 2012
Thanks: 1,827 given, 6,985 received


Exactly what @ABCTG said...


sell next bar at SlowAvg[3] stop;

Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:
 
(login for full post details)
  #4 (permalink)
xxjoocexx
Akron, Oh
 
 
Posts: 7 since Oct 2021
Thanks: 3 given, 5 received

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
The following user says Thank You to xxjoocexx for this post:
 
(login for full post details)
  #5 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,464 since Jul 2012
Thanks: 1,827 given, 6,985 received


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
The following user says Thank You to kevinkdog for this post:
 
(login for full post details)
  #6 (permalink)
xxjoocexx
Akron, Oh
 
 
Posts: 7 since Oct 2021
Thanks: 3 given, 5 received


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
 
(login for full post details)
  #7 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,464 since Jul 2012
Thanks: 1,827 given, 6,985 received


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
The following user says Thank You to kevinkdog for this post:
 
(login for full post details)
  #8 (permalink)
xxjoocexx
Akron, Oh
 
 
Posts: 7 since Oct 2021
Thanks: 3 given, 5 received


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
The following user says Thank You to xxjoocexx for this post:
 
(login for full post details)
  #9 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,464 since Jul 2012
Thanks: 1,827 given, 6,985 received


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
 
(login for full post details)
  #10 (permalink)
 vmodus 
Legendary Systematic Algo Trader
Somewhere, Delaware, USA
 
Experience: Intermediate
Platform: MultiCharts
Broker: Barchart.com
Trading: Everything, it all tastes like chicken
 
vmodus's Avatar
 
Posts: 1,263 since Feb 2017
Thanks: 2,958 given, 2,841 received



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 futures io Trade Journal Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Need help with a stop loss based off a moving average value


Last Updated on March 28, 2022


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2023 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