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-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-High) * 100;
Print(Variable1); //prints as expected!! 105-200
SetStopLoss(Variable1); does not work!!
any1 help please?
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:
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 ;
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 ;
The following user says Thank You to mengelbrecht for this post:
I am not trying to fix anything
I am trying to set stoploss/profittarget based on my calculations
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;
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.