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,977 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

  #11 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,666 since Jul 2012
Thanks Given: 1,892
Thanks Received: 7,360


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 NexusFi?
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
Cheap historycal L1 data for stocks
Stocks and ETFs
Trade idea based off three indicators.
Traders Hideout
How to apply profiles
Traders Hideout
 
  #12 (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


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 NexusFi Trade Journal Reply With Quote
  #13 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,666 since Jul 2012
Thanks Given: 1,892
Thanks Received: 7,360



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
Thanked by:
  #14 (permalink)
xxjoocexx
Akron, Oh
 
Posts: 8 since Oct 2021
Thanks Given: 3
Thanks Received: 5


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
Thanked by:
  #15 (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 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
  #16 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,666 since Jul 2012
Thanks Given: 1,892
Thanks Received: 7,360

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
  #17 (permalink)
xxjoocexx
Akron, Oh
 
Posts: 8 since Oct 2021
Thanks Given: 3
Thanks Received: 5

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
Thanked by:
  #18 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,666 since Jul 2012
Thanks Given: 1,892
Thanks Received: 7,360


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
Thanked by:
  #19 (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


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 NexusFi Trade Journal Reply With Quote
  #20 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,666 since Jul 2012
Thanks Given: 1,892
Thanks Received: 7,360



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
Thanked by:




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