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


vmodus View Post
@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!

I'm not sure I ever knew this about you!?!

Follow me on Twitter Reply With Quote

Can you help answer these questions
from other members on futures io?
Multi Time Frame High/Low/Median levels
NinjaTrader
Multiple brokerage accounts within one or more brokers
Traders Hideout
Market on Close data within IB
Platforms and Indicators
Big Mo Indicator for NT8
NinjaTrader
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
Artificial Intelligence (AI) and Chat GPT
7 thanks
Dax market profile (FDAX, TPO)
7 thanks
Want your NinjaTrader indicator created, free?
7 thanks
 
(login for full post details)
  #12 (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


kevinkdog View Post
I'm not sure I ever knew this about you!?!

I think I mentioned it a long time ago, that's why I'm so familiar with where you're located. I will be up there this summer (Westlake), so I will reach out to you privately in case we have a chance to meetup.

~vmodus

Enjoy everything!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #13 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,464 since Jul 2012
Thanks: 1,827 given, 6,985 received



vmodus View Post
I think I mentioned it a long time ago, that's why I'm so familiar with where you're located. I will be up there this summer (Westlake), so I will reach out to you privately in case we have a chance to meetup.

Yes, I think I forgot about your Westlake connection. Definitely reach out, maybe we can talk trading and do some Lake Erie Jet Skiing!

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


vmodus View Post
@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!

Thank you! Got some very helpful people in here. Lots of info to glean from the different threads. How about that swing in weather! 73 today!

Reply With Quote
The following user says Thank You to xxjoocexx for this post:
 
(login for full post details)
  #15 (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 have this working most of the time. One thing I am having trouble with is keeping the stop loss value static or predictable. I'm using the difference from the entry price and the medium length moving average of the pivot bar. The thing that makes everything wonky is if there's another pivot discovered before the stop get's triggered. I don't know how to go about that.

This is what I have currently and I know it's throwing it off since the Pivot function is set to the most recent occurance:

 
Code
Value2= AvgEntryprice;
Value3= PivotLowVSBar(1,Low,2,2,50);

MedStop = (value2 - MedEMA[Value3]);

SetStopPosition;
SetStopLoss(MedStop * BigPointvalue);
I can't figure out how to take the MA of the trigger pivot and ONLY the trigger pivot. I'm dropping in a picture of it happening. The vertical blue is the pivot that is being identified, the horizontal line is where the exit should be based on the moving average value. As you can see it exits well above.

pivot exit



Side question: can you have conditions for SetStopPositions? I thought I read somewhere that Easy Language takes the LAST conditional and uses that regardless if there is more. Is there a way to get around that?

Reply With Quote
 
(login for full post details)
  #16 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,464 since Jul 2012
Thanks: 1,827 given, 6,985 received

For the pivot/average stop, to set it at the trigger point, capture the value right when you buy (I did not test this, this is just in general how you could do it):

 
Code
If  xxxxx then begin
 buy next bar at market;
 Value3= PivotLowVSBar(1,Low,2,2,50);
 Value4 = MedEMA[Value3];
end;

SetStopPosition;
SetStopLoss((AvgEntryPrice-Value4)* BigPointvalue);

For the side question, you could have conditionals;

 
Code
SetStopLoss(1000);

If OpenPositionProfit>2000 then SetStopPosition(500);

Good Luck!

Follow me on Twitter Reply With Quote
 
(login for full post details)
  #17 (permalink)
xxjoocexx
Akron, Oh
 
 
Posts: 7 since Oct 2021
Thanks: 3 given, 5 received

With your help, I've got everything working except, I think I am coming to realization that you can not have two SetStopLoss/SetProfitTargets in one strategy. I was hoping to use the medium moving average value at pivot low to be my stop loss if the buy happened above the medium moving average, and then use a slow moving average value at pivot low to be the stop loss if the buy occurred below the medium moving average. Seems like the last SetPosition group ends up being the dominate one. Even if I split the code in two separate strategies on the same chart. Say it ain't so!

I have two different versions of the below as my stoploss/profit targets based on which entry condition occurred.

 
Code
If MedTrade Then
Begin;
	SetStopPosition;
	SetStopLoss( MedStop * BigPointvalue ); 

	SetStopPosition;
	SetProfitTarget(1.5 * MedStop * Bigpointvalue);
End;
This works on it's own, but not when there are two. Any advice?

Reply With Quote
The following user says Thank You to xxjoocexx for this post:
 
(login for full post details)
  #18 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,464 since Jul 2012
Thanks: 1,827 given, 6,985 received


xxjoocexx View Post
With your help, I've got everything working except, I think I am coming to realization that you can not have two SetStopLoss/SetProfitTargets in one strategy. I was hoping to use the medium moving average value at pivot low to be my stop loss if the buy happened above the medium moving average, and then use a slow moving average value at pivot low to be the stop loss if the buy occurred below the medium moving average. Seems like the last SetPosition group ends up being the dominate one. Even if I split the code in two separate strategies on the same chart. Say it ain't so!

I have two different versions of the below as my stoploss/profit targets based on which entry condition occurred.

 
Code
If MedTrade Then
Begin;
	SetStopPosition;
	SetStopLoss( MedStop * BigPointvalue ); 

	SetStopPosition;
	SetProfitTarget(1.5 * MedStop * Bigpointvalue);
End;
This works on it's own, but not when there are two. Any advice?

I would convert to a regular stop/limit statement (will not work on the bar of entry though):

Sell next bar at XXXX stop;
Sell next bar at YYYY limit;

but note XXXX and YYYY are prices, not dollar values like you use in SetStopLoss. So you have to convert MedStop from dollars to actual price value...

Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:
 
(login for full post details)
  #19 (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


kevinkdog View Post
I would convert to a regular stop/limit statement (will not work on the bar of entry though):

Sell next bar at XXXX stop;
Sell next bar at YYYY limit;

but note XXXX and YYYY are prices, not dollar values like you use in SetStopLoss. So you have to convert MedStop from dollars to actual price value...

@kevinkdog, is this how you send both a stop and limit order at the same time? I could never figure that out in EasyLanguage (MC PowerLanguage allows one statement for both).

~vmodus

Enjoy everything!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #20 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,464 since Jul 2012
Thanks: 1,827 given, 6,985 received



vmodus View Post
@kevinkdog, is this how you send both a stop and limit order at the same time? I could never figure that out in EasyLanguage (MC PowerLanguage allows one statement for both).

I believe if you try to send both, only one will be "active" at any one time.

Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:


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