Dear all,
I am a beginner in coding. Acutally I am looking for a solution to enter a short position once the current bar is trading lower than the low of the last bar. Then set a Stop Loss above the last bar’s high and a profit target which is 3 times the stop loss.
Somehow this code isn’t working yet. Can anyone tell me what I do have to correct?
Thanks a lot for your support.
Defparam cumulateorders = false
c1 = close<low[1]
h1 = High[1]
l1 = Low[1]
SL = h1 - l1 + 1*PointSize
IF NOT ShortOnMarket AND c1 THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
SET STOP PLOSS 1*SL
SET TARGET PPROFIT 3*SL
Best regards
Simon
JSParticipant
Senior
Hi Simon,
Try this…
DefParam CumulateOrders = false
h1 = High
l1 = Low
SL = (h1 - l1)
If NOT ShortOnMarket then
SellShort 1 contract at Low Stop
Set Stop pLoss SL * pipsize
Set Target pProfit (3 * SL) * pipsize
EndIf
Thanks a lot that works much better.
Now I have one last question. During a test session one trade was entered although the low of the bar (let’s say at price 105) was not below low the last bar (also 105) but just the same price. How do I have to adjust if the trade should be entered just one pip lower at 104.99?
Thanks again!
JSParticipant
Senior
Hi,
SellShort 1 contract at (Low-pipsize) Stop
You have to control what the size of the “pipsize” is…
For example, a “pipsize” of 1 can be divided by 100 (pipsize/100)…