Setting StopLoss in Easy Language via Variable1-99 (calculated live) - MultiCharts | futures io social day trading
futures io futures trading


Setting StopLoss in Easy Language via Variable1-99 (calculated live)
Updated: Views / Replies:8,068 / 14
Created: by buggyboy Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Setting StopLoss in Easy Language via Variable1-99 (calculated live)

  #1 (permalink)
Trading Apprentice
sure I do
 
Futures Experience: Intermediate
Platform: NinjaTader, TradeStation
Favorite Futures: Forex
 
Posts: 3 since Jan 2012
Thanks: 1 given, 0 received

Setting StopLoss in Easy Language via Variable1-99 (calculated live)

Hello I am programming strategy and I have huge issue to set up either profit target or stop loss
(I do program in Easy Language for TradeStation)
Oke main problem is to set up "setstoploss()" & "setProfitTarget()".
I have a variable that is calculated as following '(Open[1]-High)*100' and that value I would like to put as mine profittarget & stoploss.
I've tried everything multiply, divide, * BigPointValue
I tried debugging via Print() (variable is printed alright e.g. 105 so my stoploss should be 105 but it isnt
Variables: float Variable1(0.0);

Variable1 = (Open[1]-High) * 100;
Print(Variable1); //prints as expected!! 105-200
SetStopLoss(Variable1); does not work!!
any1 help please?

Reply With Quote
 
  #2 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

Hi,

I think that Variable1 is calculated again at each bar. So your stop loss changes at each bar according to current Open[1]-High, whereas you would like it to be fixed (is it what you want?).

You could try to calculate it only once, in the part of the code in which you enter the trade.

Another solution is to continue calculating it at each bar, but using [BarsSinceEntry].

Other solutions are probably possible.

Nicolas

Reply With Quote
 
  #3 (permalink)
Elite Member
copenhagen, denmark
 
Futures Experience: Intermediate
Platform: multicharts, Ninja
Broker/Data: IB & Kinetick
Favorite Futures: ES
 
mengelbrecht's Avatar
 
Posts: 47 since Aug 2010
Thanks: 16 given, 21 received


Hi
It looks to me like you are trying to do some sort of trailing stop?. I have found that fixed stops actually gives you a better result so what i do is set a fixed initial stop and then move my stop to a break even once my first targit is met.
Se below example:

Input:
Cts(2),
CTS_tgt1(1),
CTS_tgt2(1),
TGT1(6),
TGT2(16),
Stop1 (9),
Stop2 (4),

Variables: , ticksize (0);

//Variable conditions
ticksize= MinMove/PriceScale;
targit1= tgt1*ticksize;
targit2= (tgt1+tgt2)*ticksize;
stoploss1 = stop1*ticksize;
stoploss2 = stop2*ticksize

// StopLoss
If ( MarketPosition = 1 ) Then begin
If ( CurrentContracts = Cts) then sell ("Long_stoploss1") cts contracts next bar at (openentryprice - Stoploss1) stop ;
If ( CurrentContracts = cts - CTS_tgt1) then sell ("long_stoploss2") (cts - CTS_tgt1) contracts next bar at (OpenEntryPrice - stoploss2) stop ;
end;
If ( MarketPosition = -1 ) Then begin
If ( CurrentContracts = Cts) then buytocover ("short_stoploss1") cts contracts next bar at (openentryprice + Stoploss1) stop ;
If ( CurrentContracts = cts - CTS_tgt1) then buytocover ("short_stoploss2") (cts - CTS_tgt1) contracts next bar at (OpenEntryPrice + stoploss2) stop ;
end;

Have fun

Mengelbrecht

Reply With Quote
The following user says Thank You to mengelbrecht for this post:
 
  #4 (permalink)
Trading Apprentice
sure I do
 
Futures Experience: Intermediate
Platform: NinjaTader, TradeStation
Favorite Futures: Forex
 
Posts: 3 since Jan 2012
Thanks: 1 given, 0 received


Nicolas11 View Post
I think that Variable1 is calculated again at each bar. So your stop loss changes at each bar according to current Open[1]-High, whereas you would like it to be fixed (is it what you want?).
Nicolas

Look at example from books/help pages
 
Code
if MoValue crosses over 0 then 
  buy next bar at market;

SetStoploss(100);
SetProfitTarget(100);
As all programers know following if MoValu... triggers only one command after (so only buy command in this case)
and setstoploss/profittarget are triggered on every loop that script runs.

How is it possible that I can not set my stoploss as I would like I mean
 
Code
Value1 = (Close[1]-Low)*100;
SetStopLoss(Value1);
and as you say I should do
 
Code
if my statement here is true then begin
buy command;
set value1;
end;
setstoploss(value1);
///I will try ASAP
I really do not get what parameter the stoploss() needs.




Quoting 
mengelbrecht
Hi
It looks to me like you are trying to do some sort of trailing stop?. I have found that fixed stops actually gives you a better result so what i do is set a fixed initial stop and then move my stop to a break even once my first targit is met.
Se below example:

thanks for your post but all I am trying to do is figure out function setstoploss() && setprofittarget();
all my examples are made up to illustrate my problem

Reply With Quote
 
  #5 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

Answer
This post has been selected as an answer to the original posters question Answer

Sorry if you have already clarified it, but... do you want a fixed stop loss (at such or such price) or a trailing stop loss (some ticks below recent price)?

Reply With Quote
 
  #6 (permalink)
Trading Apprentice
sure I do
 
Futures Experience: Intermediate
Platform: NinjaTader, TradeStation
Favorite Futures: Forex
 
Posts: 3 since Jan 2012
Thanks: 1 given, 0 received

I am not trying to fix anything
I am trying to set stoploss/profittarget based on my calculations
for example
I enter a short
**here are my hardcore calculations for stoploss/profittarget (its changing on many things so I can not have fixed stop/profit)
Value1 = hardcore calculation value; (not fixed) lets say 105.2 (or whatever 105) so I want to set for this SHORT my setstoploss(105); -> setstoploss(Value1);

it just came to my mind does my Value1 need to be float or integer?

so I calculate my Value1 only one time per trade. I think we solved this;

Reply With Quote
 
  #7 (permalink)
Elite Member
near Paris, France
 
Futures Experience: Beginner
Platform: -
Favorite Futures: -
 
Nicolas11's Avatar
 
Posts: 1,070 since Aug 2011
Thanks: 2,232 given, 1,729 received

OK. Personally, I would do something close to the following:

 
Code
if MarketPosition = 1 {long trade on-going} then begin
   Value1 = ( Close[BarSinceEntry+2] - Low[BarSinceEntry+1] ) * 100;
   SetStopLoss(Value1);
end;
[BarSinceEntry+1] refers to the "signal bar", that is to say the bar just before the bar when the trade was entered.
[BarSinceEntry+2] refers to the bar just before the signal bar.

Nicolas

Reply With Quote
The following user says Thank You to Nicolas11 for this post:
 
  #8 (permalink)
Trading Apprentice
City Poland
 
Futures Experience: Advanced
Platform: MT4,AmiBroker,MultiCharts
Favorite Futures: FX, futures, options, commodities, stocks
 
Posts: 14 since Sep 2012
Thanks: 1 given, 1 received

Some update from my side. I was successfully able to implement setting SL and TP which is fix.
 
Code
Setstopcontract; 
if MarketPosition < 0 then begin
   Value1 = TP [BarsSinceEntry+1];
   SetProfitTarget(Value1);
   Value2 = SL [BarsSinceEntry+1];
   SetStopLoss(Value2);
end;
But when I set in MultiCharts that "Allow up to 2 entry orders in the same direction as the current position" then SL and TP for second position is not proper (because set as first one). Is there any way to overcome this?

Reply With Quote
 
  #9 (permalink)
Market Wizard
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,533 since Apr 2013
Thanks: 231 given, 855 received
Forum Reputation: Legendary

jamesfisher,

the reserved words for SetProfitTarget and SetStopLoss are for the total position, you can't use two different ones when you have a positions with two entries. The only way around this is to code your own stop and limit exit orders for each entry.

Regards,

ABCTG


jamesfisher View Post
Some update from my side. I was successfully able to implement setting SL and TP which is fix.
 
Code
Setstopcontract; 
if MarketPosition < 0 then begin
   Value1 = TP [BarsSinceEntry+1];
   SetProfitTarget(Value1);
   Value2 = SL [BarsSinceEntry+1];
   SetStopLoss(Value2);
end;
But when I set in MultiCharts that "Allow up to 2 entry orders in the same direction as the current position" then SL and TP for second position is not proper (because set as first one). Is there any way to overcome this?


Reply With Quote
 
  #10 (permalink)
Trading Apprentice
City Poland
 
Futures Experience: Advanced
Platform: MT4,AmiBroker,MultiCharts
Favorite Futures: FX, futures, options, commodities, stocks
 
Posts: 14 since Sep 2012
Thanks: 1 given, 1 received


Yes, I was thinking about that but there is one disadvantage. If I use e.g.:
 
Code
Buy("LEx1") MyContracts contracts Next Bar at maxSetup stop;
Buy("LEx2") MyContracts contracts Next Bar at maxSetup stop;

Sell("LXx") from entry("LEx1") Next Bar at slLong stop;
Sell("LXx") from entry("LEx2") Next Bar at slLong stop;
and during market is moving on, my first position "LEx1" will be closed (SL reached) then the system doesn't know that should open new entry with tag "LEx1", instead of "LEx2".



ABCTG View Post
jamesfisher,

the reserved words for SetProfitTarget and SetStopLoss are for the total position, you can't use two different ones when you have a positions with two entries. The only way around this is to code your own stop and limit exit orders for each entry.

Regards,

ABCTG


Reply With Quote

Reply



futures io > > > > Setting StopLoss in Easy Language via Variable1-99 (calculated live)

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy Language to Ninja Script fireman912 NinjaTrader Programming 4 June 23rd, 2011 11:39 PM
easy language ..not easy... Serger EasyLanguage Programming 4 April 26th, 2011 04:42 PM
Easy Language for tradestation esam_jir EasyLanguage Programming 3 November 3rd, 2010 06:22 PM


All times are GMT -4. The time now is 07:23 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, 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
Page generated 2017-12-16 in 0.13 seconds with 39 queries on phoenix via your IP 54.226.113.250