Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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?
Can you help answer these questions from other members on NexusFi?
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].
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:
// 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;
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
and as you say I should do
///I will try ASAP
I really do not get what parameter the stoploss() needs.
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
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)?
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;
OK. Personally, I would do something close to the following:
[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.
Some update from my side. I was successfully able to implement setting SL and TP which is fix.
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?
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.
Yes, I was thinking about that but there is one disadvantage. If I use e.g.:
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
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.