NexusFi: Find Your Edge


Home Menu

 





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


Discussion in MultiCharts

Updated
      Top Posters
    1. looks_one ABCTG with 4 posts (1 thanks)
    2. looks_two jamesfisher with 4 posts (0 thanks)
    3. looks_3 buggyboy with 3 posts (0 thanks)
    4. looks_4 Nicolas11 with 3 posts (1 thanks)
    1. trending_up 14,865 views
    2. thumb_up 3 thanks given
    3. group 4 followers
    1. forum 14 posts
    2. attach_file 0 attachments




 
Search this Thread

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

  #1 (permalink)
buggyboy
sure I do
 
Posts: 3 since Jan 2012
Thanks Given: 1
Thanks Received: 0

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

Can you help answer these questions
from other members on NexusFi?
Build trailing stop for micro index(s)
Psychology and Money Management
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Futures True Range Report
The Elite Circle
Deepmoney LLM
Elite Quantitative GenAI/LLM
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
60 thanks
Funded Trader platforms
43 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)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

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

Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 
mengelbrecht's Avatar
 mengelbrecht 
copenhagen, denmark
 
Experience: Intermediate
Platform: multicharts, Ninja
Broker: IB & Kinetick
Trading: ES
Posts: 47 since Aug 2010
Thanks Given: 16
Thanks Received: 23


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
Thanked by:
  #4 (permalink)
buggyboy
sure I do
 
Posts: 3 since Jan 2012
Thanks Given: 1
Thanks Received: 0


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)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

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)?

Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
buggyboy
sure I do
 
Posts: 3 since Jan 2012
Thanks Given: 1
Thanks Received: 0

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)
 
Nicolas11's Avatar
 Nicolas11 
near Paris, France
 
Experience: Beginner
Platform: -
Trading: -
Posts: 1,071 since Aug 2011
Thanks Given: 2,232
Thanks Received: 1,769

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

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #8 (permalink)
jamesfisher
City Poland
 
Posts: 14 since Sep 2012
Thanks Given: 1
Thanks Received: 3

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)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

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?


Follow me on Twitter Reply With Quote
  #10 (permalink)
jamesfisher
City Poland
 
Posts: 14 since Sep 2012
Thanks Given: 1
Thanks Received: 3


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




Last Updated on June 16, 2016


© 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