Short Position if actual price below last bar

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #217369 quote
    titleist311
    Participant
    New

    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

    #217377 quote
    JS
    Participant
    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
    #217409 quote
    titleist311
    Participant
    New

    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!

    #217413 quote
    JS
    Participant
    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)…

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Short Position if actual price below last bar


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by JS
2 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/06/2023
Status: Active
Attachments: No files
Logo Logo
Loading...